Auto Increment Version in visual studio

Solution1 : auto-increase but random number


http://www.razorleaf.com/2010/01/auto-incrementing-visual-studio/

  1. Open the file AssemblyInfo.cs
  2. Change [assembly: AssemblyVersion("1.0.0.0")] to [assembly: AssemblyVersion("1.0.*")]
  3. Remove [assembly: AssemblyFileVersion("1.0.0.0")]
  4. Rebuild the project and verify that the version is incremented properly by viewing the properties of the newly compiled assembly

However,

 

You can specify all the values or you can accept the default build number, revision number, or both by using an asterisk (*). For example, [assembly:AssemblyVersion("2.3.25.1")] indicates 2 as the major version, 3 as the minor version, 25 as the build number, and 1 as the revision number. A version number such as [assembly:AssemblyVersion("1.2.*")] specifies 1 as the major version, 2 as the minor version, and accepts the default build and revision numbers. A version number such as [assembly:AssemblyVersion("1.2.15.*")] specifies 1 as the major version, 2 as the minor version, 15 as the build number, and accepts the default revision number. The default build number increments daily. The default revision number is random . (--http://msdn.microsoft.com/en-us/library/system.reflection.assemblyversionattribute.aspx)

 

Solution2 : auto-increase and +1

h ttp://www.csharpfans.com/post/2007/10/Auto-Increment-Revision-Number-in-AssemblyInfocs.aspx

 


 


Compile and you will have a dll file. How to use the dll?

note: from envykok

you can create a library name : BuildTask

 

Put the dll under your project folder, project folder was including ".csproj"
Edit the ".csproj" file in notepad or any text editor

 

First , Find Tag "<Project" and between <Project> and <PropertyGroup>, insert a line

<UsingTask TaskName="BuildTask.AutoIncrementBuildNumber" AssemblyFile="BuildTask.dll" />

S econd , Find Tag "<Import Project="$(MSBuildBinPath)/Microsoft.CSharp.targets" />", and add the following after the tag:

<Target Name="BeforeBuild">
  <AutoIncrementBuildNumber
    AssemblyFileLocation="$(MSBuildProjectDirectory)/Properties/AssemblyInfo.cs"
    ExecuteFileLocation="$(TargetPath)"
  />
</Target>
<Target Name="AfterBuild">
</Target>

Change the AssemlyFileLocation if your AssemblyInfo.cs is not located in The Properties Folder.

 

Sample *.csproj updated:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build"
    xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <UsingTask TaskName="BuildTasks.IncrementBuildNumber"
     AssemblyFile="BuildTask.dll" />

  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">
               Debug</Configuration>
   
    ...

<Import Project="$(MSBuildBinPath)/Microsoft.VisualBasic.targets" />
<Target Name="BeforeBuild">
  <IncrementBuildNumber AssemblyFileLocation=
           "$(MSBuildProjectDirectory)/AssemblyInfo.vb">
  </IncrementBuildNumber>
  </Target>
  <Target Name="AfterBuild">
  </Target>

</Project>

 

 

OK, Now all is ready, Compile and enjoy the auto increment.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值