Removing Analyzers from .NET Core Project Publishing

2020年3月6日 4993点热度 1人点赞 2条评论
内容目录

To improve project code quality, analyzers are often installed.

file

However, these analyzers occupy 10MB when generating project program files. Since these DLLs are unnecessary, they should not be left taking up space.

file

You can use the built-in Property Manager in VS to remove them.

filefile

You can also do this manually.

Open the project .csproj file and find the following two nodes:

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <CodeAnalysisRuleSet>Alarm.Cpanel.ruleset</CodeAnalysisRuleSet>
    <DefineConstants>TRACE;CORS;GY</DefineConstants>
    <DocumentationFile></DocumentationFile>
    <OutputPath></OutputPath>
  </PropertyGroup>
  
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <CodeAnalysisRuleSet>Alarm.Cpanel.ruleset</CodeAnalysisRuleSet>
    <DefineConstants>CORS;GY</DefineConstants>
  </PropertyGroup>

These two are the configurations for Debug and Release. Remove the following line:

<CodeAnalysisRuleSet>Alarm.Cpanel.ruleset</CodeAnalysisRuleSet>

Then find:

    <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>

Add Condition="'$(Configuration)'=='DEBUG'" in front of Include,

for example:

    <PackageReference Condition="'$(Configuration)'=='DEBUG'" Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>

痴者工良

高级程序员劝退师

文章评论