I discovered that an app targeting 4.5 can load and run an assembly targeting 4.5.2 - but I can't compile such a setup!
Question: How can I compile a .NET 4.5 app with a reference to .NET 4.5.2 assembly?
Experiment details:
- MyLib.csproj - Targets 4.5.2
- MyApp.csproj - Targets 4.5, has project reference to MyLib.csproj
Compiling in either Visual Studio or MSBuild fails with:
warning MSB3274: The primary reference "(...)\MyLib.dll" could not be resolved because it was built against the ".NETFramework,Version=v4.5.2" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.5".
error CS0246: The type or namespace name 'MyLib' could not be found (are you missing a using directive or an assembly reference?)
I tried to compile MyLib separately and reference its DLL, but got the same compilation errors.
However, I managed to get both to run:
- Set both projects to 4.5, compile, copy the result to c:\test\MyApp.exe
- Set both projects to 4.5.2, compile, copy the result to c:\test\MyLib.dll
- Run MyApp.exe - runs ok!
Background: I'm preparing a transition of our large NuGet-managed multi-project from .NET 4.5 to 4.5.2. The announcement says It is a highly compatible, in-place update to the .NET Framework 4, 4.5 and 4.5.1
, So I tried what would happen if we upgraded some of our (NuGet-managed) refs to 4.5.2, and non-upgraded projects tried to consume them.