Continuous Integration Script for Windows 8 Store Apps (PowerShell)

Nowadays it’s common to build Applications automatically. I made an application for one of the leading telecommunication companies in Germany and there it is necessary to make ci so I had to make a script which can build and deliver always an testable App.


$fileVersion = "C:\Build\Version.txt"
$AppPath = "C:\Projects 45\MySolution\"
$AppSolution = "MySolution.sln"
$msbuild = "C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe"
$buildfolder = "C:\StoreBuild"
$logger = "build.log"
$buildconfiguration = "Release"
$buildPath = "C:\Build\"

#Version Auslesen und erhöhen
$versionInfo = Get-content $fileVersion
$firstPoint = $versionInfo.IndexOf(".")
$versionMajorText = $versionInfo.Substring(0, $firstPoint)
$versionInfo = $versionInfo.Remove(0, $firstPoint+1)

$firstPoint = $versionInfo.IndexOf(".")
$versionMinorText = $versionInfo.Substring(0, $firstPoint)
$versionInfo = $versionInfo.Remove(0, $firstPoint+1)

$firstPoint = $versionInfo.IndexOf(".")
$versionBuildText = $versionInfo.Substring(0, $firstPoint)
$versionInfo = $versionInfo.Remove(0, $firstPoint+1)

$firstPoint = $versionInfo.IndexOf(".")
$versionRevisionText = $versionInfo

[int]$versionMajor = [System.Convert]::ToInt32($versionMajorText)
[int]$versionMinor = [System.Convert]::ToInt32($versionMinorText)
[int]$versionBuild = [System.Convert]::ToInt32($versionBuildText)
[int]$versionRevision = [System.Convert]::ToInt32($versionRevisionText)

$versionRevision++

[String]$versionText = [String]$versionMajor +"."+ [String]$versionMinor +"." + [String]$versionBuild + "." + [String]$versionRevision

Set-Content $fileVersion $versionText

$outputFolder = $buildPath + "Output\" + $versionText +"\"

#Konfigurationsdatei auslesen um die Manifestdateien zu ermitteln
$AppPathSolution = $AppPath + $AppSolution
$Solution = [String] (Get-Content -Path $AppPathSolution)
$Solution = $Solution.Substring(0, $Solution.IndexOf("EndProject Global")+11)
$Solution = $Solution.Substring($Solution.IndexOf("Project"))

echo "Update Version in Manifest files"
do
{
$endProjectIndex = $Solution.IndexOf("EndProject")
$ProjectItem = $Solution.Substring(0, $endProjectIndex +11)
$firstSeperator = $ProjectItem.IndexOf(",")
$lastSeperator = $ProjectItem.LastIndexOf(",")
$ProjectFile = $projectItem.Substring($firstSeperator + 2, $lastSeperator - $firstSeperator -2)
$Solution = $Solution.Remove(0, $endProjectIndex+11)
If ($ProjectFile.Contains("csproj"))
{
$ValidProject = $ProjectFile
$SearchPath = $AppPath + $ProjectFile.Substring(1, $ProjectFile.LastIndexOf("\"))
Foreach ($file in Get-Childitem $SearchPath)
{

If ($file.Name -eq "Package.appxmanifest")
{
echo $file.FullName
#Version in den Mainfestdateien Updaten
$Manifest = [xml] (Get-Content -Path $file.FullName)
$Manifest.Package.Identity.Version = $versionText
$Manifest.Save($file.FullName)
}
}
}
}
while($Solution.Length -gt 0)

echo "Files will be stored to: $buildfolder"

# if the build folder exists, delete it
if ([System.IO.Directory]::Exists($buildfolder))
{
[System.IO.Directory]::Delete($buildfolder, 1)
}

[System.IO.Directory]::CreateDirectory($buildfolder)

if ([System.IO.Directory]::Exists($buildfolder))
{
Copy-Item $AppPath* $buildfolder -recurse
}
else
{
[System.IO.Directory]::CreateDirectory($buildfolder)
Copy-Item $AppPath* $buildfolder -recurse

}

$options = ""
$options = $options + "/property:Configuration=" + $buildconfiguration
$options = $options + " /fl /flp:logfile=" + $buildfolder +"\" + $logger + " /noconsolelogger"
# create the build command and invoke it
# note that if you want to debug, remove the "/noconsolelogger"
# from the $options string
$build = $msbuild + " """ + $buildfolder +"\"+ $AppSolution + """ " + $options + " /t:Build"

echo "Build Process starting: $build"

Invoke-Expression $build

# move all the files that were built to the output folder
echo "Move Items from: $buildfolder"

$releaseFolderBrand1 = $buildfolder + "\Brand1\AppPackages\*"
$releaseFolderBrand2 = $buildfolder + "\Brand2\AppPackages\*"
$releaseFolderBrand1QA = $buildfolder + "\Brand1QA\AppPackages\*"
$releaseFolderBrand2QA = $buildfolder + "\Brand2QA\AppPackages\*"
$releaseFolderBrand1PRE = $buildfolder + "\Brand1PRE\AppPackages\*"
$releaseFolderBrand2PRE = $buildfolder + "\Brand2PRE\AppPackages\*"

$outputFolderBrand1 = $outputfolder + "Brand1\"
$outputFolderBrand2 = $outputfolder + "Brand2\"
$outputFolderBrand1QA = $outputfolder + "Brand1QA\"
$outputFolderBrand2QA = $outputfolder + "Brand2QA\"
$outputFolderBrand1PRE = $outputfolder + "Brand1PRE\"
$outputFolderBrand2PRE = $outputfolder + "Brand2PRE\"

[System.IO.Directory]::CreateDirectory($outputFolderBrand1)
[System.IO.Directory]::CreateDirectory($outputFolderBrand2)
[System.IO.Directory]::CreateDirectory($outputFolderBrand1QA)
[System.IO.Directory]::CreateDirectory($outputFolderBrand2QA)
[System.IO.Directory]::CreateDirectory($outputFolderBrand1PRE)
[System.IO.Directory]::CreateDirectory($outputFolderBrand2PRE)

Move-Item -Path $releaseFolderBrand1 -Destination $outputFolderBrand1 -Force
Move-Item -Path $releaseFolderBrand2 -Destination $outputFolderBrand2 -Force
Move-Item -Path $releaseFolderBrand1QA -Destination $outputFolderBrand1QA -Force
Move-Item -Path $releaseFolderBrand2QA -Destination $outputFolderBrand2QA -Force
Move-Item -Path $releaseFolderBrand1PRE -Destination $outputFolderBrand1PRE -Force
Move-Item -Path $releaseFolderBrand2PRE -Destination $outputFolderBrand2PRE -Force

Next is now that all builded packages must pass the AppCertificationKit.

Advertisements

Windows 8 Fundamentals Part 1

Based on my work on one of the largest web email Provider in Germany i build some lessons to teach the Windows Team the fundamentals for building Windows 8 Store Apps.

Part1 of this Lessons showes the differences between Windows 8 Store App Projects and common Windows 8 Desktop Applications based on .NET Framework 4.5