在后期制作活动中确定装配版本? [英] Determine Assembly Version during a Post Build Event?

查看:103
本文介绍了在后期制作活动中确定装配版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我想创建每个版本附带的静态文本文件。我想要使​​用版本号更新该文件(在 AssemblyInfo.cs 中指定),但我不想手动执行此操作。 / p>

我希望可以使用一个后期制作事件,并将版本号提供给这样的批处理文件:

 调用foo.bat $(AssemblyVersion)

但是找不到任何合适的变量或宏使用。



有没有办法实现这一点,我错过了?

解决方案

如果您喜欢脚本,这些方法也可能适用于您:



如果您使用的是后建立事件,可以使用filever.exe工具来抓取已经构建的程序集:

  $ / $$$($ file = B / A / D bin\debug\myapp.exe')do(
set VERSION = %% F

echo版本是%VERSION%

从这里获取filever.exe: http://support.microsoft.com/kb/913111



如果您正在使用预构建事件,可以采取它出现在AssemblyInfo.cs文件中,如下所示:

  set ASMINFO = Properties\AssemblyInfo.cs 
FINDSTR / C:[assembly:AssemblyVersion(%ASMINFO%| sed.exes / \ [assembly:AssemblyVersion(\/ SET CURRENT_VERSION = / g; s / )\] // g; s / \.\ * // g> SetCurrVer.cmd
CALL SetCurrVer.cmd
DEL SetCurrVer.cmd
echo当前版本是%CURRENT_VERSION%

这使用unix命令行工具sed,您可以从许多地方下载,例如如下所示: http://unxutils.sourceforge.net/ - 一个可以正常工作的iirc。


Let's say I wanted to create a static text file which ships with each release. I want the file to be updated with the version number of the release (as specified in AssemblyInfo.cs), but I don't want to have to do this manually.

I was hoping I could use a post-build event and feed the version number to a batch file like this:

call foo.bat $(AssemblyVersion)

However I can't find any suitable variable or macro to use.

Is there any way to achieve this that I've missed?

解决方案

If you prefer scripting these methods might also work for you:

If you are using the post-build event, you can use the filever.exe tool to grab it out of the already built assembly:

for /F "tokens=4" %%F in ('filever.exe /B /A /D bin\debug\myapp.exe') do (
  set VERSION=%%F
)
echo The version is %VERSION%

Get filever.exe from here: http://support.microsoft.com/kb/913111

If you are using the pre-build event, you can take it out of the AssemblyInfo.cs file as follows:

set ASMINFO=Properties\AssemblyInfo.cs
FINDSTR /C:"[assembly: AssemblyVersion(" %ASMINFO% | sed.exe "s/\[assembly: AssemblyVersion(\"/SET CURRENT_VERSION=/g;s/\")\]//g;s/\.\*//g" >SetCurrVer.cmd
CALL SetCurrVer.cmd
DEL SetCurrVer.cmd
echo Current version is %CURRENT_VERSION%

This uses the unix command line tool sed, which you can download from many places, such as here: http://unxutils.sourceforge.net/ - iirc that one works ok.

这篇关于在后期制作活动中确定装配版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆