如何从发布中排除Microsoft.CodeAnalysis。* DLL

时间:2020-09-21 20:26:03

标签: asp.net-core .net-core

我已经编写了依赖于Microsoft.AspNetCore.Mvc v2.2.0包的.NET Standard 2.1库组件,该包间接引用了Microsoft.CodeAnalysis.CSharp.dll,MicrosoftCode.Analysis.dll和Microsoft.CodeAnalysis.Razor。 dll。当我从.NET Core 3.1应用程序站点引用我的组件并发布该站点时,还将发布Microsoft.CodeAnalysis。* dll。有没有办法排除Microsoft.CodeAnalysis。* dll的发布?我不需要它们进行生产。

这是我从.NET Standard 2.1 CSPROJ文件中引用的内容:

 <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="3.1.8" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.Abstractions" Version="3.1.8" />
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="3.1.8" />
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="3.1.8" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Language" Version="3.1.8" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="3.1.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.8" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="3.1.6" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="3.1.8" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />

谢谢!

1 个答案:

答案 0 :(得分:2)

该问题似乎来自直接引用AspNetCore软件包。

如果您可以将类库更改为目标netcoreapp3.1而不是netstandard,则可以使用FrameworkReference来替换它们。请注意,FrameworkReference仅对面向Net Core 3.x及更高版本的程序集有效。 Reference

<ItemGroup>
  <FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

或者,如果您需要同时支持netstandardnetcoreapp,则可以使用条件引用。

<!-- Framework reference for netcoreapp -->
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
  <FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<!-- Common dependencies -->
<ItemGroup>
  <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
  </PackageReference>
  <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.8" />
  <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>

<!-- netstandard dependencies -->
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
  <PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="3.1.8" />
  <PackageReference Include="Microsoft.AspNetCore.DataProtection.Abstractions" Version="3.1.8" />
  <PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="3.1.8" />
  <PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="3.1.8" />
  <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
  <PackageReference Include="Microsoft.AspNetCore.Razor.Language" Version="3.1.8" />
  <PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="3.1.6" />
  <PackageReference Include="Microsoft.Extensions.DependencyModel" Version="3.1.6" />
  <PackageReference Include="Microsoft.Extensions.Identity.Core" Version="3.1.8" />
</ItemGroup>

请注意,我必须猜测哪个软件包引用了您的软件包库,因此您需要根据需要进行调整