tech-y
tech-y

Reputation: 1867

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

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?

Upvotes: 28

Views: 8895

Answers (3)

Jason Faulkner
Jason Faulkner

Reputation: 6558

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.

Upvotes: 2

tech-y
tech-y

Reputation: 1867

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.

Upvotes: 43

FrozenKiwi
FrozenKiwi

Reputation: 1513

Another answer is to publish the project:

dotnet publish -o path/to/output/folder

Upvotes: 0

Related Questions