Visual Studio: Prevent CodeAnalysis from running on cs files included via nuget

66 Views Asked by At

I'm referencing the BlingFireNuget package in my csproj. It adds a bunch of files to my project, including a couple cs files, like BlingFireUtils.cs. These are adding hundreds of code analysis warnings when I build:

enter image description here

There must be some way to exclude these from code analysis, but still include them in compilation, but I can't figure out how. I did modify the csproj to at least not include them in Solution Explorer, but that didn't do the trick:

<ItemGroup>
    <Compile Update="@(Compile)">
      <Visible Condition="'%(NuGetItemType)' == 'Compile'">false</Visible>
    </Compile>
</ItemGroup>

Edit:

I did try modifying the .editorconfig to treat these files as generated, even tried the absolute path, and that didn't work either:

[C:\Users\unionp\.nuget\packages\blingfirenuget\0.1.8\contentFiles\cs\any\BlingFireUtils.cs]
generated_code = true

[C:/Users/unionp/.nuget/packages/blingfirenuget/0.1.8/contentFiles/cs/any/BlingFireUtils.cs]
generated_code = true
1

There are 1 best solutions below

4
Jonathan Dodds On

Create or modify your .editorconfig file and list the files as generated_code. See "Configure Generated code".

Example:

[BlingFireUtils.cs]
generated_code = true

Multiple files can be listed in one .editorconfig section header as:

[file0.cs,file1.cs]
generated_code = true