Tfs2010 内部版本号和程序集文件版本& MSBuild 目标
我读了约翰·罗宾斯的文章 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我已经弄清楚了这一点,但是有两个人提出了我的问题,所以我将在这里回答:
您可以通过表达另一个目标对目标的依赖来确保目标运行。 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 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!