Skip to content

Instantly share code, notes, and snippets.

@jeremylindsayni jeremylindsayni/build.cake
Last active Nov 28, 2017

Embed
What would you like to do?
Cake file to manage creation and deployment of a UWP application.
#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
You can’t perform that action at this time.