Enhance Your Development with Multi-Repo Support in Dotnet Aspire
Dutchskull
Posted on June 15, 2024
.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
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"));
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);
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);
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
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.
Posted on June 15, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.