Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing .NET Standard csproj project from .NET Framework traditional project

I have a library written against .NET Standard 1.3 which should be compatible with the .NET Framework 4.6.1 runtime. The library uses the new csproj and works fine when referenced by .NET Core projects.

I also have a WPF project on a traditional csproj which should be able to use this library. In Visual Studio 2017 I managed to reference the .NET Standard library and it compiles without errors.

At runtime, it tries to load assemblies which are dependencies of the .NET Standard project and it fails with assembly not found exceptions. And I can see that my output folder doesn't have any of the dependencies indeed.

Is there a way to reference my library in such a way all the required dependencies are copied to the output folder (or an equivalent solution to make the WPF project run fine)?

Note: If I reference manually one by one all the missing dependencies and use runtime assembly version binding I can make it run, but I shouldn't really do this when referencing a project.

This is the full project page: https://github.com/UnoSD/PasswordManager

.NET Standard csproj

WPF package.config

WPF csproj

It currently is a Roslyn problem: GitHub issue

like image 528
Stefano d'Antonio Avatar asked Mar 08 '17 13:03

Stefano d'Antonio


2 Answers

It is an active issue on Roslyn:

https://github.com/dotnet/roslyn/issues/17639

https://github.com/NuGet/Home/issues/4488

like image 89
Stefano d'Antonio Avatar answered Oct 10 '22 12:10

Stefano d'Antonio


You have to specify compiler output for .NET 4.6.1

Put line like below into your csproj in your .NET Standard library project.

<TargetFrameworks>netstandard1.4;net461</TargetFrameworks>

(that should go instead <TargetFramework>netstandard1.4</TargetFramework>)

Build will produce binaries both for .NET 4.6.1 and .NET Core runtime compatible with NET Standard 1.4.

like image 42
pkmiec Avatar answered Oct 10 '22 10:10

pkmiec