Search code examples
powershellmsbuildpublishpowershell-3.0tfs-2015

Changing publish version using Powershell


I have written a Powershell script to build a solution(.sln) file. My script is working properly without any issues even sanity test passes but the problem is it is not changing the publish version. The solution is needed to be published. It is publishing successfully using

/t:publish

argument. But not able to change the publish version Any idea how I can change publish version using PowerShell. To build the sln file I am using

msbuild foo.sln /p:Configuration=$configuration /t:Publish

Is there any msbuild argument to change the Publish version or any other way.


Solution

  • MSBUILD will not regenerate the existed same files in the output folder, if you do not change any code, the MSBUILD will not rebuild and create the new file, so the version number of the file will not be changed.

    First, in your .csproj file, fine the element <ApplicationVersion>*.*.*.*</ApplicationVersion>, and remove it. Then you could build and publish the application, the app.application verion will be specified by the /property:ApplicationVersion argument.

    Then use this command as below:

    msbuild xxx.csproj /target:clean;publish /property:ApplicationVersion=x.x.x.x

    You can also use the way answerd by Daniel Nolan in this question:Specify publish version with MSBuild command line as assembly version of project as stijn mentioned.

    Another way is writting a powershell script to modify the csproj file with new version number.