.NET Standard library output doesn't include nuget dependencies

Some dll from nuget packages are not copied to /bin

In order to answer your question precisely, we'd need to know a couple of things.

One explanation depends on what references you have in Project A. For example, it could be that project A, other than referencing project B, also includes additional references, among which there are Microsoft.ApplicationServer.Caching.Client and Microsoft.ApplicationServer.Caching.Core, maybe with the option Copy local set to false - but not log4net. In this case, the copy of the former two will happen only for Project B.

Another possible explanation depends on what your code does with the references in project A and project B. The MSBuild process does not automatically copy assemblies of references that are not actually used in a project.

Finally, in case you are relying on Build Events to copy references, have a look at the Output panel to make sure that there are no errors despite a successful compilation.

In any case, in order to make sure that all NuGet packages are copied, I find it useful to edit the .csproj file and, among the <PropertyGroup> tag, add this:

<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

From the documentation:

If you set this CopyLocalLockFileAssemblies to true, any NuGet package dependencies are copied to the output directory. That means you can use the output of dotnet build to run your plugin on any machine.

As per its documentation, <CopyLocalLockFileAssemblies> copies any explicitly linked NuGet dependency into the output directory of the project. It naturally follows that if you want Project A to have a copy of a NuGet dll in its output directory, but the Project A does not copy it because e.g. it falls in the first or second case outlined above, then an option can be:

  1. Make sure the NuGet package is installed in Project A;
  2. add <CopyLocalLockFileAssemblies> in Project A's csproj file.

This is not a silver bullet, i.e. it won't work if the error lies in e.g. the third case outlined above.

.NET Standard library output doesn't include nuget dependencies

编译.net standard项目的时候,bin/Debug目录下,没有依赖的项目。设置CopyLocalLockFileAssemblies

Here is another suggestion, taken from CEZARY PIĄTEK's blog

 <Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>    
  </PropertyGroup>
</Project>

 

How do I get .NET Core projects to copy NuGet references to the build output?

You can add this to a <PropertyGroup> inside your csproj file to enforce copying NuGet assemblies to the build output:

<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

However, note that the build output (bin/Release/netcoreapp*/*) is not supposed to be portable and distributable, the output of dotnet publish is. But in your case, copying the assemblies to the build output is probably very useful for testing purposes. But note that you could also use the DependencyContext api to resolve the DLLs and their locations that are part of the application's dependency graph instead of enumerating a local directory.

 

posted @ 2020-11-27 13:50  ChuckLu  阅读(123)  评论(0编辑  收藏  举报