How can I compile a .NET 4.5 application with reference to a .NET 4.5.2 assembly?

I found that targeting application 4.5 can load and run assembly assembler 4.5.2, but I cannot compile such a setting!

Question How can I compile a .NET 4.5 application with reference to a .NET 4.5.2 assembly?

Experiment Details:

  • MyLib.csproj - goals 4.5.2
  • MyApp.csproj - Goals 4.5, has a link to the MyLib.csproj project

Compilation in Visual Studio or MSBuild fails:

warning MSB3274: The main link "(...) \ MyLib.dll" could not be resolved because it was built as part of ".NETFramework, Version = v4.5.2." This is a higher version than the current target environment is ".NETFramework, Version = v4.5".
error CS0246: Could not find the name or namespace name MyLib (are you missing the using directive or assembly references?)

I tried to compile MyLib separately and reference its DLL, but got the same compilation errors.

However, I managed to start both starts:

  • Install both projects in 4.5, compile, copy the result to c: \ test \ MyApp.exe
  • Install both projects in 4.5.2, compile, copy the result to c: \ test \ MyLib.dll
  • Run MyApp.exe - it works fine!

Background: I am preparing a migration of a large NuGet-managed project from .NET 4.5 to 4.5.2. Announcement

+8
source share
2 answers

You can try to create the .NET Standard library, not the .NET Framework 4.X

See the linked stream.

0
source share

For backward compatibility, you can use multi-targeting. Open the .csproj file and modify it as follows:

  <PropertyGroup> <TargetFrameworks>net462;netstandard1.6</TargetFrameworks> <PreserveCompilationContext>true</PreserveCompilationContext> </PropertyGroup> 

This is an example .nuget package for two frameworks: net462 and netstandard1.6

When building, it will create two folders with libraries:

  • net462
  • netstandard1.6
0
source share

All Articles