OpenLiveWriter/build.ps1

110 lines
3.0 KiB
PowerShell

# Cause powershell to fail on errors rather than keep going
$ErrorActionPreference = "Stop";
@"
=======================================================
Checking solution exists
=======================================================
"@
$solutionFile = "$PSSCRIPTROOT\src\managed\writer.sln"
if (-Not (Test-Path "$solutionFile" -PathType Leaf))
{
"Unable to find solution file at $solutionFile"
exit 100
}
"Solution found at '$solutionFile'"
@"
=======================================================
Fetching MSBuild location
=======================================================
"@
# Install module to allow us to find MSBuild
# See https://github.com/Microsoft/vssetup.powershell
Install-Module VSSetup -Scope CurrentUser
$visualStudioLocation = (Get-VSSetupInstance `
| Select-VSSetupInstance -Version '[16.0,17.0)' -Latest).InstallationPath
$msBuildExe = $visualStudioLocation + "\MSBuild\Current\Bin\msbuild.exe"
IF (-Not (Test-Path -LiteralPath "$msBuildExe" -PathType Leaf))
{
"MSBuild not found at '$msBuildExe'"
"In order to build OpenLiveWriter either Visual Studio 2019 (any edition) or Build "
"Tools for Visual Studio 2019 must be installed."
"These can be downloaded from https://visualstudio.microsoft.com/downloads/"
exit 101
}
"MSBuild.exe found at: '$msBuildExe'"
@"
=======================================================
Ensureing nuget.exe exists
=======================================================
"@
$nugetPath = "$env:LocalAppData\NuGet"
$nugetExe = "$nugetPath\NuGet.exe"
if (-Not (Test-Path -LiteralPath "$nugetExe" -PathType Leaf))
{
if (-Not (Test-Path -LiteralPath "$nugetPath" -PathType Container))
{
"Creating Directory '$nugetPath'"
New-Item "$nugetPath" -Type Directory
}
"Downloading nuget.exe"
Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/latest/nuget.exe' -OutFile "$nugetExe"
}
"Nuget.exe found at: '$nugetExe'"
@"
=======================================================
Ensure nuget packages exist
=======================================================
"@
$packageFolder = "$PSSCRIPTROOT\src\managed\packages"
if (Test-Path -LiteralPath $packageFolder)
{
"Packages found at '$packageFolder'"
}
else
{
"Running nuget restore"
& $nugetExe restore $solutionFile
}
@"
=======================================================
Check build type
=======================================================
"@
if (-Not (Test-Path env:OLW_CONFIG))
{
"Environment variable OWL_CONFIG not set, setting to 'Debug'"
$env:OLW_CONFIG = 'Debug'
}
"Using build '$env:OLW_CONFIG'"
@"
=======================================================
Starting build
=======================================================
"@
Get-Date
New-Item -ItemType Directory -Force -Path ReleasesUap
$buildCommand = "`"$msBuildExe`" $solutionFile /nologo /maxcpucount /verbosity:minimal /p:Configuration=$env:OLW_CONFIG /p:AppxPackageDir=ReleasesUap /p:UapAppxPackageBuildMode=StoreUpload /p:AppxBundlePlatforms=x86 /p:AppxBundle=Always $ARGS"
"Running build command '$buildCommand'"
Invoke-Expression "& $buildCommand"