Skip to content

Commit 63dbc9b

Browse files
committed
Add build scripts copied from dotnet/runtime
1 parent d0b1236 commit 63dbc9b

File tree

2 files changed

+159
-0
lines changed

2 files changed

+159
-0
lines changed

build.cmd

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@echo off
2+
setlocal
3+
4+
set _args=%*
5+
if "%~1"=="-?" set _args=-help
6+
7+
powershell -ExecutionPolicy ByPass -NoProfile -File "%~dp0eng\build.ps1" %_args%
8+
exit /b %ERRORLEVEL%

eng/build.ps1

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
[CmdletBinding(PositionalBinding=$false)]
2+
Param(
3+
[switch][Alias('h')]$help,
4+
[switch][Alias('b')]$build,
5+
[switch][Alias('t')]$test,
6+
[switch]$buildtests,
7+
[string][Alias('c')]$configuration = "Debug",
8+
[string][Alias('f')]$framework,
9+
[string]$vs,
10+
[string]$os,
11+
[switch]$allconfigurations,
12+
[switch]$coverage,
13+
[string]$testscope,
14+
[string]$arch,
15+
[string]$subsetCategory,
16+
[string]$subset,
17+
[string]$runtimeConfiguration,
18+
[string]$librariesConfiguration,
19+
[Parameter(ValueFromRemainingArguments=$true)][String[]]$properties
20+
)
21+
22+
function Get-Help() {
23+
Write-Host "Common settings:"
24+
Write-Host " -subset Build a subset, print available subsets with -subset help"
25+
Write-Host " -subsetCategory Build a subsetCategory, print available subsetCategories with -subset help"
26+
Write-Host " -os Build operating system: Windows_NT or Unix"
27+
Write-Host " -arch Build platform: x86, x64, arm or arm64"
28+
Write-Host " -configuration <value> Build configuration: Debug or Release (short: -c)"
29+
Write-Host " -verbosity <value> MSBuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] (short: -v)"
30+
Write-Host " -binaryLog Output binary log (short: -bl)"
31+
Write-Host " -help Print help and exit (short: -h)"
32+
Write-Host ""
33+
34+
Write-Host "Actions (defaults to -restore -build):"
35+
Write-Host " -restore Restore dependencies (short: -r)"
36+
Write-Host " -build Build all source projects (short: -b)"
37+
Write-Host " -buildtests Build all test projects"
38+
Write-Host " -rebuild Rebuild all source projects"
39+
Write-Host " -test Run all unit tests (short: -t)"
40+
Write-Host " -pack Package build outputs into NuGet packages"
41+
Write-Host " -sign Sign build outputs"
42+
Write-Host " -publish Publish artifacts (e.g. symbols)"
43+
Write-Host " -clean Clean the solution"
44+
Write-Host ""
45+
46+
Write-Host "Libraries settings:"
47+
Write-Host " -vs Open the solution with VS for Test Explorer support. Path or solution name (ie -vs Microsoft.CSharp)"
48+
Write-Host " -framework Build framework: netcoreapp or netfx (short: -f)"
49+
Write-Host " -coverage Collect code coverage when testing"
50+
Write-Host " -testscope Scope tests, allowed values: innerloop, outerloop, all"
51+
Write-Host " -allconfigurations Build packages for all build configurations"
52+
Write-Host ""
53+
54+
Write-Host "Command-line arguments not listed above are passed thru to msbuild."
55+
Write-Host "The above arguments can be shortened as much as to be unambiguous (e.g. -con for configuration, -t for test, etc.)."
56+
}
57+
58+
if ($help -or (($null -ne $properties) -and ($properties.Contains('/help') -or $properties.Contains('/?')))) {
59+
Get-Help
60+
exit 0
61+
}
62+
63+
$subsetCategory = $subsetCategory.ToLowerInvariant()
64+
65+
# VS Test Explorer support for libraries
66+
if ($vs) {
67+
. $PSScriptRoot\common\tools.ps1
68+
69+
# Microsoft.DotNet.CoreSetup.sln is special - hosting tests are currently meant to run on the
70+
# bootstrapped .NET Core, not on the live-built runtime.
71+
if ([System.IO.Path]::GetFileName($vs) -ieq "Microsoft.DotNet.CoreSetup.sln") {
72+
if (-Not (Test-Path $vs)) {
73+
$vs = Join-Path "$PSScriptRoot\..\src\installer" $vs
74+
}
75+
76+
# This tells .NET Core to use the bootstrapped runtime to run the tests
77+
$env:DOTNET_ROOT=InitializeDotNetCli -install:$false
78+
}
79+
else {
80+
if (-Not (Test-Path $vs)) {
81+
$vs = Join-Path "$PSScriptRoot\..\src\libraries" $vs | Join-Path -ChildPath "$vs.sln"
82+
}
83+
84+
$archTestHost = if ($arch) { $arch } else { "x64" }
85+
86+
# This tells .NET Core to use the same dotnet.exe that build scripts use
87+
$env:DOTNET_ROOT="$PSScriptRoot\..\artifacts\bin\testhost\netcoreapp5.0-Windows_NT-$configuration-$archTestHost";
88+
}
89+
90+
# This tells MSBuild to load the SDK from the directory of the bootstrapped SDK
91+
$env:DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR=InitializeDotNetCli -install:$false
92+
93+
# This tells .NET Core not to go looking for .NET Core in other places
94+
$env:DOTNET_MULTILEVEL_LOOKUP=0;
95+
96+
# Put our local dotnet.exe on PATH first so Visual Studio knows which one to use
97+
$env:PATH=($env:DOTNET_ROOT + ";" + $env:PATH);
98+
99+
# Launch Visual Studio with the locally defined environment variables
100+
."$vs"
101+
102+
exit 0
103+
}
104+
105+
# Check if an action is passed in
106+
$actions = "r","restore","b","build","buildtests","rebuild","t","test","pack","sign","publish","clean"
107+
$actionPassedIn = @(Compare-Object -ReferenceObject @($PSBoundParameters.Keys) -DifferenceObject $actions -ExcludeDifferent -IncludeEqual).Length -ne 0
108+
if ($null -ne $properties -and $actionPassedIn -ne $true) {
109+
$actionPassedIn = @(Compare-Object -ReferenceObject $properties -DifferenceObject $actions.ForEach({ "-" + $_ }) -ExcludeDifferent -IncludeEqual).Length -ne 0
110+
}
111+
112+
if (!$actionPassedIn) {
113+
$arguments = "-restore -build"
114+
}
115+
116+
$possibleDirToBuild = if($properties.Length -gt 0) { $properties[0]; } else { $null }
117+
118+
if ($null -ne $possibleDirToBuild -and $subsetCategory -eq "libraries") {
119+
$dtb = $possibleDirToBuild.TrimEnd('\')
120+
if (Test-Path $dtb) {
121+
$properties[0] = "/p:DirectoryToBuild=$(Resolve-Path $dtb)"
122+
}
123+
else {
124+
$dtb = Join-Path "$PSSCriptRoot\..\src\libraries" $dtb
125+
if (Test-Path $dtb) {
126+
$properties[0] = "/p:DirectoryToBuild=$(Resolve-Path $dtb)"
127+
}
128+
}
129+
}
130+
131+
foreach ($argument in $PSBoundParameters.Keys)
132+
{
133+
switch($argument)
134+
{
135+
"build" { $arguments += " -build" }
136+
"buildtests" { if ($build -eq $true) { $arguments += " /p:BuildTests=true" } else { $arguments += " -build /p:BuildTests=only" } }
137+
"test" { $arguments += " -test" }
138+
"configuration" { $configuration = (Get-Culture).TextInfo.ToTitleCase($($PSBoundParameters[$argument])); $arguments += " /p:ConfigurationGroup=$configuration -configuration $configuration" }
139+
"runtimeConfiguration" { $arguments += " /p:RuntimeConfiguration=$((Get-Culture).TextInfo.ToTitleCase($($PSBoundParameters[$argument])))" }
140+
# This should be removed after we have finalized our ci build pipeline.
141+
"framework" { if ($PSBoundParameters[$argument].ToLowerInvariant() -eq 'netcoreapp') { $arguments += " /p:TargetGroup=netcoreapp5.0" } else { if ($PSBoundParameters[$argument].ToLowerInvariant() -eq 'netfx') { $arguments += " /p:TargetGroup=net472" } else { $arguments += " /p:TargetGroup=$($PSBoundParameters[$argument].ToLowerInvariant())"}}}
142+
"os" { $arguments += " /p:OSGroup=$($PSBoundParameters[$argument])" }
143+
"allconfigurations" { $arguments += " /p:BuildAllConfigurations=true" }
144+
"arch" { $arguments += " /p:ArchGroup=$($PSBoundParameters[$argument]) /p:TargetArchitecture=$($PSBoundParameters[$argument])" }
145+
"properties" { $arguments += " " + $properties }
146+
default { $arguments += " /p:$argument=$($PSBoundParameters[$argument])" }
147+
}
148+
}
149+
150+
Invoke-Expression "& `"$PSScriptRoot/common/build.ps1`" $arguments"
151+
exit $lastExitCode

0 commit comments

Comments
 (0)