Reference multitarget class library in VS2017 solution

481 Views Asked by At

In VisualStudio 2017 I created a class library which targets .net 4.0 (to support legacy applications on win XP) and 4.6.1 framework. I did this by making use of the new .csproj format which allows to specify multiple target frameworks as shown below.

<PropertyGroup>
    <TargetFrameworks>net40;net472</TargetFrameworks>
</PropertyGroup>

Building the library for both frameworks works perfectly. I get my two folders, net40 and net472 which contain both a dll for the specific target framework.

In my solution, I now have two further projects. One WinForms App that references my library and a WPF App which also references it. WinForms App should use net40 and WPF App net472 version of my library.

When I add a project reference to the library in my WinForms App it uses net40 version. Everything fine.

But when I reference the class library project to my WPF application (which builds for net472) it also uses the net40 dll. But I want my WPF app to use the net472 version of the library.

Is there any possibility to select the target framework when referencing a multitarget class library as project reference in VS2017?

Update: When I build a multitarget nuget package from the library and use the package to reference it, everything is fine. WPF app uses net472 and WinForms net40 automatically.

0

There are 0 best solutions below