.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:
- Make sure the NuGet package is installed in Project A;
- 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 |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.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