Disclaimer: I don’t recommend a solution that contains projects targeting different versions of the .NET framework. However there are legitimate cases (e.g. inherited code), that demand solutions rather than a rewrite. You may decide to use a later version of the .NET framework than some of the existing code. If you mix these projects in the same solution and use the same nuget packages in different projects, you will get the following error.
MSBuild builds your solution in an order that determines dependencies but leaves the rest to chance. When nuget package references are resolved, they include the .NET version. By default MSBuild builds the solution into a single output directory. This means that if project A references package X and targets .NET 4.0 and project B references package X and targets .NET 4.5 then the last one to be built will overwrite the previous one’s package X dll. This will cause the build to fail.
But fear not, there is a solution.
Update the Output Location
- Edit the build definition
- Navigate to
2. Build
- Change
4. Output Location
from toAsConfigured
Yay! Our build works again, but our unit tests won’t be run as part of the build.
Update our Test Run Settings
- Edit the build definition
- Navigate to
3. Test
- Go to
1. Automated Tests
- Expand
1. Test Source
- Click the ellipse on
Run Settings
- Add ..\src\*\bin\*\*test*.dll to the default
Test assembly file specification
which is**\*test*.dll;**\*test*.appx
This important step instructs msbuild to look for unit tests in the source directories bin folders in addition to the standard single bin for the solution.
Now your tests will actually get run as part of your build.