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?
3 Answers
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.
-
That Hanselman article is great - thanks for the link – dlchambers Oct 27 '20 at 11:46
-
Sadly, adding the above xml to my .csproj causes the project to fail to load – dlchambers Oct 27 '20 at 11:57
-
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...". – IngoB Nov 11 '21 at 11:16
Another answer is to publish the project:
dotnet publish -o path/to/output/folder

- 1,362
- 13
- 26
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.

- 6,378
- 2
- 28
- 33