I'm creating a reusable library that targets several platforms (.NET 4.0, .NET 4.5, .NETStandard 1.0 and .NETStandard 1.3). The .NET 4.5 version of this project contains some features that are not available under the .NET 4.0 version.
The unit test project that references this library project has one single target platform, namely NET 4.5.1. This test project obviously contains some code that tests the .NET 4.5 specific features of the core library.
Unfortunately however, the test project does not compile, because Visual Studio seems to reference the .NETStandard 1.0 version, which obviously does not contain this feature.
To demonstrate my problem, I reduced this to the following two projects:
Core library:
{
"version": "1.0.0-*",
"frameworks": {
"netstandard1.0": {
"dependencies": {
"NETStandard.Library": "1.6.0"
}
},
"net40": {},
"net45": {}
}
}
Code file:
namespace CoreLibrary
{
#if NETSTANDARD1_0
public class ClassNetStandard { }
#endif
#if NET40
public class ClassNet40 { }
#endif
#if NET45
public class ClassNet45 { }
#endif
}
Test library:
{
"version": "1.0.0-*",
"dependencies": {
"CoreLibrary": { "target": "project" }
},
"frameworks": {
"net451": {}
}
}
Code:
// This compiles
new CoreLibrary.ClassNetStandard();
// This doesn't.
// error: Type or namespace 'ClassNet40' does not exist in namespace 'CoreLibrary'
new CoreLibrary.ClassNet40();
// error: Type or namespace 'ClassNet45' does not exist in namespace 'CoreLibrary'
new CoreLibrary.ClassNet45();
What should I change to allow my unit test project to compile and test the specific .NET 4.5 features?