Can I automatically increment the file build version when using Visual Studio?

后端 未结 25 2945
-上瘾入骨i
-上瘾入骨i 2020-11-22 14:32

I was just wondering how I could automatically increment the build (and version?) of my files using Visual Studio (2005).

If I look up the properties of sa

25条回答
  •  暖寄归人
    2020-11-22 15:08

    In Visual Studio 2019

    It was not enough for me adding

    [assembly: AssemblyVersion("1.0.*")]
    

    When building it throws me this error

    The specified version string does not conform to the required format

    Solution

    The format was finally accepted after I set Deterministic to False in project.csproj

    false
    

    Edit:

    For some reason setting Deterministic to False messed up my config file loading it and saving it on different locations.

    Workaround:

    I setup a post-build event to increment the revision number:

    Post-Build Event batch script

    This calls a powershell script named autoincrement_version.ps1 passing as argument the path of AssemblyInfo.cs

    if $(ConfigurationName) == Release (
    PowerShell -ExecutionPolicy RemoteSigned $(ProjectDir)autoincrement_version.ps1 '$(ProjectDir)My Project\AssemblyInfo.cs'
    )
    

    Poweshell script

    It autoincrements the revision number using Regex

    param( [string]$file );
      $regex_revision = '(?<=Version\("(?:\d+\.)+)(\d+)(?="\))'
      $found = (Get-Content $file) | Select-String -Pattern $regex_revision
      $revision = $found.matches[0].value
      $new_revision = [int]$revision + 1
      (Get-Content $file) -replace $regex_revision, $new_revision | Set-Content $file -Encoding UTF8
    

提交回复
热议问题