I have a C# project (ProjectA) that invokes another C# project (ProjectB) in a separate process. The build output directory structure is:
/ProjectA.exe
/ProjectB/ProjectB.exe
ProjectA and ProjectB reference difference versions of the same assembly, in this case Newtonsoft.Json.dll.
The build output directory structure is achieved by adding a nuget package for ProjectB to ProjectA. ProjectA and ProjectB are in separate solutions and built separately. The nuget package for ProjectB was created with the following .nuspec and .targets.
<?xml version="1.0"?>
<package>
<metadata>
<id>ProjectB</id>
<version>$version$</version>
<title>ProjectB</title>
<authors>me</authors>
<owners>me</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>ProjectB</description>
<copyright>Copyright 2016</copyright>
<tags>ProjectB</tags>
</metadata>
<files>
<file src="x64\Release\*" target="build" />
<file src="ProjectB.targets" target="build/ProjectB.targets" />
</files>
</package>
.
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<NativeLibs Include="$(MSBuildThisFileDirectory)*" />
<Content Include="@(NativeLibs)">
<Link>ProjectB\%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
My problem is that ProjectA is referencing the newer Newtonsoft.Json.dll from the ProjectB nuget package /build directory instead of the older Newtonsoft.Json.dll that is part of the ProjectA solution. They are different versions so this is causing a problem at runtime. I realize I could just update the version of Newtonsoft.Json.dll in the ProjectA solution, but I want to be able to solve the more general case when that is not possible. How can I prevent Visual Studio from finding the wrong Newtonsoft.Json.dll?