Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add local build scripts #253

Merged
merged 1 commit into from
Dec 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
:: options
@echo Off
cd %~dp0
setlocal

:: set tool versions
set NUGET_VERSION=4.3.0
set MSBUILD_VERSION=15
set CSI_VERSION=2.3.2

:: determine nuget cache dir
set NUGET_CACHE_DIR=%LocalAppData%\.nuget\v%NUGET_VERSION%
set NUGET_LOCAL_DIR=.nuget\v%NUGET_VERSION%

:: download nuget to cache dir
set NUGET_URL=https://dist.nuget.org/win-x86-commandline/v%NUGET_VERSION%/NuGet.exe
if not exist %NUGET_CACHE_DIR%\NuGet.exe (
if not exist %NUGET_CACHE_DIR% mkdir %NUGET_CACHE_DIR%
echo Downloading '%NUGET_URL%'' to '%NUGET_CACHE_DIR%\NuGet.exe'...
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest '%NUGET_URL%' -OutFile '%NUGET_CACHE_DIR%\NuGet.exe'"
)

:: copy nuget locally
if not exist %NUGET_LOCAL_DIR%\NuGet.exe (
if not exist %NUGET_LOCAL_DIR% mkdir %NUGET_LOCAL_DIR%
copy %NUGET_CACHE_DIR%\NuGet.exe %NUGET_LOCAL_DIR%\NuGet.exe > nul
)

:: restore packages for build script
echo Restoring NuGet packages for build script...
%NUGET_LOCAL_DIR%\NuGet.exe restore .\packages.config -PackagesDirectory ./packages

:: run build script
echo Running build script...
".\packages\Microsoft.Net.Compilers.%CSI_VERSION%\tools\csi.exe" .\build.csx %*
42 changes: 42 additions & 0 deletions src/build.csx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#load "packages/simple-targets-csx.5.2.1/simple-targets.csx"
#load "scripts/cmd.csx"

using System;
using static SimpleTargets;

var vswhere = "packages/vswhere.2.1.4/tools/vswhere.exe";
var nuget = ".nuget/v4.3.0/NuGet.exe";
string msBuild = null;

var solutions = Directory.EnumerateFiles(".", "*.sln", SearchOption.AllDirectories);

var targets = new TargetDictionary();

targets.Add("default", DependsOn("build"));

targets.Add(
"restore",
() =>
{
foreach (var solution in solutions)
{
Cmd(nuget, $"restore {solution}");
}
});

targets.Add(
"find-msbuild",
() => msBuild = $"{ReadCmd(vswhere, "-latest -requires Microsoft.Component.MSBuild -property installationPath").Trim()}/MSBuild/15.0/Bin/MSBuild.exe");

targets.Add(
"build",
DependsOn("find-msbuild", "restore"),
() =>
{
foreach (var solution in solutions)
{
Cmd(msBuild, $"{solution} /p:Configuration=Debug /nologo /m /v:m /nr:false");
}
});

Run(Args, targets);
6 changes: 6 additions & 0 deletions src/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Net.Compilers" version="2.3.2" />
<package id="simple-targets-csx" version="5.2.1" />
<package id="vswhere" version="2.1.4" />
</packages>
57 changes: 57 additions & 0 deletions src/scripts/cmd.csx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Diagnostics;

public static string ReadCmd(string fileName, string args)
{
var output = new StringBuilder();
using (var process = new Process())
{
process.StartInfo = new ProcessStartInfo {
FileName = $"\"{fileName}\"",
Arguments = args,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
};

process.OutputDataReceived += (sender, e) => output.AppendLine(e.Data);
process.ErrorDataReceived += (sender, e) => output.AppendLine(e.Data);

Console.WriteLine($"Running '{process.StartInfo.FileName} {process.StartInfo.Arguments}'...");
process.Start();

process.BeginOutputReadLine();
process.BeginErrorReadLine();

process.WaitForExit();

if (process.ExitCode != 0)
{
throw new InvalidOperationException($"The command exited with code {process.ExitCode}. {output.ToString()}");
}
}

return output.ToString();
}

public static void Cmd(string fileName, string args)
{
using (var process = new Process())
{
process.StartInfo = new ProcessStartInfo {
FileName = $"\"{fileName}\"",
Arguments = args,
UseShellExecute = false,
};

Console.WriteLine($"Running '{process.StartInfo.FileName} {process.StartInfo.Arguments}'...");
process.Start();

process.WaitForExit();

if (process.ExitCode != 0)
{
throw new InvalidOperationException($"The command exited with code {process.ExitCode}.");
}
}
}