MsBuild:将引用从 ProjectReference 更改为 Reference

发布于 2024-09-14 21:27:49 字数 253 浏览 2 评论 0原文

在我们的环境中,我们有两个内部框架和一个单独的网站。在开发过程中,对内部框架的引用往往设置为项目引用。然而,一旦我们开始发布,内部框架就会安装到 GAC 中,因为它们用于每台服务器上网站的多个实例。所有 ProjectReferences 都手动更改为 References,并且网站程序集和网站都被重新编译和部署。

我正在尝试自动化这个过程。处理这些问题的最佳方法是什么?我已经开始学习 MsBuild 试图实现这一目标,但我完全感到困惑。关于如何进行的任何指示和/或建议?

In our environment, we have two in-house frameworks and a separate website. During development, the references to the in-house frameworks tend to be set tp project references. However, once we move to release, the in-house frameworks are installed into the GAC as they are used for multiple instances of the website on each server. All of the ProjectReferences are changed, by hand, to References and the website assemblies and website are re-compiled and deployed.

I am attempting to automate this process. What is the best way to handle these issues? I have started to learn MsBuild in the attempt to accomplish this, but am totally confused. Any pointers and/or suggestions on how to proceed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

悲凉≈ 2024-09-21 21:27:49

据我所知,不需要从使用项目引用更改为文件引用,仅仅因为程序集已在 GAC 中注册 - 只要引用的项目在构建时是强类型的,参考应该仍然有效。

说明

GAC 引用和文件引用之间没有根本区别 - 如果您有对强命名程序集的引用,并且该程序集放置在 GAC 中,则最终应用程序将加载该程序集来自 GAC。

有关运行时如何查找引用程序集的详细信息,请参阅此链接:

仅供参考 - 我相信建议您不要引用程序集它们物理上位于 GAC 中,并且您可以在将其放入 GAC 之前引用强命名程序集(不要与该程序集是否应安装到最终用户计算机上的 GAC 相混淆)

As far as I am aware there shouldn't be any need to change from using project references to file references simply because the assembly is registered in the GAC - as long as the referenced project is strongly typed at the point that it is built, the reference should still be valid.

Clarification:

There is no fundamental difference between a GAC reference and a file reference - if you have a reference to a strongly named assembly, and that assembly is placed in the GAC then the end application will load that assembly from the GAC.

See this link for more information on how the runtime locates referenced assemblies:

FYI - I believe it is recommended that you don't reference assemblies which are in physically in the GAC, and that you instead reference the strongly named assembly before it is placed in the GAC (not to be confused with whether or not the assembly should be installed to the GAC on the end-user machine)

叹倦 2024-09-21 21:27:49

如果您保留项目引用,MSBUILD 会将所有项目引用作为 DLL 复制到目标网站的 bin 目录中,即使您已将这些 DLL 安装到 GAC 中,我认为这就是您想要在发布级别更改此设置的原因——这样可以节省空间。

我还假设您打算仅在发布分支上执行此操作,而不是在源代码管理的开发分支上执行此操作。因为如果您在源代码管理的所有分支上执行此操作,那么手动执行实际上是一次性更改的最佳且最快的方法。

要在 MSBUILD 中执行此操作,您将需要创建一个可以修改项目文件的自定义任务。项目文件是一个 XML 文件,因此您可以使用 XPath 作为 MSBUILD 中的自定义任务。在项目文件中,您将找到引用项目的“”标签。您需要将它们更改为“”标签。使用项目中标签的现有示例来查看它的外观

抱歉,我没有这方面的示例代码——这样做会有点困难,因为需要考虑很多事情考虑,最终可能不可行。

If you leave the project references in, MSBUILD will copy all the project references as DLLs into the target website's bin directory, even though you've installed these DLLs into the GAC, which I assume is why you want to change this at the release level--so that space can be saved.

I also assume that you are intending to do this at the Release Branch only, and not at the development branch of your source control. Because if you are doing this at all branches of source control, then doing by hand is actually the best and fastest way of doing this for a one-time change.

To do this in MSBUILD, you will need to create a custom task that can modify the project file. The project file is an XML file, so you could use XPath as your custom task in MSBUILD. In the project file, you will find tags for "" to your referenced projects. You will need to change those to "" tags instead. Use existing examples of the tag in your project to see how it should look

Sorry I don't have sample code for this--doing it this way will be a bit of an undertaking, as there will be a number of things to take into consideration, and it might end up not being feasible.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文