防止使用 Visual Studio Publish 复制包引用

问题描述 投票:0回答:1

我正在处理的 C# 程序集引用了 Newtonsoft.Json 包,在 Visual Studio 中使用 Publish 函数时会自动复制该包。

我使用发布功能将程序集复制到 Unity 项目文件夹中,该文件夹还使用其内部包管理引用 Newtonsoft Json。结果是 Unity 有两个相互冲突的 DLL,这一直困扰着我。解决方案是删除其中一个,但每次我发布时,Visual Studio 都会将 DLL 复制回来。

应该有效但无效的解决方案:

  • 我发现很多对某些“复制到输出目录”设置的引用,该设置适用于大多数文件,但不适用于包引用。

任何其他文件: Settings for any other file

包参考属性: Settings for Package Reference

  • 我还在 .csproj 中找到了对 CopyToPublishDirectory 设置的引用,我尝试过,但它要么不起作用,要么我无法获得正确的语法。
  1. 在包装参考中:
  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" CopyToPublishDirectory="Never" />
  </ItemGroup>

  1. 在内容更新块中:
  <ItemGroup>
    <Content Update="Newtonsoft.Json.dll">
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </Content> 
  </ItemGroup>

  • 我尝试了一些可能在 .csproj 中工作的其他设置:
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <ExcludeFilesFromDeployment>Newtonsoft.Json.dll</ExcludeFilesFromDeployment>
  </PropertyGroup>
c# visual-studio package .net-assembly
1个回答
0
投票

清洁项目。 添加 ExcludeAssets="runtime"

<PackageReference Include="Newtonsoft.Json" Version="13.0.3"  ExcludeAssets="runtime"/>
© www.soinside.com 2019 - 2024. All rights reserved.