Add build error when GenerateAssemblyInfo is disabled in AppHost projects#13751
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 13751Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 13751" |
Co-authored-by: DamianEdwards <249088+DamianEdwards@users.noreply.github.com>
Co-authored-by: DamianEdwards <249088+DamianEdwards@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds build-time validation to detect and prevent a misconfiguration in Aspire AppHost projects where GenerateAssemblyInfo is disabled, which causes cryptic runtime failures. When this setting is false, assembly metadata attributes that embed DCP and Dashboard paths are not generated, breaking the orchestration infrastructure.
Key Changes:
- Added MSBuild target that fails the build with ASPIRE008 error when
GenerateAssemblyInfois false in AppHost projects - Created comprehensive test to verify the validation triggers correctly
- Documented the new ASPIRE008 diagnostic in the diagnostics reference
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/Aspire.Hosting.AppHost/build/Aspire.Hosting.AppHost.in.targets |
Added __ErrorOnGenerateAssemblyInfoDisabled target that emits ASPIRE008 error when GenerateAssemblyInfo is false in AppHost projects |
tests/Aspire.Hosting.Tests/MSBuildTests.cs |
Added GenerateAssemblyInfoFalse_EmitsError test that verifies build fails with ASPIRE008 when GenerateAssemblyInfo is disabled |
docs/list-of-diagnostics.md |
Added ASPIRE008 entry to MSBuild errors table with clear description and location reference |
|
Results from running locally on apphosts with On Blazor starter: ➜ aspire run
🔍 Finding apphosts...
BlazorStarter.AppHost\BlazorStarter.AppHost.csproj
🗄 Created settings file at '.aspire/settings.json'.
Determining projects to restore...
All projects are up-to-date for restore.
D:\scratch\aspire\pr-13751\BlazorStarter\BlazorStarter.AppHost\BlazorStarter.AppHost.csproj : error ASPIRE008: BlazorStarter.AppHost
project requires GenerateAssemblyInfo to be enabled. The Aspire AppHost relies on assembly metadata attributes to locate required
dependencies. Please remove <GenerateAssemblyInfo>false</GenerateAssemblyInfo> from your project file or set it to true.
Build FAILED.
D:\scratch\aspire\pr-13751\BlazorStarter\BlazorStarter.AppHost\BlazorStarter.AppHost.csproj : error ASPIRE008: BlazorStarter.AppHost
project requires GenerateAssemblyInfo to be enabled. The Aspire AppHost relies on assembly metadata attributes to locate required
dependencies. Please remove <GenerateAssemblyInfo>false</GenerateAssemblyInfo> from your project file or set it to true.
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.88
❌ The project could not be built. For more information run with --debug switch.On Python starter: aspire run
🔍 Finding apphosts...
apphost.cs
🗄 Created settings file at '.aspire/settings.json'.
❌ An error occurred while connecting to the app host. The app host possibly crashed before it was available: AppHost process has exited
unexpectedly. Use --debug to see more details..
Using launch settings from D:\scratch\aspire\pr-13751\PythonStarter\apphost.run.json...
Building...
D:\scratch\aspire\pr-13751\PythonStarter\apphost.csproj : error ASPIRE008: apphost project requires GenerateAssemblyInfo to be
enabled. The Aspire AppHost relies on assembly metadata attributes to locate required dependencies. Please remove
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> from your project file or set it to true.
The build failed. Fix the build errors and run again. |
| | `ASPIRE004` | Warning | '\[ProjectName\]' is referenced by an Aspire Host project, but it is not an executable. Did you mean to set IsAspireProjectResource="false"? | [src/Aspire.Hosting.AppHost/build/Aspire.Hosting.AppHost.in.targets](../src/Aspire.Hosting.AppHost/build/Aspire.Hosting.AppHost.in.targets) | | ||
| | `ASPIRE005` | Error | (Deprecated) This diagnostic is no longer used. | | | ||
| | `ASPIRE007` | Error | '\[ProjectName\]' project requires a reference to "Aspire.AppHost.Sdk" with version "9.0.0" or greater to work correctly. Please add the following line after the Project declaration `<Sdk Name=Aspire.AppHost.Sdk" Version="9.0.0" />`. | [src/Aspire.Hosting.AppHost/build/Aspire.Hosting.AppHost.in.targets](../src/Aspire.Hosting.AppHost/build/Aspire.Hosting.AppHost.in.targets) | | ||
| | `ASPIRE008` | Error | '\[ProjectName\]' project requires GenerateAssemblyInfo to be enabled. The Aspire AppHost relies on assembly metadata attributes to locate required dependencies. Please remove <GenerateAssemblyInfo>false</GenerateAssemblyInfo> from your project file or set it to true. | [src/Aspire.Hosting.AppHost/build/Aspire.Hosting.AppHost.in.targets](../src/Aspire.Hosting.AppHost/build/Aspire.Hosting.AppHost.in.targets) | |
There was a problem hiding this comment.
We will need to add this to the official docs and will also need to add an aka.ms link for it I think.
There was a problem hiding this comment.
Hmmm I wonder if we should consider changing the aka.ms stuff to flow this as a query parameter instead so each diagnostic doesn't need its own entry?
There was a problem hiding this comment.
Created regular aka.ms link for now and logged dotnet/docs-aspire#6093
Description
AppHost projects rely on
AssemblyMetadataAttributeto embed DCP and Dashboard paths during compilation. WhenGenerateAssemblyInfois disabled, these attributes are not generated, causing cryptic runtime failures about missing orchestration dependencies. This change detects the misconfiguration at build time with a clear, actionable error.Changes:
__ErrorOnGenerateAssemblyInfoDisabledtarget inAspire.Hosting.AppHost.in.targetsthat emits ASPIRE008 error whenGenerateAssemblyInfoisfalseGenerateAssemblyInfoFalse_EmitsErrortest to verify error emissionError message:
Checklist
<remarks />and<code />elements on your triple slash comments?diagnostictemplate - ASPIRE008 diagnostic needs documentationOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.