<p>I would like the version property of my application to be incremented for each build but I'm not sure on how to enable this functionality in Visual Studio (2005/2008). I have tried to specify the AssemblyVersion as 1.0.* but it doesn't get me exactly what I want. </p>

<p>I'm also using a settings file and in earlier attempts when the assembly version changed my settings got reset to the default since the application looked for the settings file in another directory. </p>

<p>I would like to be able to display a version number in the form of 1.1.38 so when a user finds a problem I can log the version they are using as well as tell them to upgrade if they have an old release.</p>

<p>A short explanation of how the versioning works would also be appreciated. When does the build and revision number get incremented?</p>

[{'answer_id': 655, 'author': 'Michael Stum', 'author_id': 91, 'author_profile': 'https://Stackoverflow.com/users/91', 'pm_score': 8, 'selected': True, 'text': '<p>With the "Built in" stuff, you can\'t, as using 1.0.* or 1.0.0.* will replace the revision and build numbers with a coded date/timestamp, which is usually also a good way. </p>\n\n<p>For more info, see the <a href="http://msdn2.microsoft.com/en-us/library/c405shex(vs.80).aspx" rel="noreferrer">Assembly Linker</a> Documentation in the /v tag.</p>\n\n<p>As for automatically incrementing numbers, use the AssemblyInfo Task:</p>\n\n<p><a href="http://code.msdn.microsoft.com/AssemblyInfoTaskvers" rel="noreferrer">AssemblyInfo Task</a></p>\n\n<p>This can be configured to automatically increment the build number.</p>\n\n<p>There are 2 Gotchas:</p>\n\n<ol>\n<li>Each of the 4 numbers in the Version string is limited to 65535. This is a Windows Limitation and unlikely to get fixed.\n\n<ul>\n<li><a href="http://blogs.msdn.com/msbuild/archive/2007/01/03/why-are-build-numbers-limited-to-65535.aspx" rel="noreferrer">Why are build numbers limited to 65535?</a></li>\n</ul></li>\n<li>Using with with Subversion requires a small change:\n\n<ul>\n<li><a href="http://www.andrewconnell.com/blog/archive/2006/08/29/4078.aspx" rel="noreferrer">Using MSBuild to generate assembly version info at build time (including SubVersion fix)</a></li>\n</ul></li>\n</ol>\n\n<p>Retrieving the Version number is then quite easy:</p>\n\n<pre><code>Version v = Assembly.GetExecutingAssembly().GetName().Version;\nstring About = string.Format(CultureInfo.InvariantCulture, @"YourApp Version {0}.{1}.{2} (r{3})", v.Major, v.Minor, v.Build, v.Revision);\n</code></pre>\n\n<hr>\n\n<p>And, to clarify: In .net or at least in C#, the build is actually the THIRD number, not the fourth one as some people (for example Delphi Developers who are used to Major.Minor.Release.Build) might expect.</p>\n\n<p>In .net, it\'s Major.Minor.Build.Revision.</p>\n'}, {'answer_id': 787, 'author': 'engtech', 'author_id': 175, 'author_profile': 'https://Stackoverflow.com/users/175', 'pm_score': 3, 'selected': False, 'text': '<p>What source control system are you using? </p>\n\n<p>Almost all of them have some form of $ Id $ tag that gets expanded when the file is checked in.</p>\n\n<p>I usually use some form of hackery to display this as the version number.</p>\n\n<p>The other alternative is use to use the date as the build number: 080803-1448</p>\n'}, {'answer_id': 1550, 'author': 'caryden', 'author_id': 313, 'author_profile': 'https://Stackoverflow.com/users/313', 'pm_score': 1, 'selected': False, 'text': '<p>Some time ago I wrote a quick and dirty exe that would update the version #\'s in an assemblyinfo.{cs/vb} - I also have used rxfind.exe (a simple and powerful regex-based search replace tool) to do the update from a command line as part of the build process.  A couple of other helpfule hints:</p>\n\n<ol>\n<li>separate the assemblyinfo into product parts (company name, version, etc.) and assembly specific parts (assembly name etc.).  See <a href="http://blog.darrenstokes.com/2007/12/17/ease-versioning-multiple-assemblies-by-splitting-up-assemblyinfo/" rel="nofollow noreferrer">here</a></li>\n<li>Also - i use subversion, so I found it helpful to set the build number to subversion revision number thereby making it really easy to always get back to the codebase that generated the assembly (e.g. 1.4.100.1502 was built from revision 1502).</li>\n</ol>\n'}, {'answer_id': 155067, 'author': 'Solracnapod', 'author_id': 8900, 'author_profile': 'https://Stackoverflow.com/users/8900', 'pm_score': 4, 'selected': False, 'text': '<p>VS.NET defaults the Assembly version to 1.0.* and uses the following logic when auto-incrementing: it sets the build part to the number of days since January 1st, 2000, and sets the revision part to the number of seconds since midnight, local time, divided by two. See this <a href="http://msdn.microsoft.com/en-us/library/system.reflection.assemblyversionattribute.assemblyversionattribute.aspx" rel="noreferrer">MSDN article</a>.</p>\n\n<p>Assembly version is located in an assemblyinfo.vb or assemblyinfo.cs file. From the file: </p>\n\n<pre class="lang-vb prettyprint-override"><code>\' Version information for an assembly consists of the following four values:\n\'\n\'      Major Version\n\'      Minor Version \n\'      Build Number\n\'      Revision\n\'\n\' You can specify all the values or you can default the Build and Revision Numbers \n\' by using the \'*\' as shown below:\n\' &lt;Assembly: AssemblyVersion("1.0.*")&gt; \n\n&lt;Assembly: AssemblyVersion("1.0.0.0")&gt; \n&lt;Assembly: AssemblyFileVersion("1.0.0.0")&gt; \n</code></pre>\n'}, {'answer_id': 2352703, 'author': 'user283258', 'author_id': 283258, 'author_profile': 'https://Stackoverflow.com/users/283258', 'pm_score': 0, 'selected': False, 'text': '<p>If you want an auto incrementing number that updates each time a compilation is done, you can use <a href="http://testdox.wordpress.com/versionupdater/" rel="nofollow noreferrer">VersionUpdater</a> from a pre-build event. Your pre-build event can check the build configuration if you prefer so that the version number will only increment for a Release build (for example).</p>\n'}, {'answer_id': 15211000, 'author': 'user8128167', 'author_id': 351154, 'author_profile': 'https://Stackoverflow.com/users/351154', 'pm_score': 4, 'selected': False, 'text': '<p>I have found that it works well to simply display the date of the last build using the following wherever a product version is needed:</p>\n\n<pre><code>System.IO.File.GetLastWriteTime(System.Reflection.Assembly.GetExecutingAssembly().Location).ToString("yyyy.MM.dd.HH.mm.ss")\n</code></pre>\n\n<p>Rather than attempting to get the version from something like the following:</p>\n\n<pre><code>System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();\nobject[] attributes = assembly.GetCustomAttributes(typeof(System.Reflection.AssemblyFileVersionAttribute), false);\nobject attribute = null;\n\nif (attributes.Length &gt; 0)\n{\n    attribute = attributes[0] as System.Reflection.AssemblyFileVersionAttribute;\n}\n</code></pre>\n'}, {'answer_id': 43894925, 'author': 'Nacho Coll', 'author_id': 7975865, 'author_profile': 'https://Stackoverflow.com/users/7975865', 'pm_score': 3, 'selected': False, 'text': '<p><em>[Visual Studio 2017, <strong>.csproj</strong> properties]</em></p>\n\n<p>To automatically update your PackageVersion/Version/AssemblyVersion property (or any other property), first, create a new <code>Microsoft.Build.Utilities.Task</code> class that will get your current build number and send back the updated number (I recommend to create a separate project just for that class).</p>\n\n<p>I manually update the major.minor numbers, but let MSBuild to automatically update the build number (1.1.<strong>1</strong>, 1.1.<strong>2</strong>, 1.1.<strong>3</strong>, etc. :)</p>\n\n<pre><code>using Microsoft.Build.Framework;\nusing System;\nusing System.Collections.Generic;\nusing System.Text;\n\npublic class RefreshVersion : Microsoft.Build.Utilities.Task\n{\n    [Output]\n    public string NewVersionString { get; set; }\n    public string CurrentVersionString { get; set; } \n\n    public override bool Execute()\n    {       \n        Version currentVersion = new Version(CurrentVersionString ?? "1.0.0");\n\n        DateTime d = DateTime.Now;\n        NewVersionString = new Version(currentVersion.Major, \n            currentVersion.Minor, currentVersion.Build+1).ToString();\n        return true;\n    }\n\n}\n</code></pre>\n\n<p>Then call your recently created Task on MSBuild process adding the next code on your .csproj file:</p>\n\n<pre><code>&lt;Project Sdk="Microsoft.NET.Sdk"&gt;    \n...\n&lt;UsingTask TaskName="RefreshVersion" AssemblyFile="$(MSBuildThisFileFullPath)\\..\\..\\&lt;dll path&gt;\\BuildTasks.dll" /&gt;\n&lt;Target Name="RefreshVersionBuildTask" BeforeTargets="Pack" Condition="\'$(Configuration)|$(Platform)\'==\'Release|AnyCPU\'"&gt;\n   &lt;RefreshVersion CurrentVersionString="$(PackageVersion)"&gt;\n          &lt;Output TaskParameter="NewVersionString" PropertyName="NewVersionString" /&gt;             \n   &lt;/RefreshVersion&gt;\n   &lt;Message Text="Updating package version number to $(NewVersionString)..." Importance="high" /&gt;\n   &lt;XmlPoke XmlInputPath="$(MSBuildProjectDirectory)\\mustache.website.sdk.dotNET.csproj" Query="/Project/PropertyGroup/PackageVersion" Value="$(NewVersionString)" /&gt;\n&lt;/Target&gt;\n...\n&lt;PropertyGroup&gt;\n ..\n &lt;PackageVersion&gt;1.1.4&lt;/PackageVersion&gt;\n ..\n</code></pre>\n\n<p>When picking Visual Studio Pack project option (just change to <code>BeforeTargets="Build"</code> for executing the task before Build) the RefreshVersion code will be triggered to calculate the new version number, and <code>XmlPoke</code> task will update your .csproj property accordingly (yes, it will modify the file).</p>\n\n<p>When working with NuGet libraries, I also send the package to NuGet repository by just adding the next build task to the previous example.</p>\n\n<pre><code>&lt;Message Text="Uploading package to NuGet..." Importance="high" /&gt;\n&lt;Exec WorkingDirectory="$(MSBuildProjectDirectory)\\bin\\release" Command="c:\\nuget\\nuget push *.nupkg -Source https://www.nuget.org/api/v2/package" IgnoreExitCode="true" /&gt;\n</code></pre>\n\n<p><code>c:\\nuget\\nuget</code> is where I have the NuGet client (remember to save your NuGet API key by calling <code>nuget SetApiKey &lt;my-api-key&gt;</code> or to include the key on the NuGet push call).</p>\n\n<p>Just in case it helps someone ^_^.</p>\n'}, {'answer_id': 67165881, 'author': 'GrahamS', 'author_id': 79591, 'author_profile': 'https://Stackoverflow.com/users/79591', 'pm_score': 0, 'selected': False, 'text': '<p>Here is a handcranked alternative option: This is a quick-and-dirty PowerShell snippet I wrote that gets called from a pre-build step on our Jenkins build system.</p>\n<p>It sets the last digit of the <code>AssemblyVersion</code> and <code>AssemblyFileVersion</code> to the value of the <code>BUILD_NUMBER</code> environment variable which is automatically set by the build system.</p>\n<pre class="lang-powershell prettyprint-override"><code>if (Test-Path env:BUILD_NUMBER) {\n    Write-Host &quot;Updating AssemblyVersion to $env:BUILD_NUMBER&quot;\n\n    # Get the AssemblyInfo.cs\n    $assemblyInfo = Get-Content -Path .\\MyShinyApplication\\Properties\\AssemblyInfo.cs\n\n    # Replace last digit of AssemblyVersion\n    $assemblyInfo = $assemblyInfo -replace \n        &quot;^\\[assembly: AssemblyVersion\\(`&quot;([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.[0-9]+`&quot;\\)]&quot;, \n        (\'[assembly: AssemblyVersion(&quot;$1.$2.$3.\' + $env:BUILD_NUMBER + \'&quot;)]\')\n    Write-Host  ($assemblyInfo -match \'^\\[assembly: AssemblyVersion\')\n        \n    # Replace last digit of AssemblyFileVersion\n    $assemblyInfo = $assemblyInfo -replace \n        &quot;^\\[assembly: AssemblyFileVersion\\(`&quot;([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.[0-9]+`&quot;\\)]&quot;, \n        (\'[assembly: AssemblyFileVersion(&quot;$1.$2.$3.\' + $env:BUILD_NUMBER + \'&quot;)]\')\n    Write-Host  ($assemblyInfo -match \'^\\[assembly: AssemblyFileVersion\')\n        \n    $assemblyInfo | Set-Content -Path .\\MyShinyApplication\\Properties\\AssemblyInfo.cs -Encoding UTF8\n} else {\n    Write-Warning &quot;BUILD_NUMBER is not set.&quot;\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/650', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/143/']