简体   繁体   English

GAC中的程序集不会复制到项目中的输出,该项目引用引用具有CopyLocal = true的GAC程序集的项目

[英]Assembly in GAC is not copied to output in project that references a project that references the GAC assembly with CopyLocal=true

I have a "Project A" that references System.Web.Mvc with CopyLocal=TRue. 我有一个“Project A”,它引用System.Web.Mvc和CopyLocal = TRue。 System.Web.Mvc is in the GAC both on my local maching and on the buildserver. System.Web.Mvc在我的本地机器和构建服务器上都在GAC中。

I also have a "Project B" that references "Project A" in the output for "Project B" System.Web.Mvc is not copied to during the build. 我还有一个“项目B”,在“项目B”System.Web.Mvc的输出中引用“项目A”,在构建期间不会复制到该项目。

I suspect that this is because it is in the GAC. 我怀疑这是因为它在GAC中。 Is this true? 这是真的? And can I do something to make MSBuild copy it to the output folder? 我可以做些什么来让MSBuild将它复制到输出文件夹吗?

I read the answer from Muse VsExtensions in this thread, which talks about only the direct reference to the GAC, however we have an indirect reference through "Project A": .NET Reference "Copy Local" True / False Being Set Based on Contents of GAC 我在这个帖子中读到了Muse VsExtensions的答案,它只讨论了对GAC的直接引用,但我们通过“项目A”间接引用: .NET参考“复制本地”真/假根据内容设置GAC

This blogpost is also related: http://deeperdesign.wordpress.com/2010/02/08/msbuild-assembly-dependencies-and-the-gac/ 这篇博文也是相关的: http//deeperdesign.wordpress.com/2010/02/08/msbuild-assembly-dependencies-and-the-gac/

Did you check the .csproj file to verify that the reference does indeed contain the <Private>True</Private> tag? 您是否检查.csproj文件以验证引用确实包含<Private>True</Private>标记? Copy local is unfortunately has 3 states in the xml - True, False and ... missing. 不幸的是,复制本地在xml中有3个状态 - True,False和......缺失。

A pragmatic (read hack) solution is that I referenced System.Web.Mvc.dll in "Project B". 一个实用的(读取黑客)解决方案是我在“Project B”中引用了System.Web.Mvc.dll。 This is definitively not the right solution, so please bring me a better solution :-) 这绝对不是正确的解决方案,所以请给我一个更好的解决方案:-)

One suggestion I've seen floating around for this one is to change all of your projects to have the same output path. 我见过的一个建议就是将所有项目更改为具有相同的输出路径。 This is of limited value though, since if you have a dependency chain like: Prj B > Prj A > Lib C Then it's probably because Prj A is shared across multiple applications, for which you will want to each have their own output path. 这是有限的价值,因为如果你有一个依赖链如:Prj B> Prj A> Lib C那么可能是因为Prj A在多个应用程序之间共享,你需要为每个应用程序分别拥有自己的输出路径。

I resolved the issue by instead using MSBuild to compile, and setting the OutDir property on each build. 我通过使用MSBuild进行编译并在每个构建上设置OutDir属性来解决问题。

eg MSBuild projectB.csproj /p:OutDir=C:\\AppBOutput\\ 例如MSBuild projectB.csproj /p:OutDir=C:\\AppBOutput\\

This will put the output for project B, its dependent projects (prj A), and prj As copy local dependencies all into the C:\\AppBOutput\\ directory. 这将把项目B的输出,它的依赖项目(prj A)和prj As复制到C:\\ AppBOutput \\目录中。

Why it Works 为什么会这样

When building the project in Visual Studio, both prj A and prj B have their own output directory, eg prjA\\bin\\debug and prjB\\bin\\debug . 在Visual Studio中构建项目时,prj A和prj B都有自己的输出目录,例如prjA\\bin\\debugprjB\\bin\\debug The GAC-stored assembly set to copylocal will be included in the output directory of the project that directly references it (prjA). 设置为copylocal的GAC存储的程序集将包含在直接引用它的项目的输出目录中(prjA)。 But it will not be copied to the output directory of the project referencing that project (prjB). 但它不会被复制到引用该项目(prjB)的项目的输出目录中。 That's just how the project reference copying works. 这就是项目引用复制的工作原理。 Dig into the MSBuild targets and I'm sure the underlying reason could be found (sorry, not doing it myself). 深入了解MSBuild目标,我确信可以找到潜在的原因(抱歉,不是自己动手)。

What the /p:OutDir=C:\\AppBOutput\\ MSBuild parameter does, is set the output directory of all projects to be the same. 什么/p:OutDir=C:\\AppBOutput\\ MSBuild参数,将所有项目的输出目录设置为相同。 By doing this, you side-step the MSBuild behaviour of how it copies project-to-project reference outputs. 通过这样做,您可以逐步执行MSBuild如何复制项目到项目引用输出的行为。 Instead of relying on MSBuild to copy some of the content in prjA\\bin\\debug to prjB\\bin\\debug , you just force all projects to output to the same directory. 您只需强制所有项目输出到同一目录,而不是依赖MSBuild将prjA\\bin\\debug 某些内容复制到prjB\\bin\\debug

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM