コンテンツにスキップ
Docs Try Aspire
Docs Try

.NET tool resources

このコンテンツはまだ日本語訳がありません。

.NET logo

This article is the reference for the .NET tool resources AppHost integration. It enumerates the AppHost APIs — with examples for both AppHost.cs and apphost.ts — that you use to model .NET CLI tool resources in your AppHost project.

Use .NET tool resources when you need to:

  • Run .NET CLI tools that are distributed as NuGet packages.
  • Integrate database migration tools like Entity Framework Core CLI (dotnet-ef).
  • Execute diagnostic tools such as dotnet-dump, dotnet-trace, or dotnet-counters.
  • Run code generators or analysis tools as part of your development workflow.

Before using .NET tool resources, ensure you have:

  • .NET 10 SDK or later installed on the host machine running the C# AppHost.
  • The tool’s working directory must not be in the context of a global.json file that forces an older SDK version.

The addDotnetTool API requires a resource name and the NuGet package ID of the tool:

C# — AppHost.cs
#pragma warning disable ASPIREDOTNETTOOL
var builder = DistributedApplication.CreateBuilder(args);
// Add Entity Framework Core CLI tool
var efTool = builder.AddDotnetTool("ef", "dotnet-ef");
// After adding all resources, run the app...
builder.Build().Run();
#pragma warning restore ASPIREDOTNETTOOL

When the AppHost runs, Aspire executes dotnet tool exec dotnet-ef to run the tool.

Use withArgs to pass command-line arguments to the tool:

C# — AppHost.cs
#pragma warning disable ASPIREDOTNETTOOL
var builder = DistributedApplication.CreateBuilder(args);
var efTool = builder.AddDotnetTool("ef", "dotnet-ef")
.WithArgs("migrations", "list");
builder.Build().Run();
#pragma warning restore ASPIREDOTNETTOOL

By default, the latest stable version of the tool is used. You can specify a particular version or allow prerelease versions.

Use withToolVersion to pin to a specific version:

C# — AppHost.cs
var efTool = builder.AddDotnetTool("ef", "dotnet-ef")
.WithToolVersion("9.0.1");

You can also use wildcard versions to get the latest patch:

C# — AppHost.cs
var efTool = builder.AddDotnetTool("ef", "dotnet-ef")
.WithToolVersion("10.0.*");

Use withToolPrerelease to allow prerelease versions of the tool:

C# — AppHost.cs
var efTool = builder.AddDotnetTool("ef", "dotnet-ef")
.WithToolPrerelease();

By default, tools are acquired from configured NuGet feeds. You can add additional sources or configure the tool to use only specific sources.

Use withToolSource to add a NuGet package source:

C# — AppHost.cs
var tool = builder.AddDotnetTool("my-tool", "my-custom-tool")
.WithToolSource("https://my-private-feed.example.com/nuget/v3/index.json");

Use withToolIgnoreExistingFeeds to ignore the existing NuGet configuration and use only the sources you specify:

C# — AppHost.cs
var tool = builder.AddDotnetTool("my-tool", "my-custom-tool")
.WithToolSource("./local-packages")
.WithToolIgnoreExistingFeeds();

Use withToolIgnoreFailedSources to treat package source failures as warnings rather than errors:

C# — AppHost.cs
var tool = builder.AddDotnetTool("my-tool", "my-custom-tool")
.WithToolIgnoreFailedSources();

The following is a complete example using Entity Framework Core CLI to run database migrations:

C# — AppHost.cs
#pragma warning disable ASPIREDOTNETTOOL
var builder = DistributedApplication.CreateBuilder(args);
var postgres = builder.AddPostgres("postgres")
.AddDatabase("appdb");
var api = builder.AddProject<Projects.Api>("api")
.WithReference(postgres);
var efMigrations = builder.AddDotnetTool("ef-migrate", "dotnet-ef")
.WithArgs("database", "update", "--project", "../Api")
.WithReference(postgres)
.WaitFor(postgres);
builder.Build().Run();
#pragma warning restore ASPIREDOTNETTOOL

.NET tool resources appear in the Aspire Dashboard with a dedicated resource type, allowing you to filter and view tools separately from other resources. The dashboard displays tool-specific properties including:

  • Package: The NuGet package ID of the tool.
  • Version: The version of the tool being used (if specified).
  • Source: The package source from which the tool was acquired.
C# methodTypeScript methodDescription
AddDotnetTool(name, packageId)addDotnetTool(name, packageId)Adds a .NET tool resource with the specified name and NuGet package ID.
WithToolVersion(version)withToolVersion(version)Sets the package version for the tool. Supports wildcards like 10.0.*.
WithToolPrerelease()withToolPrerelease()Allows prerelease versions of the tool to be used.
WithToolSource(source)withToolSource(source)Adds a NuGet package source for tool acquisition.
WithToolIgnoreExistingFeeds()withToolIgnoreExistingFeeds()Configures the tool to use only specified package sources.
WithToolIgnoreFailedSources()withToolIgnoreFailedSources()Treats package source failures as warnings.
WithArgs(params string[])withArgs(string[])Passes command-line arguments to the tool.

The ASPIREDOTNETTOOL diagnostic applies to C# AppHosts only. The TypeScript AppHost SDK does not require any suppression.

C# — AppHost.cs
#pragma warning disable ASPIREDOTNETTOOL
var tool = builder.AddDotnetTool("my-tool", "dotnet-tool-package");
#pragma warning restore ASPIREDOTNETTOOL
XML — AppHost.csproj
<PropertyGroup>
<NoWarn>$(NoWarn);ASPIREDOTNETTOOL</NoWarn>
</PropertyGroup>