Solution1 : auto-increase but random number
http://www.razorleaf.com/2010/01/auto-incrementing-visual-studio/
- Open the file AssemblyInfo.cs
- Change [assembly: AssemblyVersion("1.0.0.0")] to [assembly: AssemblyVersion("1.0.*")]
- Remove [assembly: AssemblyFileVersion("1.0.0.0")]
- 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.