Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added #pragma warning disable CS1591 to supress warnings in the source generated code #8940

Merged

Conversation

m3nax
Copy link
Contributor

@m3nax m3nax commented Apr 11, 2024

Description

Added #pragma warning disable CS1591 and "#pragma warning restore CS1591 to the source generated file to supress warnings when projects contains <GenerateDocumentationFile>True</GenerateDocumentationFile>

Fixes #8290

@m3nax m3nax changed the title Added #pragma to supress warning CS1591 to the source generated code Added #pragma warning disable CS1591 to supress warning in the source generated code Apr 11, 2024
@m3nax m3nax changed the title Added #pragma warning disable CS1591 to supress warning in the source generated code Added #pragma warning disable CS1591 to supress warnings in the source generated code Apr 11, 2024
@ReubenBond
Copy link
Member

Thank you for opening this PR, @m3nax!

I was looking for the Roslyn-native way to do this. It might look something like this, in CodeGenerator.cs before we return the CompilationSyntax but I haven't tested this yet:

            var disabledWarnings = new List<string>();
            assemblyAttributes[0] = assemblyAttributes[0]
                .WithLeadingTrivia(
                    SingletonList(
                        PragmaWarningDirectiveTrivia(
                            Token(SyntaxKind.DisableKeyword),
                            SeparatedList(disabledWarnings.Select(w => (ExpressionSyntax)w.GetLiteralExpression())), isActive: true)));
            
            return CompilationUnit()
                .WithAttributeLists(List(assemblyAttributes))
                .WithMembers(List(namespaces));

@m3nax
Copy link
Contributor Author

m3nax commented Apr 20, 2024

I Will test It tomorrow

@m3nax m3nax marked this pull request as draft April 22, 2024 08:31
@m3nax
Copy link
Contributor Author

m3nax commented Apr 22, 2024

@ReubenBond I have updated the implementation as you suggested but, as it is the first time I have modified a source generator, I did not understand how to remove the double quotes from the list of warnings to be suppressed

Now the output of orleans.g,cs is like this:

#pragma warning disable "CS1591"
[assembly: global::Orleans.ApplicationPartAttribute("ConsoleApp1")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")]
[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.ConsoleApp1.Metadata_ConsoleApp1))]
namespace OrleansCodeGen.ConsoleApp1
{

// CODE

}
#pragma warning restore "CS1591"

Do you have any suggestions?

@ReubenBond ReubenBond self-assigned this May 16, 2024
@m3nax m3nax marked this pull request as ready for review May 28, 2024 08:53
@m3nax
Copy link
Contributor Author

m3nax commented May 28, 2024

@ReubenBond Problem fixed

@ReubenBond ReubenBond merged commit 47b29f8 into dotnet:main May 30, 2024
18 checks passed
@ReubenBond
Copy link
Member

Fantastic, thank you, @m3nax!

@m3nax m3nax deleted the fix-8290-Added-xml-comments-suppression-(CS1591) branch May 30, 2024 14:38
@github-actions github-actions bot locked and limited conversation to collaborators Jun 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CodeGenerator not suppress Missing XML comment
2 participants