Skip to content

Generated project metadata class produces CS1591 warnings if project generates documentation xml #9197

@afscrome

Description

@afscrome

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

If your project references the Aspire.Hosting.AppHost package, a project metadata class (_AppHost.ProjectMetadata.g.cs) gets auto generated. This generated code violates CS1591 if your project has GenerateDocumentationFile enabled, causing unfixable compiler warnings (if you turn warnings as errors on, this becomes a compiler error)

I'm building a nuget package for an internal package to share, which is why to to generate xml docs, for my package.

// <auto-generated/>

namespace Projects;

[global::System.CodeDom.Compiler.GeneratedCode("Aspire.Hosting", null)]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage(Justification = "Generated code.")]
[global::System.Diagnostics.DebuggerDisplay("Type = {GetType().Name,nq}, ProjectPath = {ProjectPath}")]
public class aspire91_ServiceDefaults
{
    private aspire91_ServiceDefaults() { }
    public static string ProjectPath => """S:\aspire91\aspire91.ServiceDefaults""";
}

Expected Behavior

The generated Projects class should either have default xml documentation, or suppress the error with #pragma warning disable

Another option is to only generate the project metadata for executable projects.

Steps To Reproduce

Create the following project with no code files and compile it

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net9.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Aspire.Hosting.AppHost" Version="9.2.1" />
  </ItemGroup>

</Project>

Exceptions (if any)

Severity	Code	Description	Project	File	Line	Suppression State	Details
Error (active)	CS1591	The /doc compiler option was specified, but one or more constructs did not have comments.	aspire91.ServiceDefaults	S:\aspire91\aspire91.ServiceDefaults\obj\Debug\net9.0\Aspire\references\_AppHost.ProjectMetadata.g.cs	8		
Error (active)	CS1591	The /doc compiler option was specified, but one or more constructs did not have comments.	aspire91.ServiceDefaults	S:\aspire91\aspire91.ServiceDefaults\obj\Debug\net9.0\Aspire\references\_AppHost.ProjectMetadata.g.cs	11		

.NET Version info

No response

Anything else?

The usual workaround is to suppress the error with #pragma warning disable, however that doesn't work as the culprit is generated code I don't control. I have tried to work around this with [SuppressMessage] but haven't been able to get that to work.

[assembly: SuppressMessage("Usage", "CS1591:Missing XML comment for publicly visible type or member",
    Justification = "Not production code.",
    Scope = "namespaceanddescendants",
    Target = "~N:Projects")]

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-app-modelIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions