I'm looking to define one location in my project to store a version string. The behavior that I'm looking for is that I store the version in a text file (version.txt) in my project directory, and then my pre-build event updates the content in Properties/AssemblyInfo.cs.
[assembly: AssemblyVersion("<Version>")] [assembly: AssemblyFileVersion("<Version>")] Yes, I know that there are only two fields and that they are right next to each other, but I'd still like to know if this is possible.
I wrote and tested this Powershell script that carries out this functionality.
$assemblyInfoPath = "Properties\AssemblyInfo.cs" $versionText = (Get-Content -Path version.txt -ReadCount 0) $assemblyInfoText = (Get-Content -Path $assemblyInfoPath -ReadCount 0) $assemblyInfoText = $assemblyInfoText -replace '\[assembly: AssemblyVersion\("((\d)+|(\.))*"\)\]', "[assembly: AssemblyVersion(`"$versionText`")]" $assemblyInfoText -replace '\[assembly: AssemblyFileVersion\("((\d)+|(\.))*"\)\]', "[assembly: AssemblyFileVersion(`"$versionText`")]" | Set-Content -Path $assemblyInfoPath What's failing (I think) is the invocation during the pre-build step:
Pre-build event command line:
powershell $(ProjectDir)set_assembly_version.ps1 I haven't tried running this with msbuild, only through Visual Studio 2017. Is this even possible since AssemblyInfo.cs is a project file?
