我如何使用的MSBuild只有当一个程序集已更改为更新版本的信息? [英] How can I use MSBuild to update version information only when an assembly has changed?

查看:172
本文介绍了我如何使用的MSBuild只有当一个程序集已更改为更新版本的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要安装多个Web安装项目(使用VS2005和ASP.Net/C#)到同一个虚拟文件夹的要求。该项目共享一些程序集引用(文件系统都是结构使用相同的'bin文件夹),更改的部署,因为MS安装程序只覆盖组件如果当前安装的版本比在旧的问题这些程序集微星。

I have a requirement to install multiple web setup projects (using VS2005 and ASP.Net/C#) into the same virtual folder. The projects share some assembly references (the file systems are all structured to use the same 'bin' folder), making deployment of changes to those assemblies problematic since the MS installer will only overwrite assemblies if the currently installed version is older than the one in the MSI.

我并不是暗示悲观的安装方案是错误的 - 只是它会在我一直在考虑与工作环境的问题。由于有共同的组件相当数量和谁可能会改变一个共同的组件,但忘记更新它的版本号开发商显著号码,试图管理手动版本,最终将导致大规模的混乱在安装时。

I'm not suggesting that the pessimistic installation scheme is wrong - only that it creates a problem in the environment I've been given to work with. Since there are a sizable number of common assemblies and a significant number of developers who might change a common assembly but forget to update its version number, trying to manage versioning manually will eventually lead to massive confusion at install time.

在这个问题的另一面,它也是重要的是不要自发更新版本号和替换的所有的共同点的每个的安装,装配,因为这可以(至少暂时),其中实际变化作了模糊的情况。

On the flip side of this issue, it's also important not to spontaneously update version numbers and replace all common assemblies with every install, since that could (temporarily at least) obscure cases where actual changes were made.

这是说,我要找的是更新程序集的版本信息(preferably使用的MSBuild)只有在案件的手段,其中组件组成(code模块,资源等)已/已实际改变

That said, what I'm looking for is a means to update assembly version information (preferably using MSBuild) only in cases where the assembly constituents (code modules, resources etc) has/have actually changed.

我已经发现了一些参考的至少部分相关的<一个href=\"http://$c$c.msdn.microsoft.com/AssemblyInfoTaskvers/Release/ProjectReleases.aspx?ReleaseId=232\">here (MSDN上的AssemblyInfo任务)和<一个href=\"http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/94054d89-ba19-4658-9e4e-ce7d8ff4dea3/\">here (类似于我需要什么,但两年多岁,没有一个明确的解决方案)。

I've found a few references that are at least partially pertinent here (AssemblyInfo task on MSDN) and here (looks similar to what I need, but more than two years old and without a clear solution).

我的团队也使用TFS版本控制,因此自动化解决方案可能应包括由该AssebmlyInfo可/在构建过程中被检出一种手段。

My team also uses TFS version control, so an automated solution should probably include a means by which the AssebmlyInfo can be checked out/in during the build.

任何帮助将是非常美联社preciated。

Any help would be much appreciated.

先谢谢了。

推荐答案

我不能回答你所有的问题,因为我没有经验,TFS。

I cannot answer all your questions, as I don't have experience with TFS.

不过,我可以推荐一个更好的方法来使用更新的AssemblyInfo.cs文件不是使用的AssemblyInfo任务。这项任务似乎只是从头开始重新创建一个标准的程序集信息文件,并失去您可能已添加任何自定义的部分。

But I can recommend a better approach to use for updating your AssemblyInfo.cs files than using the AssemblyInfo task. That task appears to just recreate a standard AssemblyInfo file from scratch, and loses any custom portions you may have added.

出于这个原因,我建议你看看FileUpdate任务,从社区的MSBuild任务的项目。它可以查找特定内容的文件,并替换它,就像这样:

For that reason, I suggest you look into the FileUpdate task, from the MSBuild Community Tasks project. It can look for specific content in a file and replace it, like this:

<FileUpdate 
Files="$(WebDir)\Properties\AssemblyInfo.cs"
Regex="(\d+)\.(\d+)\.(\d+)\.(\d+)"
ReplacementText="$(Major).$(ServicePack).$(Build).$(Revision)" 
Condition="'$(Configuration)' == 'Release'"
/>

有几种方法可以控制内部版本号的递增。因为我只想递增版本号如果构建是完全成功的,我使用的是2步法:

There are several ways you can control the incrementing of the build number. Because I only want the build number to increment if the build is completely successful, I use a 2-step method:


  • 读取文本文件数(文件中的唯一事情是数),并添加1而不改变文件;

  • 作为构建过程的最后一步,如果一切成功,保存递增数回的文本文件。

有任务,例如ReadLinesFromFile,这可以帮助你,但我发现它最容易写一个小的自定义任务:

There are tasks such as ReadLinesFromFile, that can help you with this, but I found it easiest to write a small custom task:

using System;
using System.IO;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace CredibleCustomBuildTasks
{
    public class IncrementTask : Task
    {
    	[Required]
    	public bool SaveChange { get; set; }

    	[Required]
    	public string IncrementFileName { get; set; }

    	[Output]
    	public int Increment { get; set; }

    	public override bool Execute()
    	{
    		if (File.Exists(IncrementFileName))
    		{
    			string lines = File.ReadAllText(IncrementFileName);
    			int result;
    			if(Int32.TryParse(lines, out result))
    			{
    				Increment = result + 1;
    			}
    			else
    			{
    				Log.LogError("Unable to parse integer in '{0}' (contents of {1})");
    				return false;
    			}
    		}
    		else
    		{
    			Increment = 1;
    		}

    		if (SaveChange)
    		{
    			File.Delete(IncrementFileName);
    			File.WriteAllText(IncrementFileName, Increment.ToString());
    		}
    		return true;
    	}
    }
}

我用这个FileUpdateTask之前获得下一个版本号:

I use this before the FileUpdateTask to get the next build number:

<IncrementTask 
IncrementFileName="$(BuildNumberFile)" 
SaveChange="false">
  <Output TaskParameter="Increment" PropertyName="Build" />
</IncrementTask>

和我的最后一步在构建(通知其他前):

and as my final step (before notifying others) in the build:

<IncrementTask 
IncrementFileName="$(BuildNumberFile)" 
SaveChange="true"
Condition="'$(Configuration)' == 'Release'" />

如何更新,只有当源$ C ​​$ C,改变了版本号你的另一个问题是高度依赖于您的构建过程中如何与您的源代码控制交互。通常情况下,在源文件更改检查应启动持续集成构建。那就是用更新有关版本号之一。

Your other question of how to update the version number only when source code has changed is highly dependent on your how your build process interacts with your source control. Normally, checking in source file changes should initiate a Continuous Integration build. That is the one to use to update the relevant version number.

这篇关于我如何使用的MSBuild只有当一个程序集已更改为更新版本的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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