.NET Core 项目发布去除分析器

2020年3月6日 3985点热度 1人点赞 2条评论
内容纲要

为了提高项目代码质量,所以往往会安装分析器。

file

但是呢,这些分析器在生成项目程序文件时,占了 10MB。这些 dll 用不上的,没必要留着占空间。

file

可以使用 VS 自带的属性管理器去除
filefile

也可以手动

打开项目 .csproj 文件,找到如下的两个节点

  <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>

这两个就是 Debug ,reseale 的配置,除这一行。

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

然后找到

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

在 Include 前加上 Condition="'$(Configuration)'=='DEBUG'",

例如

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

痴者工良

高级程序员劝退师

文章评论