4 minute read

I developed for fun a couple a WP7 apps and I needed to automate (just a little bit:-) the release process, mainly because:

  • The application version must be entered in various point and should be keep in sync
  • I’d like to store all released version in a specific directory

The easiest way I found to do this is via PowerShell. I wrote a super simple script that:

  • store into a variable the version you want to assign to the build
  • replace the version in all location needed for the project.
    • In my project, that is of just 1 dll, I had to keep in sync the following files:
      • Properties\AssemblyInfo.cs
      • Properties\WMAppManifest.xml
      • Model\ApplicationInfo.cs (this is a custom c# class…)
  • Rebuild the solution as “release”
  • Copy the .xap file into Releases Folder, renaming it adding the version to the file

The directory structure I used (in my project – LED) is the following

  • LED (solution folder)
    • Releases
      • NicolD.Phone.App.LED-1.0.0.1.xap
      • NicolD.Phone.App.LED-1.0.0.2.xap
    • NicolD.Phone.App.LED (project folder)
      • bin
    • LED.sln
    • Build.ps1 (the file below)

I think that this approach can be used/extended in many other scenarios similar to this one.

Good luckSmile

$version = "1.02.00.00"
$SolutionPath = "D:\MyProjects2010\WP7\PRO\LED\"
$Solution = $SolutionPath + "LED.sln"
$SolutionBin = $SolutionPath + "NicolD.Phone.App.LED\Bin\"
$LogFile = $SolutionBin + "Build.log"
$VStudio2010= "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe"
$releases = $SolutionPath + "Releases\"
$build        = $SolutionBin + "Release\NicolD.Phone.App.LED.xap"
$buildArchive = $releases +    "NicolD.Phone.App.LED-" + $version + ".xap"
function replace 
{
    $o = $args[0]
    $a = $args[1]
    $b = $args[2]
    
    (Get-Content $o) | 
    Foreach-Object {$_ -replace $a, $b} | 
    Set-Content $o
}
$AssemblyInfo = $SolutionPath + "NicolD.Phone.App.LED\Properties\AssemblyInfo.cs"
$filter = 'AssemblyVersion\("\d+.\d+.\d+.\d+"\)'
$newstring = 'AssemblyVersion("' + $version + '")'
replace $AssemblyInfo $filter $newstring
$filter = 'AssemblyFileVersion\("\d+.\d+.\d+.\d+"\)'
$newstring = 'AssemblyFileVersion("' + $version + '")'
replace $AssemblyInfo $filter $newstring
$manifest = $SolutionPath + "NicolD.Phone.App.LED\Properties\WMAppManifest.xml"
$filter = 'Version="\d+.\d+.\d+.\d+"'
$newstring = 'Version="' + $version + '"'
replace $manifest $filter $newstring
$appinfo = $SolutionPath + "NicolD.Phone.App.LED\Model\ApplicationInfo.cs"
$filter = 'ApplicationVersion = "\d+.\d+.\d+.\d+"'
$newstring = 'ApplicationVersion = "' + $version + '"'
replace $appinfo $filter $newstring
& $VStudio2010 $Solution /clean | Out-Null
& $VStudio2010 $Solution /rebuild release /out $logfile | Out-Null
copy $build $buildarchive