A C# assembly i am working on is referencing the package Newtonsoft.Json, which is automatically copied when using the Publish function in Visual Studio.
I am using the Publish function to copy the assembly into a Unity project folder, which is also referencing Newtonsoft Json using its internal package management. The result is that Unity has two conflicting DLLs which it keeps bugging me about. The resolution is to remove one of them, but Visual Studio keeps copying the DLL back in every time I publish.
Solutions that should work, but don't:
Any other file: Settings for any other file
Package Reference Properties: Settings for Package Reference
<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>
Clean project. Add ExcludeAssets="runtime"
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" ExcludeAssets="runtime"/>