Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/list-of-diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
| `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 &quot;Aspire.AppHost.Sdk&quot; with version &quot;9.0.0&quot; 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 &lt;GenerateAssemblyInfo&gt;false&lt;/GenerateAssemblyInfo&gt; 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) |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need to add this to the official docs and will also need to add an aka.ms link for it I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created regular aka.ms link for now and logged dotnet/docs-aspire#6093


## Analyzer Warnings

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@ namespace Projects%3B
HelpLink="https://aka.ms/aspire/diagnostics/aspire007" />
</Target>

<Target Name="__ErrorOnGenerateAssemblyInfoDisabled" BeforeTargets="PrepareForBuild"
Condition="'$(IsAspireHost)' == 'true' and '$(GenerateAssemblyInfo)' == 'false'">
<Error Code="ASPIRE008"
Text="$(MSBuildProjectName) project requires GenerateAssemblyInfo to be enabled. The Aspire AppHost relies on assembly metadata attributes to locate required dependencies. Please remove &lt;GenerateAssemblyInfo&gt;false&lt;/GenerateAssemblyInfo&gt; from your project file or set it to true."
File="$(MSBuildProjectFullPath)"
HelpLink="https://aka.ms/aspire/diagnostics/aspire008" />
</Target>

<!-- Entrypoint to allow for generation of an aspire manifest to a given location -->
<Target Name="GenerateAspireManifest" DependsOnTargets="Build;_EnsureAspireManifestPublishOutputPathExists" Inputs="$(TargetFileName)" Outputs="$(_AspireManifestPublishOutputFile)">
<ItemGroup>
Expand Down
84 changes: 84 additions & 0 deletions tests/Aspire.Hosting.Tests/MSBuildTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,4 +370,88 @@ the Aspire.AppHost.SDK targets that will automatically add these references to p
// and ASPIRE004 warning should be emitted for the Library project reference
Assert.Contains("warning ASPIRE004", output);
}

/// <summary>
/// Tests that when GenerateAssemblyInfo is set to false, a build error is emitted.
/// </summary>
[Fact]
public void GenerateAssemblyInfoFalse_EmitsError()
{
var repoRoot = MSBuildUtils.GetRepoRoot();
using var tempDirectory = new TestTempDirectory();

var appHostDirectory = Path.Combine(tempDirectory.Path, "AppHost");
Directory.CreateDirectory(appHostDirectory);

File.WriteAllText(Path.Combine(appHostDirectory, "AppHost.csproj"),
$"""
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>

<!--
Test applications have their own way of referencing Aspire.Hosting.AppHost, as well as DCP and Dashboard, so we disable
the Aspire.AppHost.SDK targets that will automatically add these references to projects.
-->
<SkipAddAspireDefaultReferences Condition="'$(TestsRunningOutsideOfRepo)' != 'true'">true</SkipAddAspireDefaultReferences>
<AspireHostingSDKVersion>9.0.0</AspireHostingSDKVersion>
<_AspireUseTaskHostFactory>true</_AspireUseTaskHostFactory>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="{repoRoot}\src\Aspire.Hosting.AppHost\Aspire.Hosting.AppHost.csproj" IsAspireProjectResource="false" />
</ItemGroup>

</Project>
""");

File.WriteAllText(Path.Combine(appHostDirectory, "AppHost.cs"),
"""
var builder = DistributedApplication.CreateBuilder();
builder.Build().Run();
""");

CreateDirectoryBuildFiles(appHostDirectory, repoRoot);

// Build should fail
var output = new StringBuilder();
var outputDone = new ManualResetEvent(false);
using var process = new Process();
process.StartInfo = new ProcessStartInfo("dotnet", "build --disable-build-servers")
{
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
WorkingDirectory = appHostDirectory
};
process.OutputDataReceived += (sender, e) =>
{
if (e.Data == null)
{
outputDone.Set();
}
else
{
output.AppendLine(e.Data);
}
};
process.Start();
process.BeginOutputReadLine();

Assert.True(process.WaitForExit(milliseconds: 180_000), "dotnet build command timed out after 3 minutes.");
Assert.True(outputDone.WaitOne(millisecondsTimeout: 60_000), "Timed out waiting for output to complete.");

var buildOutput = output.ToString();

// Build should fail with ASPIRE008 error
Assert.NotEqual(0, process.ExitCode);
Assert.Contains("error ASPIRE008", buildOutput);
Assert.Contains("GenerateAssemblyInfo", buildOutput);
}
}
Loading