Repository navigation
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
A file-based AppHost that uses Central Package Management references the AppHost package without a version:
#:package Aspire.Hosting.AppHost
#:package Aspire.Hosting.Dotnet
// ...
var builder = DistributedApplication.CreateBuilder(args);The version comes from Directory.Packages.props:
<PackageVersion Include="Aspire.Hosting.AppHost" Version="17.0.0-preview.1.26555.11" />The Aspire CLI doesn't recognize this file as an AppHost. aspire run --apphost ./src/apphost.cs fails with:
❌ The --apphost option specified a project that does not exist.
aspire ls returns []. dotnet build ./src/apphost.cs evaluates and resolves the package correctly through Central Package Management.
Root cause: DotNetAppHostProject.IsValidSingleFileAppHost calls FallbackProjectParser.HasAppHostPackageDirective. That method uses PackageDirectiveRegex, which requires @version:
[GeneratedRegex(@"^[\t ]*#:package[\t ]+([a-zA-Z0-9\._]+)@([\d\.\-+a-zA-Z]+|\*)[\t ]*\r?$", RegexOptions.Multiline)]A versionless #:package Aspire.Hosting.AppHost therefore never matches. This was introduced in #20867, which deprecated Aspire.AppHost.Sdk and added HasAppHostPackageDirective. Now that the SDK is obsolete, #:package Aspire.Hosting.AppHost is the recommended pattern, and CPM users can't specify a version in the directive.
Expected Behavior
#:package Aspire.Hosting.AppHost without @version should count as an AppHost directive, so the file is discovered and aspire run/aspire start work.
Steps To Reproduce
- Create
Directory.Packages.propswith<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>and<PackageVersion Include="Aspire.Hosting.AppHost" Version="17.0.0-preview.1.26555.11" />. - Create
apphost.cs:#:package Aspire.Hosting.AppHost var builder = DistributedApplication.CreateBuilder(args); builder.Build().Run();
- Run
aspire ls --format Json. Result:[]. - Run
aspire run --apphost apphost.cs. Result:The --apphost option specified a project that does not exist.
For comparison, a file containing #:package Aspire.Hosting.AppHost@17.0.0-preview.1.26555.11 or #:sdk Aspire.AppHost.Sdk@... is detected.
Workarounds and why they're poor
- Adding
@versionto the#:packagedirective breaks restore withNU1008under CPM. - Adding
#:sdk Aspire.AppHost.Sdk@<version>restores detection but uses the now-obsolete SDK, which producesASPIRE012.
Exceptions (if any)
Aspire.Cli.Projects.ProjectLocatorException: Project file does not exist.
at Aspire.Cli.Projects.ProjectLocator.UseOrFindAppHostProjectFileCoreAsync(...)
at Aspire.Cli.Projects.ProjectLocator.UseOrFindAppHostProjectFileAsync(...)
at Aspire.Cli.Commands.RunCommand.ExecuteAsync(...)
Debug log excerpt:
[dbug] ProjectLocator: Checking candidate file ...\src\apphost.cs
[dbug] AppHostProjectFactory: Language detected: csharp for file: ...\src\apphost.cs
...
[fail] ProjectLocator: No AppHost project files found in directory ...\src
Anything else?
- Aspire CLI:
17.0.0-preview.1.26555.11+ba68df274b71ed55aaf95c040295f5daee83dc95(daily channel) - .NET SDK:
11.0.100-rc.2.26504.105 - OS: Windows
- Tooling: Aspire CLI
- The regex is unchanged on
main. - The same versionless form is probably also missed elsewhere
PackageDirectiveRegexis used, for example when extracting package references inParseCsAppHostFile.
Activity
Detect file-based AppHosts with versionless #:package directives (CPM) (