Enabling Microsoft's Code Analysis on .NET Core Projects

后端 未结 2 843
天命终不由人
天命终不由人 2020-12-29 03:17

Our team uses the Code Analysis feature with a custom ruleset to cause our build to fail if we forget to do things like null checks on method arguments.

However, now

2条回答
  •  温柔的废话
    2020-12-29 03:31

    Normally, the only thing you need to do is install the Microsoft.CodeAnalysis.FxCopAnalyzers nuget on your project.

    But as mentioned correctly, this does not work, especially for .Net Core (currently in vs2017).

    In order to work for aspnet core projects, as well, and resolve the error:

    "Could not identify platform for ..."

    Manually modify the project's csproj file and make sure to not insert the RunCodeAnalysis tag. Make the PropertyGroup like that:

    
      netcoreapp2.2
      ..\MyStylecop.ruleset
    
    

    Also, if you need to put a given ruleset file, make sure to place it to the correct path, as seen above ..\MyStylecop.ruleset. MyStylecop.ruleset is the file with the rules (actually the ones suppresed I think - so it is inverse logic).

    For example my ruleset file is:

    
    
      
      
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
      
      
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
      
    
    

提交回复
热议问题