在当前版本中不使用通过Pre-Build Event命令修改的源文件 [英] Source files modified by a Pre-Build Event command are not used in the current build

查看:159
本文介绍了在当前版本中不使用通过Pre-Build Event命令修改的源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行VS2008

这一切都试图找到一种方法来更新/修改每个版本的AssemblyVersion属性.

我知道这已经一遍又一遍地被问到,我似乎无法找到该问题的明确答案. (至少在MSDN或MSFT相关站点中/上)

我发现几个实用程序散布在网络上,我最喜欢的是在MSBuild团队博客上找到的Neil Enns的AssembyInfoTask.站点,因为它已与MSBuild集成.不幸的是,我在使用该版本时遇到了问题(稍后会详细介绍).

我最终得到了一个独立的exe,可以像预建活动.它确实满足我的要求,将Build字段设置为yyDDD形式的数字(一年的最后两位数字,然后代表一年中的一天的3位数字),并且如果内部版本号为,则将修订字段设置为零更改或只是增加(如果没有).它会很好地更新AssemblyInfo.cs中的AssemblyVersion属性.问题在于,当我查看生成的构建目标的版本信息时,它总是对AssemblyInfo.cs文件中的内容进行一次修改.

嗯?

所以我想知道这是否仅仅是因为我正在修改属性,如果您修改任何源文件,也许是真的.

然后我创建了一个简单的WinForm应用,该应用显示了一个MessageBox,并使用另一个名称为MessageBox保存了源文件的第二个副本,并带有不同的标题字符串,并添加了一个Pre-Build事件,该事件仅复制用包含修改后的Caption字符串的文件覆盖Project中指定的文件,并且发生相同的情况.第一次构建和运行时,将显示UNmodified Caption字符串.重建与运行,我得到了修改后的版本.

问题1)如果在预构建事件中修改了输出目标文件,为什么输出目标文件总是比源文件中的更新晚一个?为什么不使用写在硬盘驱动器上的源文件?

如果是这种情况,是否存在用于修改AssemblyVersion属性的标准/推荐方法或实用程序;(例如Neil Enns的AssembyInfoTask吗?)

我遇到的AssembyInfoTask问题是,因为版本字段号必须小于65535,所以您会遇到年份大于2006的问题(就像所有在2007年1月1日之后返回MSBuild Blog的评论).如果按原样运行任务,则会得到预期的" rror.)

在他的博客页面中
(在这里:您可以使用所需的任何格式.在Visual Studio中,我们现在使用的是01MMdd.任务意外失败. System.FormatException:输入字符串的格式不正确.


问题2)同样,有没有一种标准/推荐的方式或工具来实现此目的(例如尼尔·恩恩斯的AssembyInfoTask?)

提前感谢,
保罗


I'm running VS2008

This all started trying to find a way to update/modify the AssemblyVersion attribute for each build.

I know this has been asked over and over, I just can't seem to find a definitive answer to the question. (at least in/on MSDN or MSFT related site)

I found several utilities scatter over the web, with my preferred one being Neil Enns' AssembyInfoTask found on the MSBuild Team Blog site, for the fact that it integrates with MSBuild. Unfortunately I had problems using this one (more on this later) .

I ended up with a stand alone exe that runs as a Pre-Build Event. It does exactly what I want, setting the Build field to a number in the form yyDDD (last two digits of the year, then 3 digit representing the day of the year), and either setting the revision field to zero if the build number has changed or just incrementing if it hasn't. It updates AssemblyVersion attribute in AssemblyInfo.cs fine. Problems is that I when look at the version info of the resulting build target, it's the always one modification behind of what's in the of the AssemblyInfo.cs file.

Huh?

So I got to wondering if it wasn't just because I was modifying an attribute, maybe it's true if you modify any source file.

I then created a simple WinForm app that display a MessageBox, saved a second copy of the source file with different Caption string for the MessageBox under a different name, added a Pre-Build event that simply copies/overwrites the file specified in the Project with the file containing the modified Caption string and the same thing happens. First time I build and run, the UNmodified Caption string is displayed; rebuild & run and I get the modified one.

Question 1) Why is the output target file always one update behind what's in a source file if the file is modified in a pre-build event? Why isn't it using the source file that's written on the hard drive?

If this is the case, is there a standard/recommended way or util for doing modifying the AssemblyVersion attribute (like Neil Enns' AssembyInfoTask?)

The problem I had with AssembyInfoTask is that because version field numbers need to be less than 65535, you run into problems with years greater than 2006 (just like all the comments on the MSBuild Blog back after Jan 1,2007 indicate). If you run the task as is, you get the expected "Error emitting 'System.Reflection.AssemblyVersionAttribute' attribute -- 'The version specified '1.0.100131.1' is invalid "error.)

In his blog page 
 (here: http://blogs.msdn.com/msbuild/archive/2007/01/03/fixing-invalid-version-number-problems-with-the-assemblyinfotask.aspx )
he says that "You can use any format you want. Within Visual Studio we're now using 01MMdd."

I try that and it causes an "The "AssemblyInfo" task failed unexpectedly. System.FormatException: Input string was not in a correct format."
error.


Question 2) So again, is there a standard/recommended way or util for doing this (like Neil Enns' AssembyInfoTask?)

Thanks in advance,
Paul


推荐答案

有一种相当简单的方法.我认为没有确切答案的原因是,您可以采取多种方法,具体取决于您要尝试做的事情.我有一个一直在使用的特定实现,它会打开一个包含我想要的版本号的XML文档,递增和更新XML文档(必须将其签出并返回TFS),然后覆盖AssemblyInfo中的版本.每个项目的cs文件.解释这将是很漫长的.我们计划在将来某个时候将其作为TechEd演讲或博客文章来提供.

不过,Neils举例说明了您可能会做的一个很好的例子.对于上面的问题1,版本号只能是这么多位数.我相信它是short或unsigned short,因此最大值是32767或65534.(对不起,不记得是哪个,但是您可以查询一下)在上面的示例中,您将内部版本号设置为100131,太大,因此无效.这是版本号的限制,而不是Neil编写的Task.

请注意,您可以编写两个以上的版本.例如AssemblyVersion(),AssemblyFileVersion()等.这也使事情变得复杂,因为很多时候您想要两个独立的数字来更新此内容.

查克·英格兰
Visual Studio Platform
程序管理器-MSBuild
There is a fairly easy way to do this. I think the reason there is no definitive answer is that there are nunerous approaches that you can take, depending on exactly what you are trying to do. I have a specific implementation that I have been using which opens an XML document that contains the version numbers I want, increments and updates the XML document (which has to be checked out and back into TFS) and then overwrites the versions in the AssemblyInfo.cs file of each project. Explaining that here would be quite lengthy. There are plans to either provide this as a TechEd talk or as a blog post at some point in the future.

However, Neils example if a great example of what you might do. To your question 1 above, the version number can only be so many digits. I believe it is either a short or unsigned short, so the max value is 32767 or 65534. (Sorry, can't remember which, but you can look it up) In the example above, you have Build number set to 100131, which is too large, and hence invalid. This is a limitation of Version numbers, not of the Task Neil wrote.

Note that there are more than two versions you can write. For example AssemblyVersion(), AssemblyFileVersion(), and so on. This also complicates things, as many times you want two independent numbers for updating this.

Chuck England
Visual Studio Platform
Program Manager - MSBuild


这篇关于在当前版本中不使用通过Pre-Build Event命令修改的源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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