vstest icon indicating copy to clipboard operation
vstest copied to clipboard

The AutoGeneratedProgram class created for netcoreapp projects does not have a CompilerGenerated attribute

Open jayaranigarg opened this issue 9 years ago • 3 comments

Steps to Repro

I created an xUnit test project in Visual Studio 2017 RC3(15.0.26206.0) that targets .NETCoreApp 1.1. Thereafter added a Roslyn-based code analyzer via NuGet, and it unexpectedly flagged several warnings in an auto-generated {ProjectName}.Program.cs file.

The content of the file is: // This file has been auto generated. using System; class AutoGeneratedProgram {static void Main(string[] args){}}

The AutoGeneratedProgram class should be marked with the CompilerGenerated attribute to follow established conventions that allow tools such as code analyzers to identify (and ignore) generated code.

Expected behavior

No warnings should be there.

Actual behavior

Observed warnings like 1>obj\Debug\netcoreapp1.1\XUnitTestProject1.Program.cs(2,58,2,65): warning CT3103: Types should have an access modifier specified. 1>obj\Debug\netcoreapp1.1\XUnitTestProject1.Program.cs(2,58,2,65): warning CT1000: Classes with all static members should be static. 1>obj\Debug\netcoreapp1.1\XUnitTestProject1.Program.cs(2,79,2,83): warning CT3104: Members should have an access modifier specified.

jayaranigarg avatar Feb 17 '17 12:02 jayaranigarg

~~Is there a workaround available?~~

Edit: If anyone finds this issue and is looking for a fix to get rid of style cop errors. Update the xunit nuget package. This comment helped me.

Alexxtheonly avatar Mar 08 '17 10:03 Alexxtheonly

Not reproable in VS2017.5 Version 15.5.0 Preview 4.0 [27109.1.d15rel] Created xUnit NetCore test project, & built it

mayankbansal018 avatar Nov 17 '17 10:11 mayankbansal018

Added "Microsoft.CodeAnalysis" to Xunit project, & then built it, no warnings.

mayankbansal018 avatar Nov 20 '17 07:11 mayankbansal018