引用的System.Net.Http程序集未复制到dotnet msbuild上的输出bin \ Release目录 [英] Referenced System.Net.Http assembly is not copied to the output bin\Release catalog on dotnet msbuild
问题描述
我具有以下项目配置:
1) Project1
:.NET Framework 4.6.1项目
1) Project1
: .NET Framework 4.6.1 project
2) Project2
:具有< TargetFrameworks> netstandard2.0; net461</TargetFrameworks>
3) Project3
:具有< TargetFrameworks> netstandard2.0; net461</TargetFrameworks>
因此, Project3
引用了 System.Net.Http
. Project2
引用 Project3
和 Project1
引用 Project2
.
So, Project3
references System.Net.Http
. Project2
references Project3
and Project1
references Project2
.
当我在Visual Studio 2017中构建任何配置时, Project1 \ bin \%Configuration%\
目录包含 System.Net.Http.dll
以及其他系统
程序集.
When I build any configuration in Visual Studio 2017 the Project1\bin\%Configuration%\
directory contains System.Net.Http.dll
as well as other System
assemblies.
我还可以看到在 Project1.exe.conf
中生成了以下绑定重定向:< dependentAssembly>< assemblyIdentity name ="System.Net.Http" publicKeyToken ="b03f5f7f11d50a3a" culture ="neutral"/>< bindingRedirect oldVersion ="0.0.0.0-4.1.1.2" newVersion ="4.1.1.2"/></dependentAssembly>
Also I can see that the following binding redirect is generated in Project1.exe.conf
:
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.1.2" newVersion="4.1.1.2" />
</dependentAssembly>
当我使用 dotnet msbuild
进行构建(导航至解决方案文件夹并使用以下命令: dotnet msbuild/p:Configuration = Release
)时,所有内容均会成功构建,但是同一目录中缺少 System.Net.Http
dll.
When I use dotnet msbuild
to build (navigate to the solution folder and use the following command: dotnet msbuild /p:Configuration=Release
) everything builds successfully but the System.Net.Http
dll is missing from the same directory.
在Visual Studio外部运行应用程序时,在运行时出现以下错误:无法加载文件或程序集System.Net.Http,Version = 4.1.1.2
.
When I run the application outside of the Visual Studio I get the following error during runtime: Could not load file or assembly System.Net.Http, Version=4.1.1.2
.
为什么?如何使用 dotnet msbuild
工具确保所有引用的程序集都已复制?
Why? How do I use the dotnet msbuild
tooling to ensure all referenced assemblies are copied?
更新:我的 dotnet
版本是 2.1.2
.
谢谢.
推荐答案
作为nuget引用添加的System软件包会发生一些奇怪的事情.不需要添加系统库作为软件包,它们应该存在于主机上,但是在少数情况下,有必要,我认为System.Runtime.Caching存在与版本冲突相关的类似问题.
There is something strange that happens with System packages that are added as nuget references. There should be no need to add System libraries as packages, they should exist on the host, but in a few cases, it is necessary, I think a similar issue exists with System.Runtime.Caching related to version conflicts.
我认为问题在于,由于该库位于GAC中,因此构建系统会忽略将其复制到输出中的假设,前提是该库存在且无需打包即可.
I think the problem is that since the library is in the GAC, the build system ignores copying it to the output assuming that it is present and available without needing to be packaged.
您可能会想到,Visual Studio会按照自己的规则运行,这确实很烦人,因为很难知道问题发生的原因.
Visual Studio, as you might imagine, behaves by its own rules which is really annoying because it is hard to see why the problem is happening.
更让人烦恼的是,我不太记得要修复它所要做的事情.我可能已经从GAC卸载了该库,将引用属性Copy Local设置为true(如果尚未设置),或者可能直接从磁盘上的SDK位置引用了dll(copy local = true),并且不使用nuget包.全部.
To be extra annoying, I can't quite remember what I had to do to fix it. I might have uninstalled the library from the GAC, set the reference properties Copy Local to be true (if not already) or possibly referenced the dll directly from the SDK location on disk (with copy local = true) and not use the nuget package at all.
这篇关于引用的System.Net.Http程序集未复制到dotnet msbuild上的输出bin \ Release目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!