确定程序集版本中一后生成事件? [英] Determine Assembly Version during a Post Build Event?
问题描述
比方说,我想创建一个静态文本文件附带的每个版本。我想要的文件与发布的版本号进行更新(如的AssemblyInfo.cs
指定的),但我不希望有手动执行此操作。
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?
推荐答案
如果您preFER脚本这些方法还可能为你工作:
If you prefer scripting these methods might also work for you:
如果您正在使用生成后事件,您可以使用Filever.exe工具抢出来的已建成集的:
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%
获取filever.exe从这里: http://support.microsoft.com/kb/913111
如果您使用的是pre-build事件,你可以把它拿出来AssemblyInfo.cs文件如下:
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%
本使用UNIX命令行工具sed中,你可以从很多地方下载,比如在这里: http://unxutils.sourceforge.net / - IIRC,一个好的工作
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屋!