Tfs2010 内部版本号和程序集文件版本& MSBuild 目标

发布于 2024-09-25 15:37:35 字数 2026 浏览 4 评论 0原文

我读了约翰·罗宾斯的文章 TFS 2010 内部版本号和程序集文件版本:仅与 MSBuild 4.0 完全同步,我想知道整合这个的最佳方法。

本文的下载有两个文件,一个是 Targets 文件,一个是 Proj 文件。

目标文件有许多任务,用于根据 Tfs 构建号(与构建使用的构建号相同)刮出构建号,并将该数字写入某个位置(称为 BuildNumberFile)以供其他 proj 文件使用。

proj 文件非常简单。它只是导入上述目标文件,然后声明一个名为“All”的目标,同时还将 Project 元素上的 DefaultTargets 声明为 All。

    <Project ToolsVersion="4.0" DefaultTargets="All" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <PropertyGroup>
            <!-- The two required properties so the Wintellect.TFSBuildNumber tasks knows your major and minor values.-->
            <TFSMajorBuildNumber>3</TFSMajorBuildNumber>
            <TFSMinorBuildNumber>1</TFSMinorBuildNumber>
        </PropertyGroup>

        <Import Project="Wintellect.TFSBuildNumber.targets"/>

        <!-- Just ask for the version information files you need. These are here to show all the diffent ones in 
           Wintellect.TFSBuildNumber.Targets. You can change the names -->
        <Target Name="All"
              DependsOnTargets="WriteSharedCSharpAssemblyVersionFile;
                              WriteSharedVBAssemblyVersionFile;
                              WriteSharedCPPCLIAssemblyVersionFile;
                              WriteSharedCPPAssemblyVersionFile;
                              WriteSharedWiXAssemblyVersionFile;
                              WriteSharedTextAssemblyVersionFile;"/>
    </Project>

我对此有两个问题:

  • 我仍在学习 MSBuild。如果目标的名称没有在目标中的其他地方指定,那么目标是否会被执行?如何确保该目标运行?
  • csproj 文件是否应该为 BuildNumberFile 所在位置声明一个 Include 项,即使它在编译时才存在?
  • ItemGroups 和 Include 是否有 DependsOnTargets 或允许它们在构建之前确保文件存在的东西?
  • 使用此的 csproj 文件的全部内容是否应该包装在表示 BuildNumberFile 的 DependsOnTargets 的目标中?

谢谢!

I read John Robbins' article TFS 2010 Build Number and Assembly File Versions: Completely In Sync with Only MSBuild 4.0, and I'm wondering about the best way to go about integrating this.

The download for the article has two files, one is a targets file and one is a proj file.

The targets file has a number of tasks to scrape out a build number based on the Tfs build number (the same one used for the builds) and write that number out to some location (call it BuildNumberFile) for consumption by other proj files.

The proj file is very simple. It just imports the aforementioned targets file, and then declares a target with name "All" while also declaring DefaultTargets on the Project element to be All as well.

    <Project ToolsVersion="4.0" DefaultTargets="All" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <PropertyGroup>
            <!-- The two required properties so the Wintellect.TFSBuildNumber tasks knows your major and minor values.-->
            <TFSMajorBuildNumber>3</TFSMajorBuildNumber>
            <TFSMinorBuildNumber>1</TFSMinorBuildNumber>
        </PropertyGroup>

        <Import Project="Wintellect.TFSBuildNumber.targets"/>

        <!-- Just ask for the version information files you need. These are here to show all the diffent ones in 
           Wintellect.TFSBuildNumber.Targets. You can change the names -->
        <Target Name="All"
              DependsOnTargets="WriteSharedCSharpAssemblyVersionFile;
                              WriteSharedVBAssemblyVersionFile;
                              WriteSharedCPPCLIAssemblyVersionFile;
                              WriteSharedCPPAssemblyVersionFile;
                              WriteSharedWiXAssemblyVersionFile;
                              WriteSharedTextAssemblyVersionFile;"/>
    </Project>

I have two questions about this:

  • I'm still learning MSBuild. If the name of the target isn't specified elsewhere in the targets, is the target executed? How do I ensure that this target is run?
  • Are the csproj files supposed to declare an Include item for the location where BuildNumberFile is, even though it doesn't exist until compiletime?
  • Do ItemGroups and Include have a DependsOnTargets or something that allows them make sure the file exists before they build?
  • Are the entire contents of the csproj file using this supposed to be wrapped in a target that expresses DependsOnTargets for BuildNumberFile?

Thanks!

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

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

发布评论

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

评论(1

故事与诗 2024-10-02 15:37:35

我想我已经弄清楚了这一点,但是有两个人提出了我的问题,所以我将在这里回答:

  • 您可以通过表达另一个目标对目标的依赖来确保目标运行。 Microsoft.Common.targets 公开两个目标(BeforeBuild 和 AfterBuild),明确用于重写以实现可定制性。我发现最简单的方法是 其中 WriteSharedCSharpAssemblyVersionFile 是在原始帖子中的链接下载中声明的目标。另外,如果您是 MSBuild 新手,则必须在导入 Microsoft.CSharp.targets 之后声明此 BeforeBuild 目标,但默认的 csproj 模板会指导您执行此操作。

  • WriteSharedCSharpAssemblyVersionFile 目标确实应该将文件写入某个中心位置,因为在构建解决方案时,所有目标仅执行一次。所有项目都应该从该位置引用该文件,即使该文件不存在,因为在编译发生时(或更重要的是,在解析引用时),BeforeBuild 目标将已运行并且文件将就位。

    • 在我的结构中,这些版本控制文件位于分支根文件夹正下方的文件夹中。此外,由于正在生成的文件已生成,因此我将其构建到输出目录。从输出中引用内容似乎有点奇怪,但它保留了将所有构建产品放在一个位置的不变性,以便可以将输出目录吹走作为执行清理的一种方法。
  • 在 MSBuild 中,项目构成系统的输入(通常是文件),因此根据目标来考虑它们是很奇怪的。经过一番学习后,这个问题没有多大意义。无论如何,答案是否定的。

  • 该文件的全部内容确实不应该全部包含在一个目标中 - 所需要做的就是在 csproj 文件的开头导入 Wintellect.TFSBuildNumber.targets 文件,并在末尾声明 BeforeBuild 对 WriteSharedCSharpAssemblyVersionFile 的依赖关系.

希望这有帮助!

I think I've got this figured out, but two people promoted my question so I'll answer it here:

  • You can ensure that a target is run by expressing a dependency on it from another target. Microsoft.Common.targets exposes two targets--BeforeBuild and AfterBuild--expressly for the purpose of being overridden for customizability. I found the easiest way to do this was <Target Name="BeforeBuild" DependsOnTargets="WriteSharedCSharpAssemblyVersionFile" /> where WriteSharedCSharpAssemblyVersionFile is the target declared in the download from the link in the original post. Also, if you're new to MSBuild, this BeforeBuild target must be declared after the Microsoft.CSharp.targets is imported, but the default csproj template guides you in doing this.

  • The WriteSharedCSharpAssemblyVersionFile target should indeed write the file to some central location, since when building a solution, all targets are executed only once. All projects should reference the file from that location even if it doesn't exist, since by the time compilation happens (or more importantly, by the time references are resolved), the BeforeBuild target will have run and the file will be in place.

    • In my structure, I have these versioning files in a folder directly underneath the branch root folder. Furthermore, since the file being built is generated, I have it build to the output directory. It seems a little strange to be referencing things from the output, but it preserves the invariant of having all build products in one place so that the output directory can be blown away as a means of performing a clean.
  • In MSBuild items constitute inputs into the system (usually files) so it's weird to think of them depending on targets. After some learning this question doesn't make a lot of sense. In any case, the answer is no.

  • The entire contents of the file should indeed not be all in one target--all that is required is to import the Wintellect.TFSBuildNumber.targets file at the beginning of your csproj file, and declare BeforeBuild's dependency on WriteSharedCSharpAssemblyVersionFile at the end.

Hope this helps!

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