Enhance Your Development with Multi-Repo Support in Dotnet Aspire

dutchskull

Dutchskull

Posted on June 15, 2024

Enhance Your Development with Multi-Repo Support in Dotnet Aspire

.NET Aspire is renowned for its robust support for monolithic repositories, allowing developers to manage large codebases efficiently. However, managing multiple repositories, or poly repos, can be challenging. Enter Aspire.PolyRepo, a .NET Aspire package designed to bridge this gap and provide seamless multi-repo support.

Introducing Aspire.PolyRepo

Aspire.PolyRepo simplifies the process of cloning and managing Git repositories within your .NET Aspire applications. This package allows you to configure and integrate Git repositories effortlessly, streamlining your cloud-native development workflow.

Key Features

  • Direct Git Integration: Clone repositories directly into your .NET Aspire application.
  • Flexible Configuration: Customize repository URL, name, target path, default branch, and project path.
  • Seamless Integration: Easy setup with .NET Aspire App Host.

Installation

To install the Aspire.PolyRepo package, use the .NET CLI. Run the following command in your terminal:

dotnet add package Dutchskull.Aspire.PolyRepo
Enter fullscreen mode Exit fullscreen mode

Usage

Here's a step-by-step guide to using Aspire.PolyRepo in your .NET Aspire application:

Step 1: Add a Repository Resource

First, add the necessary configuration to your App Host project. Below is an example of how to configure a Git repository:

var builder = DistributedApplication.CreateBuilder(args);

var repository = builder.AddRepository(
    "repository",
    "https://github.com/Dutchskull/Aspire-Git.git",
    c => c.WithDefaultBranch("feature/rename_and_new_api")
        .WithTargetPath("../../repos"));
Enter fullscreen mode Exit fullscreen mode

Step 2: Add Projects from the Repository

You can add various types of projects from the repository. Here’s how you can add a .NET project:

var dotnetProject = builder
    .AddProjectFromRepository("dotnetProject", repository,
        "src/Dutchskull.Aspire.PolyRepo.Web/Dutchskull.Aspire.PolyRepo.Web.csproj")
    .WithReference(cache)
    .WithReference(apiService);
Enter fullscreen mode Exit fullscreen mode

Aspire.PolyRepo also supports adding npm and node applications. These methods share the initial parameters with AddProjectFromRepository, but their additional parameters are specific to npm and node configurations:

var reactProject = builder
    .AddNpmAppFromRepository("reactProject", repository, "src/Dutchskull.Aspire.PolyRepo.React")
    .WithReference(cache)
    .WithReference(apiService)
    .WithHttpEndpoint(3000);

var nodeProject = builder
    .AddNodeAppFromRepository("nodeProject", repository, "src/Dutchskull.Aspire.PolyRepo.Node")
    .WithReference(cache)
    .WithReference(apiService)
    .WithHttpEndpoint(54622);
Enter fullscreen mode Exit fullscreen mode

Step 3: Navigate to Your App Host Project Directory

Open your terminal and navigate to the directory of your App Host project.

Step 4: Run the Application

Use the .NET CLI or Visual Studio 2022 to run your application:

dotnet run
Enter fullscreen mode Exit fullscreen mode

This configuration clones the specified Git repository into your application, enabling seamless integration and development across multiple projects.

Recap

Aspire.PolyRepo is the solution for developers looking to manage multiple repositories within their .NET Aspire applications effortlessly. By following the simple steps outlined above, you can configure and run your applications, leveraging the power of poly repo support. With its straightforward setup and robust feature set, Aspire.PolyRepo ensures that managing multiple repositories becomes a hassle-free part of your development workflow.

Check out the Aspire.PolyRepo source here

💖 💪 🙅 🚩
dutchskull
Dutchskull

Posted on June 15, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related