Last active
November 28, 2017 05:56
-
-
Save jeremylindsayni/46b461f5cb5d64fe4aaa9bcd5a00c1c4 to your computer and use it in GitHub Desktop.
Cake file to manage creation and deployment of a UWP application.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#tool nuget:?package=NUnit.ConsoleRunner&version=3.4.0 | |
////////////////////////////////////////////////////////////////////// | |
// SETUP CUSTOM TOOL | |
////////////////////////////////////////////////////////////////////// | |
Setup(context => { | |
context.Tools.RegisterFile(@"C:\Program Files (x86)\Windows Kits\10\bin\x86\WinAppDeployCmd.exe"); | |
}); | |
var raspberryPiIpAddress = @"192.168.1.125"; | |
var solutionFile = @"../App3.sln"; | |
var applicationProjectFile = @"../App3/App3.csproj"; | |
var appxBundlePath = string.Empty; | |
////////////////////////////////////////////////////////////////////// | |
// ARGUMENTS | |
////////////////////////////////////////////////////////////////////// | |
var target = Argument("target", "Default"); | |
var configuration = Argument("configuration", "Release"); | |
////////////////////////////////////////////////////////////////////// | |
// PREPARATION | |
////////////////////////////////////////////////////////////////////// | |
// Define directories. | |
var buildDir = Directory("./App3/bin"); | |
var objectDir = Directory("./App3/obj"); | |
var appDir = Directory("./App3/App3"); | |
var appPackagesDir = Directory("./App3/AppPackages"); | |
var bundleArtifactsDir = Directory("./App3/BundleArtifacts"); | |
////////////////////////////////////////////////////////////////////// | |
// TASKS | |
////////////////////////////////////////////////////////////////////// | |
Task("Clean") | |
.Does(() => | |
{ | |
CleanDirectory(buildDir); | |
CleanDirectory(objectDir); | |
CleanDirectory(appDir); | |
CleanDirectory(appPackagesDir); | |
CleanDirectory(bundleArtifactsDir); | |
}); | |
Task("Restore-NuGet-Packages") | |
.IsDependentOn("Clean") | |
.Does(() => | |
{ | |
NuGetRestore(solutionFile); | |
}); | |
Task("Build") | |
.IsDependentOn("Restore-NuGet-Packages") | |
.Does(() => | |
{ | |
if(IsRunningOnWindows()) | |
{ | |
// Use MSBuild | |
MSBuild(solutionFile, settings => | |
settings.SetConfiguration(configuration)); | |
} | |
else | |
{ | |
// Use XBuild | |
XBuild(solutionFile, settings => | |
settings.SetConfiguration(configuration)); | |
} | |
}); | |
Task("Run-Unit-Tests") | |
.IsDependentOn("Build") | |
.Does(() => | |
{ | |
MSTest("../**/bin/" + configuration + "/UnitTestProject2.dll"); | |
}); | |
Task("Build-Appxbundle") | |
.IsDependentOn("Run-Unit-Tests") | |
.Does(() => | |
{ | |
var applicationProjectFile = @"../App3/App3.csproj"; | |
MSBuild(applicationProjectFile, new MSBuildSettings | |
{ | |
Verbosity = Verbosity.Minimal | |
} | |
.WithProperty("AppxBundle", "Always") | |
.WithProperty("AppxBundlePlatforms", "x86|arm") | |
); | |
appxBundlePath = FindFirstAppxBundlePath(); | |
}); | |
Task("Deploy-Appxbundle") | |
.IsDependentOn("Build-Appxbundle") | |
.Does(() => | |
{ | |
FilePath deployTool = Context.Tools.Resolve("WinAppDeployCmd.exe"); | |
Information(appxBundlePath); | |
var processSuccessCode = StartProcess(deployTool, new ProcessSettings { | |
Arguments = new ProcessArgumentBuilder() | |
.Append(@"install") | |
.Append(@"-file") | |
.Append(appxBundlePath) | |
.Append(@"-ip") | |
.Append(raspberryPiIpAddress) | |
}); | |
if (processSuccessCode != 0) | |
{ | |
throw new Exception("Deploy-Appxbundle: UWP application was not successfully deployed"); | |
} | |
}); | |
////////////////////////////////////////////////////////////////////// | |
// TASK TARGETS | |
////////////////////////////////////////////////////////////////////// | |
Task("Default") | |
.IsDependentOn("Deploy-Appxbundle"); | |
////////////////////////////////////////////////////////////////////// | |
// EXECUTION | |
////////////////////////////////////////////////////////////////////// | |
RunTarget(target); | |
private string FindFirstAppxBundlePath() | |
{ | |
var files = System.IO.Directory.GetFiles(@"..\", @"*.appxbundle", SearchOption.AllDirectories); | |
if (files.Count() > 0) | |
{ | |
return files[0]; | |
} | |
else | |
{ | |
throw new Exception("FindFirstAppxBundlePath: No appxbundle found"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment