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

查看:122
本文介绍了GAC中的程序集不会复制到引用了使用CopyLocal = true引用GAC程序集的项目的项目中的输出中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目A",它引用System.Web.Mvc并具有CopyLocal = TRue. System.Web.Mvc既在我的本地机器上,又在构建服务器上位于GAC中.

I have a "Project A" that references System.Web.Mvc with CopyLocal=TRue. System.Web.Mvc is in the GAC both on my local maching and on the buildserver.

我还有一个项目B",在项目B" System的输出中引用了项目A".在构建过程中未将Web.Mvc复制到该项目.

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.

我怀疑这是因为它在GAC中. 这是真的? 我可以做些什么使MSBuild将其复制到输出文件夹吗?

I suspect that this is because it is in the GAC. Is this true? And can I do something to make MSBuild copy it to the output folder?

我在此线程中阅读了Muse VsExtensions的答案,该内容仅讨论对GAC的直接引用,但是我们通过"Project A"有一个间接引用: .NET参考复制本地"根据GAC的内容设置正确/错误

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

此博文也与以下内容有关: http://deeperdesign.wordpress.com /2010/02/08/msbuild-assembly-dependencies-and-the-gac/

This blogpost is also related: http://deeperdesign.wordpress.com/2010/02/08/msbuild-assembly-dependencies-and-the-gac/

推荐答案

我看到的一个建议是,将所有项目更改为具有相同的输出路径.但是,这是有限的,因为如果您有一个依赖链,例如: Prj B> Prj A> Lib C 那可能是因为Prj A在多个应用程序之间共享,因此您将希望每个应用程序都有自己的输出路径.

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.

我通过使用MSBuild进行编译并在每个版本上设置OutDir属性来解决了该问题.

I resolved the issue by instead using MSBuild to compile, and setting the OutDir property on each build.

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

这会将项目B,其依赖项目(prj A)和prj As的输出全部复制到本地依赖关系中,并放置在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.

在Visual Studio中构建项目时,prj A和prj B都有自己的输出目录,例如prjA\bin\debugprjB\bin\debug.设置为copylocal的GAC存储程序集将包含在直接引用该程序集(prjA)的项目的输出目录中.但是它将复制到引用该项目(prjB)的项目的输出目录中.这就是项目引用复制的工作方式.深入研究MSBuild目标,我确定可以找到潜在的原因(抱歉,我自己没有这样做).

When building the project in Visual Studio, both prj A and prj B have their own output directory, e.g. prjA\bin\debug and prjB\bin\debug. The GAC-stored assembly set to copylocal will be included in the output directory of the project that directly references it (prjA). But it will not be copied to the output directory of the project referencing that project (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).

/p:OutDir=C:\AppBOutput\ MSBuild参数的作用是将所有项目的输出目录设置为相同.这样,您就可以绕开MSBuild行为,即如何复制项目间参考输出.不必依靠MSBuild将prjA\bin\debug中的 some 内容复制到prjB\bin\debug,您只需强制所有项目输出到同一目录即可.

What the /p:OutDir=C:\AppBOutput\ MSBuild parameter does, is set the output directory of all projects to be the same. By doing this, you side-step the MSBuild behaviour of how it copies project-to-project reference outputs. 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.

这篇关于GAC中的程序集不会复制到引用了使用CopyLocal = true引用GAC程序集的项目的项目中的输出中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆