使构建过程独立于 GAC

发布于 2024-07-13 23:34:29 字数 633 浏览 5 评论 0原文

我们如何才能使 .NET 项目的构建过程 (Dev Studio 2005) 完全独立于运行该项目的特定计算机上的 GAC 上安装的内容。

这是我们试图解决的问题:根据 GAC 中安装的程序集,我们的构建过程会在输出目录中生成不同的 .NET 程序集,然后我们用它来构建 .MSI

大概这是因为 dev studio假设由于它安装在 GAC 中,因此不应将其作为我们产品的一部分安装。

我们希望禁用此行为,以便我们的项目直接或间接引用的所有 .NET 程序集都被复制到项目的输出目录中(.NET 2.0 运行时标准程序集除外)。

对于直接程序集引用,我知道设置“Copy Local=True”可以实现此目的。

但是,这不适用于间接程序集引用。

即我们的一个项目引用了一个名为“A.dll”的程序集,该程序集依赖于另一个名为“B.dll”的程序集,该程序集与“A.dll”位于同一目录中。 在 GAC 中未安装“B.dll”的计算机上,A.dll 和 B.dll 都会在 Dev studio 构建过程中复制到输出目录。 这就是我们想要的。

但在将 B.dll 安装到 GAC 中的计算机上,即使 A.dll 的“Copy Local = True”,B.dll 也不会被复制到输出目录中。

How can we make our build process (Dev Studio 2005) for a .NET project completely independent of what is installed on the GAC on the particular machine that it is running on.

Here's the problem we're trying to solve: Depending on what assemblies happen to have been installed into the GAC, our build process generates different .NET assemblies in the output directory that we then use to build a .MSI

Presumably this is because dev studio is assuming that, because it's installed in the GAC, it should not be installed as part of our product.

We want to disable this behaviour so that all .NET assemblies that are referenced, directly or indirectly by our project, get copied into the output directory of the project (excepting the .NET 2.0 runtime standard assemblies).

For direct assembly references, I am aware that setting "Copy Local=True" makes this work.

However, this isn't working for indirect assembly references.

i.e. One of our projects references an assembly called "A.dll", which depends on another assembly called "B.dll" which is in the same directory as "A.dll". On machines in which "B.dll" is not installed in the GAC, both A.dll and B.dll are copied to the output directory in the Dev studio build process. This is what we want.

But on machines on which B.dll is installed into the GAC, even if "Copy Local = True" for A.dll, B.dll does not get copied into the output directory.

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

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

发布评论

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

评论(3

秋千易 2024-07-20 23:34:29

就像 Marc 建议的那样,唯一的方法是添加依赖引用并设置 CopyLocal=True。

但我开始同意 Danny 的答案 - 不要使用 Dev Studio 进行部署,因为您无法充分控制构建过程。

为什么? Dev Studio 存在一些“默认”逻辑,其中如果它计算了属性的值,那么它不会将其保存到 .CSPROJ 文件,从而将另一台计算机上的 Dev Studio 实例留给“默认”任务“把财产变成别的东西!

唯一无错误的方法是直接显式编辑 .csproj xml 文件,并确保您已将 True 添加到 Reference 元素:

<ItemGroup>
    <Reference Include="ConfigManagerClient, Version=1.0.0.0, Culture=neutral, PublicKeyToken=20fc1ffb797ec904, processorArchitecture=MSIL">
    <SpecificVersion>False</SpecificVersion>
    <HintPath>..\..\thirdparty\CM\ConfigManagerClient.dll</HintPath>
    <!-- If DevStudio inferred this to be true, then it won't explicitly save it.
         When the project is loaded on another machine on which the assembly is
         installed in the GAC,
         Dev Studio on _that_ machine will infer that CopyLocal should be False!!
     -->
    <Private>True</Private>
</Reference>

这种行为似乎使得几乎不可能知道您的 .CSPROJ 文件的内容在不同的机器上运行时会执行此操作。

从长远来看,最好不要将构建和打包过程委托给 Dev Studio,而只使用 Nant 和显式命令行。

Like Marc suggested, the only way to do it was to add the dependent references and setting CopyLocal=True.

But I'm coming to agree with Danny's answer - don't use Dev Studio for your deployment, because you can't get sufficient control over the build process.

Why? There's some "defaulting" logic going on with the Dev Studio in which if it has computed the value of a property, then it won't save it to the .CSPROJ file, leaving a Dev Studio instance on another machine the task of "defaulting" the property to something else!

The only error-free way to do it is to explicitly edit the .csproj xml file directly and ensure that you've added True to the Reference element:

<ItemGroup>
    <Reference Include="ConfigManagerClient, Version=1.0.0.0, Culture=neutral, PublicKeyToken=20fc1ffb797ec904, processorArchitecture=MSIL">
    <SpecificVersion>False</SpecificVersion>
    <HintPath>..\..\thirdparty\CM\ConfigManagerClient.dll</HintPath>
    <!-- If DevStudio inferred this to be true, then it won't explicitly save it.
         When the project is loaded on another machine on which the assembly is
         installed in the GAC,
         Dev Studio on _that_ machine will infer that CopyLocal should be False!!
     -->
    <Private>True</Private>
</Reference>

This sort of behaviour appears to make it next to impossible to know what your .CSPROJ file is going to do when run on a different machine.

In the long run you're much better off not entrusting your build and packaging process to Dev Studio and instead just using, say, Nant and explicit command lines.

醉殇 2024-07-20 23:34:29

我认为您可能不应该依赖 Visual Studio 构建过程自动为您执行此操作,特别是当结果可能因构建机器而异时。

在这种情况下(无论您是使用 Visual Studio 构建还是使用自动构建脚本,这都适用),我要做的就是让一些构建后脚本(为了简单起见,我通常使用批处理文件)将项目需要的所有程序集复制到构建后立即保存到适当的目录(我通常将不属于我的项目的任何程序集保留在源代码管理中的目录中,以便将其全部放在一个位置)。 然后,当您构建安装程序时,一切都准确无误。

I think you probably should not be relying on the Visual Studio build process to do this for you automatically, particularly when the results can vary depending on the building machine.

What I would do in this case (this applies whether you are building with Visual Studio or using an automated build script) is to have some post-build script (I usually use batch files for simplicity) copy all of the assemblies your project needs into the appropriate directory immediately after the build (I normally keep any assemblies that are not part of my project in a directory in my source control so that it's all in one place). Then when you build your installer, everything is exactly where it needs to be.

这个俗人 2024-07-20 23:34:29

最简单的答案是明确的:添加对 B.dll 的引用并按照您想要的方式设置它。

The simplest answer is to be explicit: add a reference to B.dll and set it how you want it.

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