我正在处理的 C# 程序集引用了 Newtonsoft.Json 包,在 Visual Studio 中使用 Publish 函数时会自动复制该包。
我使用发布功能将程序集复制到 Unity 项目文件夹中,该文件夹还使用其内部包管理引用 Newtonsoft Json。结果是 Unity 有两个相互冲突的 DLL,这一直困扰着我。解决方案是删除其中一个,但每次我发布时,Visual Studio 都会将 DLL 复制回来。
应该有效但无效的解决方案:
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" CopyToPublishDirectory="Never" />
</ItemGroup>
<ItemGroup>
<Content Update="Newtonsoft.Json.dll">
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</Content>
</ItemGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<ExcludeFilesFromDeployment>Newtonsoft.Json.dll</ExcludeFilesFromDeployment>
</PropertyGroup>
清洁项目。 添加 ExcludeAssets="runtime"
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" ExcludeAssets="runtime"/>