MSBuild TFS 内部版本号
我已经使用 SVN 一段时间了。最近在一个项目中我正在使用TFS。对于构建,我喜欢在项目输出上附加/更新构建版本号。我在主页上执行此操作,以便它在应用程序上清晰可见。由于应用程序可以在多台计算机上运行,因此可以方便地了解正在运行的版本。
我在 SVN 世界中实现了这一点:
<!-- Import of the MSBuildCommunityTask targets -->
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
<!-- to AssemblyInfo to include svn revision number -->
<Target Name="BeforeBuild">
<SvnVersion LocalPath="$(MSBuildProjectDirectory)" ToolPath="$(ProgramFiles)\CollabNet Subversion Client">
<Output TaskParameter="Revision" PropertyName="Revision" />
</SvnVersion>
<Time>
<Output TaskParameter="Year" PropertyName="Year" />
<Output TaskParameter="Month" PropertyName="Month" />
<Output TaskParameter="Day" PropertyName="Day" />
</Time>
<FileUpdate Files="MasterPage.master" Regex="svn revision: (\d+)\.(\d+)\.(\d+)\.(\d+)" ReplacementText="svn revision: $(Year).$(Month).$(Day).$(Revision)" />
</Target>
正如您在上面看到的,“BeforeBuild”任务使用 YYYY.MM.DD.SVNVERSION 标记更新 masterPage.master 文件。
如何使用 TFS 作为源代码控制来实现此目的。如何获取 TFS 内部版本号?
I have been using SVN for a little while now. recently on a project I am using TFS. With the builds I like to append/update the build version number on the project output. I do this on the masterpage so that it is clearly visible on the application. Since the application could be running on multiple machines, it is handy information on which verison are running.
I achive this in SVN world as:
<!-- Import of the MSBuildCommunityTask targets -->
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
<!-- to AssemblyInfo to include svn revision number -->
<Target Name="BeforeBuild">
<SvnVersion LocalPath="$(MSBuildProjectDirectory)" ToolPath="$(ProgramFiles)\CollabNet Subversion Client">
<Output TaskParameter="Revision" PropertyName="Revision" />
</SvnVersion>
<Time>
<Output TaskParameter="Year" PropertyName="Year" />
<Output TaskParameter="Month" PropertyName="Month" />
<Output TaskParameter="Day" PropertyName="Day" />
</Time>
<FileUpdate Files="MasterPage.master" Regex="svn revision: (\d+)\.(\d+)\.(\d+)\.(\d+)" ReplacementText="svn revision: $(Year).$(Month).$(Day).$(Revision)" />
</Target>
As you can see above the "BeforeBuild" task updates the masterPage.master file with the YYYY.MM.DD.SVNVERSION stamp.
How can I achive this with TFS as the source control. How do I get the TFS build number?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您指的是 Team Build,则 $(BuildNumber) 属性包含当前的内部版本号。
请参阅 http://blogs .msdn.com/aaronhallberg/archive/2008/02/12/team-build-2008-property-reference.aspx 了解可用属性的完整参考。
如果您只是运行 MSBuild,我不相信它会生成/应用总体内部版本号(每个项目在其 AssemblyInfo.cs [默认情况下] 文件中都会有一个单独的、可能自动递增的版本号)。您可以在运行时使用 System.Reflection.Assembly 类动态获取特定程序集的版本号。
更新
从 TFS 2010 开始,“BuildNumber”变量不再由 TFS 自动传递到 MSBuild 进程。 TFS 2010 现在使用 Windows Workflow 作为其内部构建引擎,因此如果您需要内部版本号,则必须修改构建定义以包含它,如 这篇 MSDN 文章。
Assuming you mean Team Build, the $(BuildNumber) property contains the current build number.
See http://blogs.msdn.com/aaronhallberg/archive/2008/02/12/team-build-2008-property-reference.aspx for a full reference of available properties.
If you're just running MSBuild, I don't believe it generates/applies an overall build number (each project will have an individual, possibly auto-incremented, version number in its AssemblyInfo.cs [by default] file). You can dynamically get this version number for a specific assembly using the System.Reflection.Assembly class at runtime.
Update
As of TFS 2010, the 'BuildNumber' variable is no longer automatically passed to the MSBuild process by TFS. TFS 2010 now uses Windows Workflow as its internal build engine, so if you want the build number, you'll have to modify your build definition to include it, as mentioned in this MSDN article.