diff --git a/Build.cmd b/Build.cmd
new file mode 100644
index 0000000000000..ac384244199b5
--- /dev/null
+++ b/Build.cmd
@@ -0,0 +1,2 @@
+@echo off
+powershell -noprofile -executionPolicy RemoteSigned -file "%~dp0\build\scripts\build.ps1" -build %*
diff --git a/BuildAndTest.proj b/BuildAndTest.proj
index 2976b4e5577c5..330217a62505c 100644
--- a/BuildAndTest.proj
+++ b/BuildAndTest.proj
@@ -104,7 +104,7 @@
$(NuGetPackageRoot)\xunit.runner.console\$(xunitrunnerconsoleVersion)\tools $(RunTestArgs) @(TestAssemblies, ' ')
-
+
diff --git a/Restore.cmd b/Restore.cmd
index d3f2fcbfe446a..384375b90bca1 100755
--- a/Restore.cmd
+++ b/Restore.cmd
@@ -1,3 +1,3 @@
-@if not defined EchoOn @echo off
-powershell -noprofile -executionPolicy RemoteSigned -file "%~dp0\build\scripts\restore-legacy.ps1" %*
+@echo off
+powershell -noprofile -executionPolicy RemoteSigned -file "%~dp0\build\scripts\build.ps1" -restore %*
diff --git a/Test.cmd b/Test.cmd
new file mode 100644
index 0000000000000..23dcdc38889eb
--- /dev/null
+++ b/Test.cmd
@@ -0,0 +1,2 @@
+@echo off
+powershell -noprofile -executionPolicy RemoteSigned -file "%~dp0\build\scripts\build.ps1" -test %*
diff --git a/build/scripts/build-utils.ps1 b/build/scripts/build-utils.ps1
index d096198c4ff49..4341f3b633d3d 100644
--- a/build/scripts/build-utils.ps1
+++ b/build/scripts/build-utils.ps1
@@ -190,4 +190,60 @@ function Get-VisualStudioDir() {
return $p
}
+# Clear out the NuGet package cache
+function Clear-PackageCache() {
+ $nuget = Ensure-NuGet
+ Exec { & $nuget locals all -clear }
+}
+
+# Restore a single project
+function Restore-Project([string]$fileName, [string]$nuget, [string]$msbuildDir) {
+ $nugetConfig = Join-Path $repoDir "nuget.config"
+ $filePath = Join-Path $repoDir $fileName
+ Exec { & $nuget restore -verbosity quiet -configfile $nugetConfig -MSBuildPath $msbuildDir -Project2ProjectTimeOut 1200 $filePath }
+}
+
+# Restore all of the projects that the repo consumes
+function Restore-Packages([switch]$clean = $false, [string]$msbuildDir = "", [string]$project = "") {
+ $nuget = Ensure-NuGet
+ if ($msbuildDir -eq "") {
+ $msbuildDir = Get-MSBuildDir
+ }
+
+ Write-Host "Restore using MSBuild at $msbuildDir"
+
+ if ($clean) {
+ Write-Host "Deleting project.lock.json files"
+ Get-ChildItem $repoDir -re -in project.lock.json | Remove-Item
+ }
+
+ if ($project -ne "") {
+ Write-Host "Restoring project $project"
+ Restore-Project -fileName $project -nuget $nuget -msbuildDir $msbuildDir
+ }
+ else {
+ $all = @(
+ "Toolsets:build\ToolsetPackages\project.json",
+ "Toolsets (Dev14 VS SDK build tools):build\ToolsetPackages\dev14.project.json",
+ "Toolsets (Dev15 VS SDK RC build tools):build\ToolsetPackages\dev15rc.project.json",
+ "Samples:src\Samples\Samples.sln",
+ "Templates:src\Setup\Templates\Templates.sln",
+ "Toolsets Compiler:build\Toolset\Toolset.csproj",
+ "Roslyn:Roslyn.sln",
+ "DevDivInsertionFiles:src\Setup\DevDivInsertionFiles\DevDivInsertionFiles.sln",
+ "DevDiv Roslyn Packages:src\Setup\DevDivPackages\Roslyn\project.json",
+ "DevDiv Debugger Packages:src\Setup\DevDivPackages\Debugger\project.json")
+
+ foreach ($cur in $all) {
+ $both = $cur.Split(':')
+ Write-Host "Restoring $($both[0])"
+ Restore-Project -fileName $both[1] -nuget $nuget -msbuildDir $msbuildDir
+ }
+ }
+}
+
+# Restore all of the projects that the repo consumes
+function Restore-All([switch]$clean = $false, [string]$msbuildDir = "") {
+ Restore-Packages -clean:$clean -msbuildDir $msbuildDir
+}
diff --git a/build/scripts/build.ps1 b/build/scripts/build.ps1
new file mode 100644
index 0000000000000..25baadee91a16
--- /dev/null
+++ b/build/scripts/build.ps1
@@ -0,0 +1,71 @@
+# Script to run standard developer operations: restore, build and test.
+[CmdletBinding(PositionalBinding=$false)]
+param (
+ [switch]$build = $false,
+ [switch]$restore = $false,
+ [switch]$test = $false,
+ [switch]$clean = $false,
+ [switch]$clearPackageCache = $false,
+ [string]$project = "",
+ [string]$msbuildDir = "")
+
+Set-StrictMode -version 2.0
+$ErrorActionPreference="Stop"
+
+function Print-Usage() {
+ Write-Host "Build.ps1"
+ Write-Host "`t-build Run a build operation (default false)"
+ Write-Hest "`t-restore Run a restore operation (default false)"
+ Write-Hest "`t-test Run tests (default false)"
+ Write-Host "`t-clean Do a clean build / restore (default false)"
+ Write-Host "`t-clearPackageCache Clear package cache before restoring"
+ Write-Host "`t-project Project the build or restore should target"
+ Write-Host "`t-msbuildDir MSBuild which should be used"
+}
+
+function Run-Build() {
+ $buildArgs = "/v:m /m"
+ if ($clean) {
+ $buildArgs = "$buildArgs /t:Rebuild"
+ }
+
+ $target = if ($project -ne "") { $project } else { Join-Path $repoDir "Roslyn.sln" }
+ $buildArgs = "$buildArgs $target"
+
+ Invoke-Expression "& `"$msbuild`" $buildArgs"
+}
+
+function Run-Test() {
+ $proj = Join-Path $repoDir "BuildAndTest.proj"
+ Invoke-Expression "& `"$msbuild`" /v:m /p:SkipCoreClr=true /t:Test $proj"
+}
+
+try {
+ . (Join-Path $PSScriptRoot "build-utils.ps1")
+
+ $nuget = Ensure-NuGet
+ if ($msbuildDir -eq "") {
+ $msbuildDir = Get-MSBuildDir
+ }
+ $msbuild = Join-Path $msbuildDir "msbuild.exe"
+
+ if ($restore) {
+ if ($clearPackageCache) {
+ Clear-PackageCache
+ }
+
+ Restore-Pacakages -clean:$clean -msbuildDir $msbuildDir -project:project
+ }
+
+ if ($build) {
+ Run-Build
+ }
+
+ if ($test) {
+ Run-Test
+ }
+}
+catch {
+ Write-Host $_
+ exit 1
+}
diff --git a/build/scripts/cibuild.ps1 b/build/scripts/cibuild.ps1
index ec4e8abb50f23..a716d1d33e8a7 100644
--- a/build/scripts/cibuild.ps1
+++ b/build/scripts/cibuild.ps1
@@ -60,7 +60,7 @@ try {
if (-not $skipRestore) {
Write-Host "Running restore"
- & ".\build\scripts\restore.ps1" -msbuildDir $msbuildDir
+ Restore-All -msbuildDir $msbuildDir
}
# Ensure the binaries directory exists because msbuild can fail when part of the path to LogFile isn't present.