Enhance Your Development with Multi-Repo Support in Dotnet Aspire
Tags: dotnet, csharp, devops, aspnet
Published: 2024-06-15 19:24:17

.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](https://github.com/Dutchskull/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:

```sh
dotnet add package Dutchskull.Aspire.PolyRepo
```

## 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:

```csharp
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"));
```

### 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:

```csharp
var dotnetProject = builder
    .AddProjectFromRepository("dotnetProject", repository,
        "src/Dutchskull.Aspire.PolyRepo.Web/Dutchskull.Aspire.PolyRepo.Web.csproj")
    .WithReference(cache)
    .WithReference(apiService);
```

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:

```csharp
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);
```

### 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:

```sh
dotnet run
```

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](https://github.com/Dutchskull/Aspire.PolyRepo)