Copy all dependencies from .Net Standard libraries to .Net Framework Console application
Asked Answered
J

3

28

After consuming .net standard projects in a .net framework(4.6) console application, the dependencies of the .net standard projects are not copied into the output directory. This results in run time error of missing dlls. The "copy local" property is already true for the referenced projects. One possible solution is to add all the dependencies again in the console application, but is not a good idea. Is there a better solution to this?

Jagir answered 3/7, 2018 at 12:59 Comment(0)
J
43

After going through an article by Scott Hanselman, below solution worked like a charm.

"Using .NET Standard requires you to use PackageReference to eliminate the pain of “lots of packages” as well as properly handle transitive dependencies. While you may be able to use .NET Standard without PackageReference, I wouldn’t recommend it."

Add below line in the first "PropertyGroup" tag of the .net framework console application's ".csproj" file

<RestoreProjectStyle>PackageReference</RestoreProjectStyle>

There will not be any need to add again the .net standard projects' nuget dependencies in the console application.

Jagir answered 3/7, 2018 at 12:59 Comment(3)
That Hanselman article is great - thanks for the linkCreodont
Sadly, adding the above xml to my .csproj causes the project to fail to loadCreodont
For me, adding that line leads to nuget packages not being shown anymore in "manage nuget packages". I could solve it by migrating my packages.config to the new PackageReference format: Right click packages.config file and choose "Migrate packages.config to PackageReference...".Canakin
A
2

In my situation, I needed the dependencies to copy to the build directory of the .NET Standard project and not have to modify the "exit project" in order for them to appear.

This comment thread had the solution I needed: https://github.com/dotnet/sdk/issues/747#issuecomment-518156718

add to [.NET Standard] csproj

<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

after

<TargetFramework>netstandard2.0</TargetFramework>

After making this change, all of the projects which referenced this .NET Standard project included all its dependency DLL's.

Note that I am using this .NET Standard project within a solution with other .NET Framework projects and linking it with a project reference. I have not tested the behavior when deploying over Nuget.

Autonomous answered 8/6, 2023 at 13:34 Comment(2)
This includes even System assemblies which is a bit rich in most cases. That said so does the publish option. Is this common for all libs or just .netstandard?Balefire
I have seen this behavior with .NET Core projects. If you have a 6/7/8 project referenced somewhere in the dependencies then I would speculate this is possible.Autonomous
A
0

Another answer is to publish the project:

dotnet publish -o path/to/output/folder
Akeyla answered 22/10, 2020 at 14:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.