Search code examples
c#builddevenvversion-numbering

How to specify Publish Version in Devenv?


I am totally new in building Visual Studio Project through a script, so feel free to correct me if you feel that my understanding about the process is incorrect.

I have a visual studio solution which consists of a Wpf.exe project and few class library projects.

Currently I am successfully building .sln file using script below

"%VS_IDE_DIR%devenv.com" "...Solution-File-Path.sln" /rebuild Release /useenv

Currently the Wpf.exe file gets the File Version and Product Version 1.0.0.0 which is the default specified in Publish -> Publish Version Property of Wpf project. enter image description here

I want to somehow set the File Version and Product Version through my script. How can I achieve that?

I have an environment variable which contains the Product Version and File Version, Basically I want to set value of Product Version and File Version equal to my environment variable.


Solution

  • There's a simple way to do this. In the WPF project, open the Properties node and double-click AssemblyInfo.cs. The [assembly: AssemblyFileVersion] attribute sets the File Version number. Add this to set the Product Version number:

    [assembly: AssemblyInformationalVersion("1.2.3.4")]
    

    Doing this from the command line is only technically possible. You'd have to create the native file version resource and compile it with rc.exe. And use Project + Properties, Resource file option to tell the compiler to use the custom .res file produced by rc.exe. You'd need scripting to get the version resource updated. Given how easy it is to do this by editing AssemblyInfo.cs, I'd recommend you don't bother.