dotnet / project-system

The .NET Project System for Visual Studio
MIT License
968 stars 387 forks source link

Visual Studio new projects not adhering to Microsoft.CodeAnalysis.FxCopAnalyzers #5274

Closed vsfeedback closed 3 years ago

vsfeedback commented 5 years ago

This issue has been moved from a ticket on Developer Community.


When one creates a new Visual Studio project from one of the templates, and then analyze it using the FxCopAnalyzers (and probably other Microsoft.CodeAnalysis analyzers) then there are many warnings.

My suggestion is that Microsoft should update their templates to adhere to this, and ideally all other Roslyn analyzers.


Original Comments

Jane Wu [MSFT] on 7/22/2019, 03:53 AM:

Thank you for taking the time to provide your suggestion. We will do some preliminary checks to make sure we can proceed further. We’ll provide an update once the issue has been triaged by the product team.

mavasani commented 5 years ago

Tagging @dotnet/project-system

I believe this is by design, but I would let the project system team to triage. The templates are designed to explicitly have some unused code (usings and args parameter for Main method in console app) to allow beginner developers to easily quick start development. Additionally, it is not possible for the templates to account for various third party analyzers that might be out there.

@vatsalyaagrawal @jinujoseph Can we port this issue to project-system repo?

davkean commented 4 years ago

Triage: Can you investigate what warnings/errors show up by default and send this back to triage?

ocallesp commented 4 years ago

I thinks this is by design. I don't think we can have all templates (for beginner developers) code with 0 warnings using Analyzers. I would only make changes to templates if an important security checkers or errors detected by the analyzer (from microsoft).

The templates show only few warnings using the Analyzer. We can: 1) Fix the templates so that Analyzer will show 0 warning/errors. disadvantage: Will make the code more complicated to understand for beginner developers. advantage: Analyzer will show 0 warnings

2) Mark this as won't fix. disadvantage: - The advanced developer should fix only few warning.

3) Make the minimum changes to templates in places not relevant to the beginner developer. advantage: less warnings after the Analyzer is installed.

Console App warning CA1303: Method 'void Program.Main(string[] args)' passes a literal string as parameter 'value' of a call to 'void Console.WriteLine(string value)'. Retrieve the following string(s) from a resource table instead: "Hello World!". warning CA1801: Parameter args of method Main is never used. Remove the parameter or use it in the method body.

Windows Forms (.net) warning CA2000: Call System.IDisposable.Dispose on object created by 'new Form1()' before all references to it are out of scope.

ASP.NET Core Web Application (Empty) warning CA1052: Type 'Program' is a static holder type but is neither static nor NotInheritable warning CA1822: Member ConfigureServices does not access instance data and can be marked as static (Shared in VisualBasic) warning CA1822: Member Configure does not access instance data and can be marked as static (Shared in VisualBasic) warning CA2007: Consider calling ConfigureAwait on the awaited task warning CA1801: Parameter services of method ConfigureServices is never used. Remove the parameter or use it in the method body.

Class Library (.Net Standard) No warnings

Blazor App warning CA1052: Type 'Program' is a static holder type but is neither static nor NotInheritable warning CA1822: Member GetForecastAsync does not access instance data and can be marked as static (Shared in VisualBasic) warning CA1822: Member Configure does not access instance data and can be marked as static (Shared in VisualBasic) warning CA1822: Member ConfigureServices does not access instance data and can be marked as static (Shared in VisualBasic)

ASP.NET Core Web Application (Model-view-controller) warning CA1052: Type 'Program' is a static holder type but is neither static nor NotInheritable warning CA1822: Member ConfigureServices does not access instance data and can be marked as static (Shared in VisualBasic) warning CA1822: Member Configure does not access instance data and can be marked as static (Shared in VisualBasic)

ASP.NET Core Web Application (API) warning CA1052: Type 'Program' is a static holder type but is neither static nor NotInheritable warning CA1822: Member ConfigureServices does not access instance data and can be marked as static (Shared in VisualBasic) warning CA1822: Member Get does not access instance data and can be marked as static (Shared in VisualBasic) warning CA1822: Member Configure does not access instance data and can be marked as static (Shared in VisualBasic)