AssemblyInfo.cs 颠覆和 TortoiseSVN

发布于 2024-08-09 17:39:13 字数 135 浏览 3 评论 0原文

我正在使用 TortoiseSVN 和 Visual Studio 2008。 有没有办法在每个构建中使用 svn 的版本更新我的项目的 assemblyinfo.cs ?

例如,1.0.0.[svn 的版本] -> 1.0.0.12

I'm using TortoiseSVN and Visual Studio 2008.
Is there any way to update my project's assemblyinfo.cs with svn's version in every build?

For example, 1.0.0.[svn's version] -> 1.0.0.12

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

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

发布评论

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

评论(7

幻梦 2024-08-16 17:39:13

您可以使用 TortoiseSVN 附带的 SubWCRev 工具(也可单独购买) 。

从命令行运行它或使用 COM-Object 它提供。

SubWCRev 命令行工具用以下信息替换文件内的关键字你的 svn 工作副本。文档中显示了示例

You could use the SubWCRev tool which comes with TortoiseSVN (also available separately).

Either run it from a command line or use the COM-Object it offers.

The SubWCRev command line tool replaces keywords inside a file with information from your svn working copy. An example is shown in the docs.

拥醉 2024-08-16 17:39:13

我在我的构建脚本中执行此操作:

<SvnInfo LocalPath=".">
  <Output TaskParameter="Revision" PropertyName="BuildRev" />
</SvnInfo>
<FileUpdate Files="protobuf-net\Properties\AssemblyInfo.cs"
  Regex='(\[\s*assembly:\s*AssemblyVersion\(\s*"[^\.]+\.[^\.]+)\.([^\.]+)(\.)([^\.]+)("\)\s*\])'
  ReplacementText='$1.$2.$(BuildRev)$5' />

使用社区构建任务。这实质上将正则表达式应用于 AssemblyInfo.cs,用 svn 修订版替换当前修订版。

I do this in my build script:

<SvnInfo LocalPath=".">
  <Output TaskParameter="Revision" PropertyName="BuildRev" />
</SvnInfo>
<FileUpdate Files="protobuf-net\Properties\AssemblyInfo.cs"
  Regex='(\[\s*assembly:\s*AssemblyVersion\(\s*"[^\.]+\.[^\.]+)\.([^\.]+)(\.)([^\.]+)("\)\s*\])'
  ReplacementText='$1.$2.$(BuildRev)$5' />

using the community build tasks. This essentially applies a regex to the AssemblyInfo.cs, replacing the current revision with the svn revision.

月亮是我掰弯的 2024-08-16 17:39:13

You could use the $Rev$ svn keyword but that will give you the last revision of the file, I think you want to get the HEAD revision number.

Give a look to this question:

胡大本事 2024-08-16 17:39:13

您对 Visual Studio 插件 执行此操作有何看法?

How do you feel about a Visual Studio addin doing it?

我为君王 2024-08-16 17:39:13

是的,您可以添加一个预构建事件,该事件调用一个脚本,该脚本

  • 调用 svn info 来提取当前修订号(如果您之前进行过更新,则可以直接包含关键字 $Revision $ 在文件中,还检查 这篇文章);
  • 相应地修改您的 Properties\AssemblyInfo.cs 文件。

我通常做的是在构建项目时转换 AssemblyInfo.cs 模板。不幸的是,该脚本必须使 $Revision$ 的形式适应该文件的语法。

有趣的属性是(模板字符串位于“$”之间):

[assembly: AssemblyVersion("$v$.$build$.$Last Changed Rev$")]
[assembly: AssemblyFileVersion("$v$.$build$.$Last Changed Rev$")]

编辑:svn info 是标准 SVN 客户端的一部分,而不是另一篇文章中指出的 TortoiseSVN。不过安装很容易。然而,TortoiseSVN 附带了 SubWCRev.exe,它可以通过关键字替换来转换文件,因此如果您更新本地副本,它就会起作用。

Yes, you can add a pre-build event that calls a script which

  • calls svn info to extract the current revision number (if you do an update before, you can directly include the keyword $Revision$ in a file, check also this post);
  • modifes your Properties\AssemblyInfo.cs file accordingly.

What I usually do is transform a AssemblyInfo.cs template when the project is built. The script is necessary to adapt the form of $Revision$ to the syntax of this file, unfortunately.

The interesting properties are (where the template strings are between '$'):

[assembly: AssemblyVersion("$v$.$build$.$Last Changed Rev$")]
[assembly: AssemblyFileVersion("$v$.$build$.$Last Changed Rev$")]

Edit: svn info is part of the standard SVN client, not TortoiseSVN as pointed out in another post. Easy to install though. However, TortoiseSVN comes with SubWCRev.exe which transforms a file with keyword substitution, so it would do the trick if you update your local copy.

浪菊怪哟 2024-08-16 17:39:13

在 Visual Studio 2008 中,您可以定义可启动脚本或小程序的预构建事件。在此脚本或程序中,您可以使用svnversion命令获取存储库修订版,然后解析您的AssemblyInfo.cs并将版本号修改为您想要的版本号。

我不确定 TortoiseSVN 是否附带 svnversion,但它确实附带提供的 Windows SVN 版本通过 CollabNet

In Visual Studio 2008, you can define a pre-build event that can launch a script or small program. Within this script or program, you can use the svnversion command to get the repository revision, then parse your AssemblyInfo.cs and modify the version number to what you desire.

I'm not sure if TortoiseSVN comes with svnversion, but it does come with the Windows SVN build provided by CollabNet

叹梦 2024-08-16 17:39:13

我为 SVN 版本插件创建了一个。 com/" rel="nofollow noreferrer">构建版本增量项目(在 popester 的答案中命名)。此 SVN 插件将从您的工作副本中提取最新的更改修订号,并允许您在版本号中使用它,这应该完全完成您想要做的事情。

I created an SVN version plug-in for the Build Version Increment project (which is named in popester's answer). This SVN plug-in will pull the latest change revision number from your working copy and allow you to use that in your version number, which should accomplish exactly what you're trying to do.

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