.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.

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(137)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2018-11-27 xunit输出output到控制台
2018-11-27 Getting Started with xUnit.net (desktop)
2017-11-27 sql server 数据库展开变慢
2017-11-27 kentico中的page template的使用
2017-11-27 asp.net website 单独编译某个页面,连带编译app_code
2017-11-27 kentico在使用局域网ip访问的时候提示Missing license或者Invalid website
2015-11-27 Check if KeyValuePair exists with LINQ's FirstOrDefault
点击右上角即可分享
微信分享提示