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

内容纲要

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

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

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

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

可以使用 VS 自带的属性管理器去除
《.NET Core 项目发布去除分析器》《.NET Core 项目发布去除分析器》

也可以手动

打开项目 .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>
点赞
  1. cialis cheap说道:

    I'm also writing to make you know what a incredible encounter my friend's girl gained studying your web site. She learned plenty of pieces, which include what it's like to possess an awesome helping nature to let other folks very easily know just exactly several multifaceted subject matter. You truly exceeded people's expectations. Thank you for presenting these powerful, safe, explanatory and in addition fun tips about this topic to Julie.

  2. hemp oil说道:

    I wanted to send you the very little remark to finally thank you the moment again over the spectacular techniques you have shared on this page. This has been simply surprisingly open-handed with you to offer unhampered what most of us would've offered for sale for an ebook in making some bucks for their own end, certainly considering that you could have done it if you considered necessary. The concepts additionally acted as a easy way to be aware that many people have a similar desire just as mine to figure out a great deal more concerning this condition. Certainly there are a lot more enjoyable instances ahead for folks who check out your blog.

发表评论

邮箱地址不会被公开。 必填项已用*标注

You must enable javascript to see captcha here!