From dd10bc7fd4a0046d0e27242d7e558dbc34d9fbbd Mon Sep 17 00:00:00 2001 From: Tomas Matousek Date: Fri, 6 Apr 2018 13:02:30 -0700 Subject: [PATCH] Update RepoToolset to 1.0.0-beta2-62804-01 --- .gitignore | 3 + Directory.Build.props | 24 +- build/NuGet.props | 17 - build/Toolset.proj | 14 - build/Versions.props | 21 +- build/build.ps1 | 304 ++++++------ build/build.sh | 440 +++++++++--------- global.json | 11 + nuget.config | 7 + src/Directory.Build.props | 1 - src/Directory.Build.targets | 2 - ...ET.Build.Extensions.Tasks.UnitTests.csproj | 4 +- ...icrosoft.NET.Build.Extensions.Tasks.csproj | 4 +- ...Microsoft.NET.Build.Tasks.UnitTests.csproj | 4 +- .../Microsoft.NET.Build.Tasks.csproj | 6 +- .../Microsoft.NET.Build.Tests.csproj | 4 +- .../Microsoft.NET.Clean.Tests.csproj | 4 +- .../Microsoft.NET.Pack.Tests.csproj | 4 +- .../Microsoft.NET.PerformanceTests.csproj | 4 +- .../Microsoft.NET.Publish.Tests.csproj | 4 +- .../Microsoft.NET.Rebuild.Tests.csproj | 4 +- .../Microsoft.NET.Restore.Tests.csproj | 4 +- .../Attributes/DotNetSdkVersionAttribute.cs | 19 + .../Microsoft.NET.TestFramework.csproj | 20 +- .../ToolsetInfo.cs | 25 +- .../Microsoft.NET.ToolPack.Tests.csproj | 4 +- 26 files changed, 464 insertions(+), 494 deletions(-) delete mode 100644 build/NuGet.props delete mode 100644 build/Toolset.proj create mode 100644 global.json create mode 100644 nuget.config create mode 100644 src/Tests/Microsoft.NET.TestFramework/Attributes/DotNetSdkVersionAttribute.cs diff --git a/.gitignore b/.gitignore index 21a6a9fb03c2..a4cb9646f824 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,9 @@ obj/ # Visual Studio ############################################################################### .vs/ +.dotnet/ +.tools/ +.packages/ # OS X Device Services Store .DS_Store diff --git a/Directory.Build.props b/Directory.Build.props index 4ee76c43ad34..8acc09c11052 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -3,31 +3,11 @@ - Debug + $(MSBuildAllProjects);$(MSBuildThisFileDirectory)..\Directory.Build.props - - - - - - $(MSBuildThisFileDirectory) - $(NuGetPackageRoot)roslyntools.repotoolset\$(RoslynToolsRepoToolsetVersion)\tools\ - - https://dotnetfeed.blob.core.windows.net/dotnet-core/packages/index.json; - https://dotnet.myget.org/F/nuget-build/api/v3/index.json - - - - - $(DOTNET_SDK_ARTIFACTS_DIR) - $(RepoRoot)artifacts\ - $([MSBuild]::EnsureTrailingSlash($(ArtifactsDir))) - $(RepoRoot)artifacts\.dotnet\$(DotNetCliVersion)\ - - + https://github.com/dotnet/sdk $(RepositoryUrl) - diff --git a/build/NuGet.props b/build/NuGet.props deleted file mode 100644 index d28f834f1786..000000000000 --- a/build/NuGet.props +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - - - - - $(NUGET_PACKAGES) - $(UserProfile)\.nuget\packages\ - $(Home)\.nuget\packages\ - $(NuGetPackageRoot)\ - - - diff --git a/build/Toolset.proj b/build/Toolset.proj deleted file mode 100644 index e8395c32d692..000000000000 --- a/build/Toolset.proj +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - net462 - https://dotnet.myget.org/F/roslyn-tools/api/v3/index.json - - - - - - - diff --git a/build/Versions.props b/build/Versions.props index 18ff4343ec7b..8ba788da6a0d 100644 --- a/build/Versions.props +++ b/build/Versions.props @@ -8,22 +8,10 @@ - 2.1.300 + 2.1.300 preview2 - - - false - - - - - 2.1.300-preview3-008414 - 1.0.0-beta-62615-02 - 2.2.7 - - 15.4.8 @@ -47,4 +35,11 @@ 15.0.0 + + + $(RestoreSources); + https://dotnetfeed.blob.core.windows.net/dotnet-core/packages/index.json; + https://dotnet.myget.org/F/nuget-build/api/v3/index.json + + diff --git a/build/build.ps1 b/build/build.ps1 index 26eeaf65d049..04b706f96d5e 100644 --- a/build/build.ps1 +++ b/build/build.ps1 @@ -57,6 +57,11 @@ function Print-Usage() { Write-Host "The above arguments can be shortened as much as to be unambiguous (e.g. -co for configuration, -t for test, etc.)." } +if ($help -or (($properties -ne $null) -and ($properties.Contains("/help") -or $properties.Contains("/?")))) { + Print-Usage + exit 0 +} + function Create-Directory([string[]] $Path) { if (!(Test-Path -Path $Path)) { New-Item -Path $Path -Force -ItemType "Directory" | Out-Null @@ -75,94 +80,114 @@ function GetVersionsPropsVersion([string[]] $Name) { throw "Failed to locate the $Name property" } -function InstallDotNetCli { - $script:DotNetCliVersion = GetVersionsPropsVersion -Name "DotNetCliVersion" - $DotNetInstallVerbosity = "" +function InitializeDotNetCli { + # Don't resolve runtime, shared framework, or SDK from other locations to ensure build determinism + $env:DOTNET_MULTILEVEL_LOOKUP=0 + + # Disable first run since we do not need all ASP.NET packages restored. + $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 - if (!$env:DOTNET_INSTALL_DIR) { - $env:DOTNET_INSTALL_DIR = Join-Path $ArtifactsDir ".dotnet\$DotNetCliVersion" + # Source Build uses DotNetCoreSdkDir variable + if ($env:DotNetCoreSdkDir -ne $null) { + $env:DOTNET_INSTALL_DIR = $env:DotNetCoreSdkDir } - $DotNetRoot = $env:DOTNET_INSTALL_DIR - $DotNetInstallScript = Join-Path $DotNetRoot "dotnet-install.ps1" - - if ($dogfood) { - $env:SDK_REPO_ROOT = $RepoRoot - $env:SDK_CLI_VERSION = $DotNetCliVersion - $env:MSBuildSDKsPath = Join-Path $ArtifactsConfigurationDir "bin\Sdks" - $env:DOTNET_MSBUILD_SDK_RESOLVER_SDKS_DIR = $env:MSBuildSDKsPath - $env:NETCoreSdkBundledVersionsProps = Join-Path $DotNetRoot "sdk\$DotNetCliVersion\Microsoft.NETCoreSdk.BundledVersions.props" - $env:MicrosoftNETBuildExtensionsTargets = Join-Path $env:MSBuildSDKsPath "Microsoft.NET.Build.Extensions\msbuildExtensions\Microsoft\Microsoft.NET.Build.Extensions\Microsoft.NET.Build.Extensions.targets" + # Use dotnet installation specified in DOTNET_INSTALL_DIR if it contains the required SDK version, + # otherwise install the dotnet CLI and SDK to repo local .dotnet directory to avoid potential permission issues. + if (($env:DOTNET_INSTALL_DIR -ne $null) -and (Test-Path(Join-Path $env:DOTNET_INSTALL_DIR "sdk\$($GlobalJson.sdk.version)"))) { + $dotnetRoot = $env:DOTNET_INSTALL_DIR + } else { + $dotnetRoot = Join-Path $RepoRoot ".dotnet" + $env:DOTNET_INSTALL_DIR = $dotnetRoot + + if ($restore) { + InstallDotNetSdk $dotnetRoot $DotNetCliVersion + } } - if (!(Test-Path $DotNetInstallScript)) { - Create-Directory $DotNetRoot - Invoke-WebRequest "https://dot.net/v1/dotnet-install.ps1" -UseBasicParsing -OutFile $DotNetInstallScript - } + $global:BuildDriver = Join-Path $dotnetRoot "dotnet.exe" + $global:BuildArgs = "msbuild" +} - if ($verbosity -eq "diagnostic") { - $DotNetInstallVerbosity = "-Verbose" +function InstallDotNetSdk([string] $dotnetRoot, [string] $version) { + $installScript = GetDotNetInstallScript $dotnetRoot + + & $installScript -Version $version -InstallDir $dotnetRoot + if ($lastExitCode -ne 0) { + throw "Failed to install dotnet SDK $version to '$dotnetRoot' (exit code '$lastExitCode')." } +} - # Install a stage 0 - $SdkInstallDir = Join-Path $DotNetRoot "sdk\$DotNetCliVersion" - - if (!(Test-Path $SdkInstallDir)) { - # Use Invoke-Expression so that $DotNetInstallVerbosity is not positionally bound when empty - Invoke-Expression -Command "& `"$DotNetInstallScript`" -Version $DotNetCliVersion $DotNetInstallVerbosity" - - if($LASTEXITCODE -ne 0) { - throw "Failed to install stage0" - } +function GetDotNetInstallScript([string] $dotnetRoot) { + $installScript = "$dotnetRoot\dotnet-install.ps1" + if (!(Test-Path $installScript)) { + Create-Directory $dotnetRoot + Invoke-WebRequest "https://dot.net/v1/dotnet-install.ps1" -OutFile $installScript } - # Install 1.0 shared framework - $NetCoreApp10Version = "1.0.5" - $NetCoreApp10Dir = Join-Path $DotNetRoot "shared\Microsoft.NETCore.App\$NetCoreApp10Version" + return $installScript +} + +function InstallDotNetSharedFramework([string]$dotnetRoot, [string]$version) { + $fxDir = Join-Path $dotnetRoot "shared\Microsoft.NETCore.App\$version" - if (!(Test-Path $NetCoreApp10Dir)) { - # Use Invoke-Expression so that $DotNetInstallVerbosity is not positionally bound when empty - Invoke-Expression -Command "$DotNetInstallScript -Version $NetCoreApp10Version -SharedRuntime $DotNetInstallVerbosity" + if (!(Test-Path $fxDir)) { + $installScript = GetDotNetInstallScript $dotnetRoot + & $installScript -Version $version -InstallDir $dotnetRoot -SharedRuntime - if($LASTEXITCODE -ne 0) { - throw "Failed to install 1.0 shared framework" + if($lastExitCode -ne 0) { + throw "Failed to install shared Framework $version to '$dotnetRoot' (exit code '$lastExitCode')." } } +} - # Install 1.1 shared framework - $NetCoreApp11Version = "1.1.2" - $NetCoreApp11Dir = Join-Path $DotNetRoot "shared\Microsoft.NETCore.App\$NetCoreApp11Version" +function InitializeCustomToolset { + if ($fullMSBuild) { + if (!($env:VSInstallDir)) { + $env:VSInstallDir = LocateVisualStudio + } - if (!(Test-Path $NetCoreApp11Dir)) { - # Use Invoke-Expression so that $DotNetInstallVerbosity is not positionally bound when empty - Invoke-Expression -Command "$DotNetInstallScript -Version $NetCoreApp11Version -SharedRuntime $DotNetInstallVerbosity" + $env:DOTNET_SDK_TEST_MSBUILD_PATH = Join-Path $env:VSInstallDir "MSBuild\15.0\Bin\msbuild.exe" + } - if($LASTEXITCODE -ne 0) { - throw "Failed to install 1.1 shared framework" + if ($dogfood) + { + $env:SDK_REPO_ROOT = $RepoRoot + $env:SDK_CLI_VERSION = $DotNetCliVersion + $env:MSBuildSDKsPath = Join-Path $ArtifactsConfigurationDir "bin\Sdks" + $env:DOTNET_MSBUILD_SDK_RESOLVER_SDKS_DIR = $env:MSBuildSDKsPath + $env:NETCoreSdkBundledVersionsProps = Join-Path $env:DOTNET_INSTALL_DIR "sdk\$DotNetCliVersion\Microsoft.NETCoreSdk.BundledVersions.props" + $env:MicrosoftNETBuildExtensionsTargets = Join-Path $env:MSBuildSDKsPath "Microsoft.NET.Build.Extensions\msbuildExtensions\Microsoft\Microsoft.NET.Build.Extensions\Microsoft.NET.Build.Extensions.targets" + + if ($properties -eq $null -and $env:DOTNET_SDK_DOGFOOD_SHELL -ne $null) + { + $properties = , $env:DOTNET_SDK_DOGFOOD_SHELL + } + if ($properties -ne $null) + { + $Host.UI.RawUI.WindowTitle = "SDK Test ($RepoRoot) ($configuration)" + & $properties[0] $properties[1..($properties.Length-1)] } } - # Install 2.0 shared framework - $NetCoreApp20Version = "2.0.0" - $NetCoreApp20Dir = Join-Path $DotNetRoot "shared\Microsoft.NETCore.App\$NetCoreApp20Version" - - if (!(Test-Path $NetCoreApp20Dir)) { - # Use Invoke-Expression so that $DotNetInstallVerbosity is not positionally bound when empty - Invoke-Expression -Command "$DotNetInstallScript -Version $NetCoreApp20Version -SharedRuntime $DotNetInstallVerbosity" + if (-not $restore) { + return + } - if($LASTEXITCODE -ne 0) { - throw "Failed to install 2.0 shared framework" - } + # The following frameworks and tools are used only for testing. + # Do not attempt to install them in source build. + if ($env:DotNetBuildFromSource -eq "true") { + return } + + $dotnetRoot = $env:DOTNET_INSTALL_DIR - # Put the stage 0 on the path - $env:PATH = "$DotNetRoot;$env:PATH" + InstallDotNetSharedFramework $dotnetRoot "1.0.5" + InstallDotNetSharedFramework $dotnetRoot "1.1.2" + InstallDotNetSharedFramework $dotnetRoot "2.0.0" - # Disable first run since we want to control all package sources - $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 - - # Don't resolve runtime, shared framework, or SDK from other locations - $env:DOTNET_MULTILEVEL_LOOKUP=0 + CreateBuildEnvScript + InstallNuget } function InstallNuGet { @@ -175,32 +200,36 @@ function InstallNuGet { } } -function InstallRepoToolset { - $RepoToolsetVersion = GetVersionsPropsVersion -Name "RoslynToolsRepoToolsetVersion" - $RepoToolsetDir = Join-Path $NuGetPackageRoot "roslyntools.repotoolset\$RepoToolsetVersion\tools" - $RepoToolsetBuildProj = Join-Path $RepoToolsetDir "Build.proj" +function InitializeToolset { + $toolsetVersion = $GlobalJson.'msbuild-sdks'.'RoslynTools.RepoToolset' + $toolsetLocationFile = Join-Path $ToolsetDir "$toolsetVersion.txt" - if ($ci -or $log) { - Create-Directory $LogDir - $logCmd = "/bl:" + (Join-Path $LogDir "Toolset.binlog") - } else { - $logCmd = "" + if (Test-Path $toolsetLocationFile) { + $path = Get-Content $toolsetLocationFile + if (Test-Path $path) { + $global:ToolsetBuildProj = $path + return + } } - if (!(Test-Path -Path $RepoToolsetBuildProj)) { - $ToolsetProj = Join-Path $PSScriptRoot "Toolset.proj" - dotnet msbuild $ToolsetProj /t:restore /m /nologo /clp:Summary /warnaserror /v:$verbosity $logCmd | Write-Host + if (-not $restore) { + throw "Toolset version $toolsetVersion has not been restored." + } - if($LASTEXITCODE -ne 0) { - throw "Failed to build $ToolsetProj" - } + $proj = Join-Path $ToolsetDir "restore.proj" + + '' | Set-Content $proj + & $BuildDriver $BuildArgs $proj /t:__WriteToolsetLocation /m /nologo /clp:None /warnaserror /bl:$ToolsetRestoreLog /v:$verbosity /p:__ToolsetLocationOutputFile=$toolsetLocationFile + + if ($lastExitCode -ne 0) { + throw "Failed to restore toolset (exit code '$lastExitCode'). See log: $ToolsetRestoreLog" } - return $RepoToolsetBuildProj + $global:ToolsetBuildProj = Get-Content $toolsetLocationFile } function LocateVisualStudio { - $VSWhereVersion = GetVersionsPropsVersion -Name "VSWhereVersion" + $VSWhereVersion = $GlobalJson.vswhere.version $VSWhereDir = Join-Path $ArtifactsDir ".tools\vswhere\$VSWhereVersion" $VSWhereExe = Join-Path $vsWhereDir "vswhere.exe" @@ -219,62 +248,16 @@ function LocateVisualStudio { } function Build { - InstallDotNetCli - InstallNuget - CreateBuildEnvScript - $RepoToolsetBuildProj = InstallRepoToolset - - if ($prepareMachine) { - Create-Directory $NuGetPackageRoot - dotnet nuget locals all --clear - - if($LASTEXITCODE -ne 0) { - throw "Failed to clear NuGet cache" - } - } - - if ($fullMSBuild) { - if (!($env:VSInstallDir)) { - $env:VSInstallDir = LocateVisualStudio - } + & $BuildDriver $BuildArgs $ToolsetBuildProj /m /nologo /clp:Summary /warnaserror /v:$verbosity /bl:$BuildLog /p:Configuration=$configuration /p:Projects=$solution /p:RepoRoot=$RepoRoot /p:Restore=$restore /p:Build=$build /p:Rebuild=$rebuild /p:Deploy=$deploy /p:Test=$test /p:Sign=$sign /p:Pack=$pack /p:CIBuild=$ci $properties - $env:DOTNET_SDK_TEST_MSBUILD_PATH = Join-Path $env:VSInstallDir "MSBuild\15.0\Bin\msbuild.exe" - } - - if ($dogfood) - { - if ($properties -eq $null -and $env:DOTNET_SDK_DOGFOOD_SHELL -ne $null) - { - $properties = , $env:DOTNET_SDK_DOGFOOD_SHELL - } - if ($properties -ne $null) - { - $Host.UI.RawUI.WindowTitle = "SDK Test ($RepoRoot) ($configuration)" - & $properties[0] $properties[1..($properties.Length-1)] - } - exit 0 - } - - if ($ci -or $log) { - Create-Directory $LogDir - $logCmd = "/bl:" + (Join-Path $LogDir "Build.binlog") - } else { - $logCmd = "" - } - - if ($solution -eq "") { - $solution = Join-Path $RepoRoot "sdk.sln" - } - - dotnet msbuild $RepoToolsetBuildProj /m /nologo /clp:Summary /warnaserror /v:$verbosity $logCmd /p:Configuration=$configuration /p:SolutionPath=$solution /p:Restore=$restore /p:Build=$build /p:Rebuild=$rebuild /p:Deploy=$deploy /p:Test=$test /p:PerformanceTest=$perf /p:Sign=$sign /p:Pack=$pack /p:CIBuild=$ci $properties - - if($LASTEXITCODE -ne 0) { - throw "Failed to build $RepoToolsetBuildProj" + if ($lastExitCode -ne 0) { + throw "Failed to build (exit code '$lastExitCode'). See log: $BuildLog" } } function Stop-Processes() { Write-Host "Killing running build processes..." + Get-Process -Name "dotnet" -ErrorAction SilentlyContinue | Stop-Process Get-Process -Name "msbuild" -ErrorAction SilentlyContinue | Stop-Process Get-Process -Name "vbcscompiler" -ErrorAction SilentlyContinue | Stop-Process } @@ -296,39 +279,52 @@ set NUGET_PACKAGES=$env:NUGET_PACKAGES Out-File -FilePath $scriptPath -InputObject $scriptContents -Encoding ASCII } -if ($help -or (($properties -ne $null) -and ($properties.Contains("/help") -or $properties.Contains("/?")))) { - Print-Usage - exit 0 -} +try { + $RepoRoot = Join-Path $PSScriptRoot ".." + $RepoRoot = [System.IO.Path]::GetFullPath($RepoRoot); -$RepoRoot = Join-Path $PSScriptRoot ".." -$RepoRoot = [System.IO.Path]::GetFullPath($RepoRoot); + $ArtifactsDir = $env:DOTNET_SDK_ARTIFACTS_DIR + if (!($ArtifactsDir)) { + $ArtifactsDir = Join-Path $RepoRoot "artifacts" + } -$ArtifactsDir = $env:DOTNET_SDK_ARTIFACTS_DIR -if (!($ArtifactsDir)) { - $ArtifactsDir = Join-Path $RepoRoot "artifacts" -} -$ArtifactsConfigurationDir = Join-Path $ArtifactsDir $configuration -$LogDir = Join-Path $ArtifactsConfigurationDir "log" -$VersionsProps = Join-Path $PSScriptRoot "Versions.props" + $ArtifactsConfigurationDir = Join-Path $ArtifactsDir $configuration + $ToolsetDir = Join-Path $ArtifactsDir "toolset" + $LogDir = Join-Path $ArtifactsConfigurationDir "log" + $BuildLog = Join-Path $LogDir "Build.binlog" + $ToolsetRestoreLog = Join-Path $LogDir "ToolsetRestore.binlog" + $TempDir = Join-Path $ArtifactsConfigurationDir "tmp" + $GlobalJson = Get-Content(Join-Path $RepoRoot "global.json") | ConvertFrom-Json + $DotNetCliVersion = $GlobalJson.sdk.version -try { + if ($solution -eq "") { + $solution = Join-Path $RepoRoot "*.sln" + } + + if ($env:NUGET_PACKAGES -eq $null) { + # Use local cache on CI to ensure deterministic build, + # use global cache in dev builds to avoid cost of downloading packages. + $env:NUGET_PACKAGES = if ($ci) { Join-Path $RepoRoot ".packages" } + else { Join-Path $env:UserProfile ".nuget\packages" } + } + + Create-Directory $ToolsetDir + Create-Directory $LogDir + if ($ci) { - $TempDir = Join-Path $ArtifactsConfigurationDir "tmp" Create-Directory $TempDir - $env:TEMP = $TempDir $env:TMP = $TempDir } - if (!($env:NUGET_PACKAGES)) { - $env:NUGET_PACKAGES = Join-Path $env:UserProfile ".nuget\packages" - } - - $NuGetPackageRoot = $env:NUGET_PACKAGES + InitializeDotNetCli + InitializeToolset + InitializeCustomToolset - Build - exit $LASTEXITCODE + if (-not $dogfood) + { + Build + } } catch { Write-Host $_ diff --git a/build/build.sh b/build/build.sh index 80a0cf45df3d..6468f036c0e8 100755 --- a/build/build.sh +++ b/build/build.sh @@ -1,23 +1,52 @@ -#!/bin/bash +#!/usr/bin/env bash + +source="${BASH_SOURCE[0]}" + +# resolve $source until the file is no longer a symlink +while [[ -h "$source" ]]; do + scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + source="$(readlink "$source")" + # if $source was a relative symlink, we need to resolve it relative to the path where the + # symlink file was located + [[ $source != /* ]] && source="$scriptroot/$source" +done +scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" build=false ci=false -configuration="Debug" -dogfood=false -log=false +configuration='Debug' +help=false pack=false -prepareMachine=false +prepare_machine=false rebuild=false restore=false sign=false -solution="" +projects='' test=false -perf=false -verbosity="minimal" -properties=() +verbosity='minimal' +properties='' -while [[ $# -gt 0 ]]; do - lowerI="$(echo "$1" | awk '{print tolower($0)}')" +repo_root="$scriptroot/.." + +if [[ -z $DOTNET_SDK_ARTIFACTS_DIR ]]; then + artifacts_dir="$repo_root/artifacts" +else + artifacts_dir="$DOTNET_SDK_ARTIFACTS_DIR" +fi + +artifacts_configuration_dir="$artifacts_dir/$configuration" +toolset_dir="$artifacts_dir/toolset" +log_dir="$artifacts_configuration_dir/log" +build_log="$log_dir/Build.binlog" +toolset_restore_log="$log_dir/ToolsetRestore.binlog" +temp_dir="$artifacts_configuration_dir/tmp" + +global_json_file="$repo_root/global.json" +build_driver="" +toolset_build_proj="" + +while (($# > 0)); do + lowerI="$(echo $1 | awk '{print tolower($0)}')" case $lowerI in --build) build=true @@ -57,22 +86,17 @@ while [[ $# -gt 0 ]]; do echo " will be ignored." echo " --solution Path to solution to build" echo " --ci Set when running on CI server" - echo " --log Enable logging (by default on CI)" echo " --prepareMachine Prepare machine for CI run" echo "" echo "Command line arguments not listed above are passed through to MSBuild." exit 0 ;; - --log) - log=true - shift 1 - ;; --pack) pack=true shift 1 ;; - --prepareMachine) - prepareMachine=true + --preparemachine) + prepare_machine=true shift 1 ;; --rebuild) @@ -104,269 +128,237 @@ while [[ $# -gt 0 ]]; do shift 2 ;; *) - properties+=("$1") + properties="$properties $1" shift 1 ;; esac done -function CreateDirectory { - if [ ! -d "$1" ] - then - mkdir -p "$1" - fi -} - -function GetVersionsPropsVersion { - echo "$( awk -F'[<>]' "/<$1>/{print \$3}" "$VersionsProps" )" +# ReadJson [filename] [json key] +# Result: Sets 'readjsonvalue' to the value of the provided json key +# Note: this method may return unexpected results if there are duplicate +# keys in the json +function ReadJson { + local file=$1 + local key=$2 + + local unamestr="$(uname)" + local sedextended='-r' + if [[ "$unamestr" == 'Darwin' ]]; then + sedextended='-E' + fi; + + readjsonvalue="$(grep -m 1 "\"$key\"" $file | sed $sedextended 's/^ *//;s/.*: *"//;s/",?//')" + if [[ ! "$readjsonvalue" ]]; then + echo "Error: Cannot find \"$key\" in $file" >&2; + ExitWithExitCode 1 + fi; } -function InstallDotNetCli { - DotNetCliVersion="$( GetVersionsPropsVersion DotNetCliVersion )" - DotNetInstallVerbosity="" +function InitializeDotNetCli { + # Disable first run since we want to control all package sources + export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 - if $dogfood - then - export SDK_REPO_ROOT="$RepoRoot" - export SDK_CLI_VERSION="$DotNetCliVersion" - export MSBuildSDKsPath="$ArtifactsConfigurationDir/bin/Sdks" - export DOTNET_MSBUILD_SDK_RESOLVER_SDKS_DIR="$MSBuildSDKsPath" - export NETCoreSdkBundledVersionsProps="$DotNetRoot/sdk/$DotNetCliVersion/Microsoft.NETCoreSdk.BundledVersions.props" - export CustomAfterMicrosoftCommonTargets="$MSBuildSDKsPath/Microsoft.NET.Build.Extensions/msbuildExtensions-ver/Microsoft.Common.Targets/ImportAfter/Microsoft.NET.Build.Extensions.targets" - export MicrosoftNETBuildExtensionsTargets="$CustomAfterMicrosoftCommonTargets" - fi + # Don't resolve runtime, shared framework, or SDK from other locations to ensure build determinism + export DOTNET_MULTILEVEL_LOOKUP=0 - if [ -z "$DOTNET_INSTALL_DIR" ] - then - export DOTNET_INSTALL_DIR="$ArtifactsDir/.dotnet/$DotNetCliVersion" + # Source Build uses DotNetCoreSdkDir variable + if [[ -n "$DotNetCoreSdkDir" ]]; then + export DOTNET_INSTALL_DIR="$DotNetCoreSdkDir" fi - DotNetRoot=$DOTNET_INSTALL_DIR - DotNetInstallScript="$DotNetRoot/dotnet-install.sh" + ReadJson "$global_json_file" "version" + local dotnet_sdk_version="$readjsonvalue" + local dotnet_root="" - if [ ! -a "$DotNetInstallScript" ] - then - CreateDirectory "$DotNetRoot" - curl "https://dot.net/v1/dotnet-install.sh" -sSL -o "$DotNetInstallScript" - fi + # Use dotnet installation specified in DOTNET_INSTALL_DIR if it contains the required SDK version, + # otherwise install the dotnet CLI and SDK to repo local .dotnet directory to avoid potential permission issues. + if [[ -d "$DOTNET_INSTALL_DIR/sdk/$dotnet_sdk_version" ]]; then + dotnet_root="$DOTNET_INSTALL_DIR" + else + dotnet_root="$repo_root/.dotnet" + export DOTNET_INSTALL_DIR="$dotnet_root" - if [[ "$(echo "$verbosity" | awk '{print tolower($0)}')" == "diagnostic" ]] - then - DotNetInstallVerbosity="--verbose" + if [[ "$restore" == true ]]; then + InstallDotNetSdk $dotnet_root $dotnet_sdk_version + fi fi - # Install a stage 0 - SdkInstallDir="$DotNetRoot/sdk/$DotNetCliVersion" + build_driver="$dotnet_root/dotnet" +} - if [ ! -d "$SdkInstallDir" ] - then - bash "$DotNetInstallScript" --version "$DotNetCliVersion" $DotNetInstallVerbosity - LASTEXITCODE=$? +function InstallDotNetSdk { + local root=$1 + local version=$2 - if [ $LASTEXITCODE != 0 ] - then - echo "Failed to install stage0" - return $LASTEXITCODE - fi - fi + local install_script=`GetDotNetInstallScript $root` - # Install 1.0 shared framework - NetCoreApp10Version="1.0.5" - NetCoreApp10Dir="$DotNetRoot/shared/Microsoft.NETCore.App/$NetCoreApp10Version" + bash "$install_script" --version $version --install-dir $root + local lastexitcode=$? - if [ ! -d "$NetCoreApp10Dir" ] - then - bash "$DotNetInstallScript" --version $NetCoreApp10Version --shared-runtime $DotNetInstallVerbosity - LASTEXITCODE=$? - - if [ $LASTEXITCODE != 0 ] - then - echo "Failed to install 1.0 shared framework" - return $LASTEXITCODE - fi + if [[ $lastexitcode != 0 ]]; then + echo "Failed to install dotnet SDK (exit code '$lastexitcode')." + ExitWithExitCode $lastexitcode fi +} - # Install 1.1 shared framework - NetCoreApp11Version="1.1.2" - NetCoreApp11Dir="$DotNetRoot/shared/Microsoft.NETCore.App/$NetCoreApp11Version" +function GetDotNetInstallScript { + local root=$1 + local install_script="$root/dotnet-install.sh" - if [ ! -d "$NetCoreApp11Dir" ] - then - bash "$DotNetInstallScript" --version $NetCoreApp11Version --shared-runtime $DotNetInstallVerbosity - LASTEXITCODE=$? + if [[ ! -a "$install_script" ]]; then + mkdir -p "$root" - if [ $LASTEXITCODE != 0 ] - then - echo "Failed to install 1.1 shared framework" - return $LASTEXITCODE + # Use curl if available, otherwise use wget + if command -v curl > /dev/null; then + curl "https://dot.net/v1/dotnet-install.sh" -sSL --retry 10 --create-dirs -o "$install_script" + else + wget -q -O "$install_script" "https://dot.net/v1/dotnet-install.sh" fi fi - # Install 2.0 shared framework - NetCoreApp20Version="2.0.0" - NetCoreApp20Dir="$DotNetRoot/shared/Microsoft.NETCore.App/$NetCoreApp20Version" + # return value + echo "$install_script" +} - if [ ! -d "$NetCoreApp20Dir" ] - then - bash "$DotNetInstallScript" --version $NetCoreApp20Version --shared-runtime $DotNetInstallVerbosity - LASTEXITCODE=$? +function InitializeToolset { + ReadJson $global_json_file "RoslynTools.RepoToolset" + local toolset_version=$readjsonvalue + local toolset_location_file="$toolset_dir/$toolset_version.txt" - if [ $LASTEXITCODE != 0 ] - then - echo "Failed to install 2.0 shared framework" - return $LASTEXITCODE + if [[ -a "$toolset_location_file" ]]; then + local path=`cat $toolset_location_file` + if [[ -a "$path" ]]; then + toolset_build_proj=$path + return fi + fi + + if [[ "$restore" != true ]]; then + echo "Toolset version $toolsetVersion has not been restored." + ExitWithExitCode 2 fi + + local proj="$toolset_dir/restore.proj" - # Put the stage 0 on the path - export PATH="$DotNetRoot:$PATH" + echo '' > $proj + "$build_driver" msbuild $proj /t:__WriteToolsetLocation /m /nologo /clp:None /warnaserror /bl:$toolset_restore_log /v:$verbosity /p:__ToolsetLocationOutputFile=$toolset_location_file + local lastexitcode=$? - # Disable first run since we want to control all package sources - export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 + if [[ $lastexitcode != 0 ]]; then + echo "Failed to restore toolset (exit code '$lastexitcode'). See log: $toolset_restore_log" + ExitWithExitCode $lastexitcode + fi - # Don't resolve runtime, shared framework, or SDK from other locations - export DOTNET_MULTILEVEL_LOOKUP=0 + toolset_build_proj=`cat $toolset_location_file` } -function InstallRepoToolset { - RepoToolsetVersion="$( GetVersionsPropsVersion RoslynToolsRepoToolsetVersion )" - RepoToolsetDir="$NuGetPackageRoot/roslyntools.repotoolset/$RepoToolsetVersion/tools" - RepoToolsetBuildProj="$RepoToolsetDir/Build.proj" +function InitializeCustomToolset { + if [[ "$dogfood" == true ]]; then + export SDK_REPO_ROOT="$RepoRoot" + export SDK_CLI_VERSION="$DotNetCliVersion" + export MSBuildSDKsPath="$ArtifactsConfigurationDir/bin/Sdks" + export DOTNET_MSBUILD_SDK_RESOLVER_SDKS_DIR="$MSBuildSDKsPath" + export NETCoreSdkBundledVersionsProps="$DotNetRoot/sdk/$DotNetCliVersion/Microsoft.NETCoreSdk.BundledVersions.props" + export CustomAfterMicrosoftCommonTargets="$MSBuildSDKsPath/Microsoft.NET.Build.Extensions/msbuildExtensions-ver/Microsoft.Common.Targets/ImportAfter/Microsoft.NET.Build.Extensions.targets" + export MicrosoftNETBuildExtensionsTargets="$CustomAfterMicrosoftCommonTargets" + fi - if $ci || $log - then - CreateDirectory "$LogDir" - logCmd="/bl:$LogDir/Build.binlog" - else - logCmd="" + if [[ "$restore" != true ]]; then + return fi - if [ ! -d "$RepoToolsetBuildProj" ] - then - ToolsetProj="$ScriptRoot/Toolset.proj" - dotnet msbuild "$ToolsetProj" /t:restore /m /nologo /clp:Summary /warnaserror "/v:$verbosity" $logCmd - LASTEXITCODE=$? + # The following frameworks and tools are used only for testing. + # Do not attempt to install them in source build. + if [[ "$DotNetBuildFromSource" == "true" ]]; then + return + fi + + InstallDotNetSharedFramework $DOTNET_INSTALL_DIR "1.0.5" + InstallDotNetSharedFramework $DOTNET_INSTALL_DIR "1.1.2" + InstallDotNetSharedFramework $DOTNET_INSTALL_DIR "2.0.0" +} - if [ $LASTEXITCODE != 0 ] - then - echo "Failed to build $ToolsetProj" - return $LASTEXITCODE +# Installs additional shared frameworks for testing purposes +function InstallDotNetSharedFramework { + local dotnet_root=$1 + local version=$2 + local fx_dir="$dotnet_root/shared/Microsoft.NETCore.App/$version" + + if [[ ! -d "$fx_dir" ]]; then + local install_script=`GetDotNetInstallScript $dotnet_root` + + bash "$install_script" --version $version --install-dir $dotnet_root --shared-runtime + local lastexitcode=$? + + if [[ $lastexitcode != 0 ]]; then + echo "Failed to install Shared Framework $version to '$dotnet_root' (exit code '$lastexitcode')." + ExitWithExitCode $lastexitcode fi fi } function Build { - if ! InstallDotNetCli - then - return $? - fi - - if ! InstallRepoToolset - then - return $? - fi - - if $prepareMachine - then - CreateDirectory "$NuGetPackageRoot" - dotnet nuget locals all --clear - LASTEXITCODE=$? - - if [ $LASTEXITCODE != 0 ] - then - echo "Failed to clear NuGet cache" - return $LASTEXITCODE - fi + "$build_driver" msbuild $toolset_build_proj /m /nologo /clp:Summary /warnaserror \ + /v:$verbosity /bl:$build_log /p:Configuration=$configuration /p:Projects=$projects /p:RepoRoot="$repo_root" \ + /p:Restore=$restore /p:Build=$build /p:Rebuild=$rebuild /p:Deploy=$deploy /p:Test=$test /p:Sign=$sign /p:Pack=$pack /p:CIBuild=$ci \ + $properties + local lastexitcode=$? + + if [[ $lastexitcode != 0 ]]; then + echo "Failed to build $toolset_build_proj" + ExitWithExitCode $lastexitcode fi +} - if [ $dogfood != true ] - then - if $ci || $log - then - CreateDirectory "$LogDir" - logCmd="/bl:$LogDir/Build.binlog" - else - logCmd="" - fi - - if [ -z "$solution" ] - then - solution="$RepoRoot/sdk.sln" - fi - - dotnet msbuild $RepoToolsetBuildProj /m /nologo /clp:Summary /warnaserror "/v:$verbosity" $logCmd "/p:Configuration=$configuration" "/p:SolutionPath=$solution" /p:Restore=$restore /p:Build=$build /p:Rebuild=$rebuild /p:Deploy=$deploy /p:Test=$test /p:PerformanceTest=$perf /p:Sign=$sign /p:Pack=$pack /p:CIBuild=$ci "${properties[@]}" - LASTEXITCODE=$? - - if [ $LASTEXITCODE != 0 ] - then - echo "Failed to build $RepoToolsetBuildProj" - return $LASTEXITCODE - fi +function ExitWithExitCode { + if [[ "$ci" == true && "$prepare_machine" == true ]]; then + StopProcesses fi + exit $1 } function StopProcesses { echo "Killing running build processes..." - pkill -9 "msbuild" + pkill -9 "dotnet" pkill -9 "vbcscompiler" } -SOURCE="${BASH_SOURCE[0]}" -while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink - ScriptRoot="$( cd -P "$( dirname "$SOURCE" )" && pwd )" - SOURCE="$(readlink "$SOURCE")" - [[ $SOURCE != /* ]] && SOURCE="$ScriptRoot/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located -done -ScriptRoot="$( cd -P "$( dirname "$SOURCE" )" && pwd )" - -RepoRoot="$ScriptRoot/.." -if [ -z $DOTNET_SDK_ARTIFACTS_DIR ] -then - ArtifactsDir="$RepoRoot/artifacts" -else - ArtifactsDir="$DOTNET_SDK_ARTIFACTS_DIR" -fi - - -ArtifactsConfigurationDir="$ArtifactsDir/$configuration" -LogDir="$ArtifactsConfigurationDir/log" -VersionsProps="$ScriptRoot/Versions.props" - -# HOME may not be defined in some scenarios, but it is required by NuGet -if [ -z "$HOME" ] -then - export HOME="$ArtifactsDir/.home/" - CreateDirectory "$HOME" -fi - -if $ci -then - TempDir="$ArtifactsConfigurationDir/tmp" - CreateDirectory "$TempDir" +function Main { + # HOME may not be defined in some scenarios, but it is required by NuGet + if [[ -z $HOME ]]; then + export HOME="$repo_root/artifacts/.home/" + mkdir -p "$HOME" + fi - export TEMP="$TempDir" - export TMP="$TempDir" -fi + if [[ -z $projects ]]; then + projects="$repo_root/*.sln" + fi -if [ -z "$NUGET_PACKAGES" ] -then - export NUGET_PACKAGES="$HOME/.nuget/packages" -fi + if [[ -z $NUGET_PACKAGES ]]; then + if [[ $ci ]]; then + export NUGET_PACKAGES="$repo_root/.packages" + else + export NUGET_PACKAGES="$HOME/.nuget/packages" + fi + fi -NuGetPackageRoot=$NUGET_PACKAGES + mkdir -p "$toolset_dir" + mkdir -p "$log_dir" + + if [[ $ci ]]; then + mkdir -p "$temp_dir" + export TEMP="$temp_dir" + export TMP="$temp_dir" + fi -Build -LASTEXITCODE=$? + InitializeDotNetCli + InitializeToolset + InitializeCustomToolset -if $ci && $prepareMachine -then - StopProcesses -fi + if [[ "$dogfood" != true ]]; then + Build + fi +} -# The script should be sourced if using --dogfood, which means in that case we don't want to exit -if [ $dogfood = true ] -then - return $LASTEXITCODE -else - exit $LASTEXITCODE -fi +Main diff --git a/global.json b/global.json new file mode 100644 index 000000000000..648f059ca91b --- /dev/null +++ b/global.json @@ -0,0 +1,11 @@ +{ + "sdk": { + "version": "2.1.300-preview3-008414" + }, + "msbuild-sdks": { + "RoslynTools.RepoToolset": "1.0.0-beta2-62805-03" + }, + "vswhere": { + "version": "2.2.7" + } +} diff --git a/nuget.config b/nuget.config new file mode 100644 index 000000000000..071c39f2a9fd --- /dev/null +++ b/nuget.config @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/Directory.Build.props b/src/Directory.Build.props index a2377512d006..6ac758705d72 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -7,7 +7,6 @@ - 1.6.0 diff --git a/src/Directory.Build.targets b/src/Directory.Build.targets index 7cb5132c2472..181c86d6f721 100644 --- a/src/Directory.Build.targets +++ b/src/Directory.Build.targets @@ -10,6 +10,4 @@ - - diff --git a/src/Tasks/Microsoft.NET.Build.Extensions.Tasks.UnitTests/Microsoft.NET.Build.Extensions.Tasks.UnitTests.csproj b/src/Tasks/Microsoft.NET.Build.Extensions.Tasks.UnitTests/Microsoft.NET.Build.Extensions.Tasks.UnitTests.csproj index b79e11363c5a..98d738639952 100644 --- a/src/Tasks/Microsoft.NET.Build.Extensions.Tasks.UnitTests/Microsoft.NET.Build.Extensions.Tasks.UnitTests.csproj +++ b/src/Tasks/Microsoft.NET.Build.Extensions.Tasks.UnitTests/Microsoft.NET.Build.Extensions.Tasks.UnitTests.csproj @@ -12,7 +12,7 @@ Tests\$(MSBuildProjectName) - + @@ -33,6 +33,6 @@ - + diff --git a/src/Tasks/Microsoft.NET.Build.Extensions.Tasks/Microsoft.NET.Build.Extensions.Tasks.csproj b/src/Tasks/Microsoft.NET.Build.Extensions.Tasks/Microsoft.NET.Build.Extensions.Tasks.csproj index 16b3089002cb..334868dca93c 100644 --- a/src/Tasks/Microsoft.NET.Build.Extensions.Tasks/Microsoft.NET.Build.Extensions.Tasks.csproj +++ b/src/Tasks/Microsoft.NET.Build.Extensions.Tasks/Microsoft.NET.Build.Extensions.Tasks.csproj @@ -23,7 +23,7 @@ true - + true @@ -100,6 +100,6 @@ - + diff --git a/src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/Microsoft.NET.Build.Tasks.UnitTests.csproj b/src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/Microsoft.NET.Build.Tasks.UnitTests.csproj index 5d25832e57cc..1198d6c297a5 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/Microsoft.NET.Build.Tasks.UnitTests.csproj +++ b/src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/Microsoft.NET.Build.Tasks.UnitTests.csproj @@ -12,7 +12,7 @@ Tests\$(MSBuildProjectName) - + @@ -36,6 +36,6 @@ - + diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/Microsoft.NET.Build.Tasks.csproj b/src/Tasks/Microsoft.NET.Build.Tasks/Microsoft.NET.Build.Tasks.csproj index 0f610b5c1021..58ceea181455 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/Microsoft.NET.Build.Tasks.csproj +++ b/src/Tasks/Microsoft.NET.Build.Tasks/Microsoft.NET.Build.Tasks.csproj @@ -19,7 +19,7 @@ true - + true @@ -71,7 +71,7 @@ <_NugetBuildTasksPackPath>$(NuGetPackageRoot)nuget.build.tasks.pack\$(NuGetBuildTasksPackVersion) - <_Stage0SdksFolder>$(DOTNET_INSTALL_DIR)\sdk\$(DotNetCliVersion)\Sdks + <_Stage0SdksFolder>$(DOTNET_INSTALL_DIR)\sdk\$(NETCoreSdkVersion)\Sdks @@ -116,6 +116,6 @@ - + diff --git a/src/Tests/Microsoft.NET.Build.Tests/Microsoft.NET.Build.Tests.csproj b/src/Tests/Microsoft.NET.Build.Tests/Microsoft.NET.Build.Tests.csproj index fca8d252af51..8784cb6f9b1b 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/Microsoft.NET.Build.Tests.csproj +++ b/src/Tests/Microsoft.NET.Build.Tests/Microsoft.NET.Build.Tests.csproj @@ -13,7 +13,7 @@ Tests\$(MSBuildProjectName) - + @@ -46,6 +46,6 @@ - + diff --git a/src/Tests/Microsoft.NET.Clean.Tests/Microsoft.NET.Clean.Tests.csproj b/src/Tests/Microsoft.NET.Clean.Tests/Microsoft.NET.Clean.Tests.csproj index 1ad72e6e3f9a..f5b0beec75d7 100644 --- a/src/Tests/Microsoft.NET.Clean.Tests/Microsoft.NET.Clean.Tests.csproj +++ b/src/Tests/Microsoft.NET.Clean.Tests/Microsoft.NET.Clean.Tests.csproj @@ -12,7 +12,7 @@ Tests\$(MSBuildProjectName) - + @@ -31,6 +31,6 @@ - + diff --git a/src/Tests/Microsoft.NET.Pack.Tests/Microsoft.NET.Pack.Tests.csproj b/src/Tests/Microsoft.NET.Pack.Tests/Microsoft.NET.Pack.Tests.csproj index 716eeb6e3d27..1d26c9d11f5f 100644 --- a/src/Tests/Microsoft.NET.Pack.Tests/Microsoft.NET.Pack.Tests.csproj +++ b/src/Tests/Microsoft.NET.Pack.Tests/Microsoft.NET.Pack.Tests.csproj @@ -12,7 +12,7 @@ Tests\$(MSBuildProjectName) - + @@ -31,6 +31,6 @@ - + diff --git a/src/Tests/Microsoft.NET.PerformanceTests/Microsoft.NET.PerformanceTests.csproj b/src/Tests/Microsoft.NET.PerformanceTests/Microsoft.NET.PerformanceTests.csproj index 2d4aaf090b00..a8fd3eb82517 100644 --- a/src/Tests/Microsoft.NET.PerformanceTests/Microsoft.NET.PerformanceTests.csproj +++ b/src/Tests/Microsoft.NET.PerformanceTests/Microsoft.NET.PerformanceTests.csproj @@ -13,7 +13,7 @@ Tests\$(MSBuildProjectName) - + @@ -34,6 +34,6 @@ - + diff --git a/src/Tests/Microsoft.NET.Publish.Tests/Microsoft.NET.Publish.Tests.csproj b/src/Tests/Microsoft.NET.Publish.Tests/Microsoft.NET.Publish.Tests.csproj index 227ae3981a70..16b9c3a2bd17 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/Microsoft.NET.Publish.Tests.csproj +++ b/src/Tests/Microsoft.NET.Publish.Tests/Microsoft.NET.Publish.Tests.csproj @@ -12,7 +12,7 @@ Tests\$(MSBuildProjectName) - + @@ -31,6 +31,6 @@ - + diff --git a/src/Tests/Microsoft.NET.Rebuild.Tests/Microsoft.NET.Rebuild.Tests.csproj b/src/Tests/Microsoft.NET.Rebuild.Tests/Microsoft.NET.Rebuild.Tests.csproj index 1ad72e6e3f9a..f5b0beec75d7 100644 --- a/src/Tests/Microsoft.NET.Rebuild.Tests/Microsoft.NET.Rebuild.Tests.csproj +++ b/src/Tests/Microsoft.NET.Rebuild.Tests/Microsoft.NET.Rebuild.Tests.csproj @@ -12,7 +12,7 @@ Tests\$(MSBuildProjectName) - + @@ -31,6 +31,6 @@ - + diff --git a/src/Tests/Microsoft.NET.Restore.Tests/Microsoft.NET.Restore.Tests.csproj b/src/Tests/Microsoft.NET.Restore.Tests/Microsoft.NET.Restore.Tests.csproj index 42880b2abaa6..b87fbc32672a 100644 --- a/src/Tests/Microsoft.NET.Restore.Tests/Microsoft.NET.Restore.Tests.csproj +++ b/src/Tests/Microsoft.NET.Restore.Tests/Microsoft.NET.Restore.Tests.csproj @@ -12,7 +12,7 @@ Tests\$(MSBuildProjectName) - + @@ -31,6 +31,6 @@ - + diff --git a/src/Tests/Microsoft.NET.TestFramework/Attributes/DotNetSdkVersionAttribute.cs b/src/Tests/Microsoft.NET.TestFramework/Attributes/DotNetSdkVersionAttribute.cs new file mode 100644 index 000000000000..0525f542510e --- /dev/null +++ b/src/Tests/Microsoft.NET.TestFramework/Attributes/DotNetSdkVersionAttribute.cs @@ -0,0 +1,19 @@ +using System; + +namespace Microsoft.NET.TestFramework +{ + /// + /// Attribute added to the test assembly during build. + /// Captures the version of dotnet SDK the build is targeting. + /// + [AttributeUsage(AttributeTargets.Assembly)] + public sealed class DotNetSdkVersionAttribute : Attribute + { + public string Version { get; } + + public DotNetSdkVersionAttribute(string version) + { + Version = version; + } + } +} diff --git a/src/Tests/Microsoft.NET.TestFramework/Microsoft.NET.TestFramework.csproj b/src/Tests/Microsoft.NET.TestFramework/Microsoft.NET.TestFramework.csproj index 89ce930caff0..3f19ec33539f 100644 --- a/src/Tests/Microsoft.NET.TestFramework/Microsoft.NET.TestFramework.csproj +++ b/src/Tests/Microsoft.NET.TestFramework/Microsoft.NET.TestFramework.csproj @@ -13,7 +13,7 @@ false - + @@ -47,6 +47,22 @@ - + + + <_DotNetSdkVersionFile>$(IntermediateOutputPath)\DotNetSdkVersion.g.cs + + + + + <_Attribute Include="Microsoft.NET.TestFramework.DotNetSdkVersionAttribute"> + <_Parameter1>$(NETCoreSdkVersion) + + + + + + + + diff --git a/src/Tests/Microsoft.NET.TestFramework/ToolsetInfo.cs b/src/Tests/Microsoft.NET.TestFramework/ToolsetInfo.cs index b53d8a8346a6..76edc357eec5 100644 --- a/src/Tests/Microsoft.NET.TestFramework/ToolsetInfo.cs +++ b/src/Tests/Microsoft.NET.TestFramework/ToolsetInfo.cs @@ -7,6 +7,7 @@ using Microsoft.DotNet.Cli.Utils; using Microsoft.NET.TestFramework.Commands; using System.Xml.Linq; +using System.Reflection; namespace Microsoft.NET.TestFramework { @@ -123,9 +124,7 @@ public static ToolsetInfo Create(string repoRoot, string repoArtifactsDir, strin } else if (repoRoot != null) { - var dotnetCliVersion = GetDotNetCliVersion(repoRoot); - - ret.DotNetHostPath = Path.Combine(repoArtifactsDir, ".dotnet", dotnetCliVersion, $"dotnet{Constants.ExeSuffix}"); + ret.DotNetHostPath = Path.Combine(repoRoot, ".dotnet", $"dotnet{Constants.ExeSuffix}"); } else { @@ -134,7 +133,7 @@ public static ToolsetInfo Create(string repoRoot, string repoArtifactsDir, strin if (repoRoot != null) { - ret.CliVersionForBundledVersions = GetDotNetCliVersion(repoRoot); + ret.CliVersionForBundledVersions = GetDotNetCliVersion(); ret.SdksPath = Path.Combine(repoArtifactsDir, configuration, "bin", "Sdks"); } @@ -150,22 +149,8 @@ public static ToolsetInfo Create(string repoRoot, string repoArtifactsDir, strin return ret; } - private static string GetDotNetCliVersion(string repoRoot) - { - var xml = XDocument.Load(Path.Combine(repoRoot, "build", "Versions.props")); - - foreach (var propertyGroup in xml.Descendants(XName.Get("PropertyGroup", "http://schemas.microsoft.com/developer/msbuild/2003"))) - { - var dotnetCliVersion = propertyGroup.Descendants(XName.Get("DotNetCliVersion", "http://schemas.microsoft.com/developer/msbuild/2003")); - - if (dotnetCliVersion.Any()) - { - return dotnetCliVersion.Single().Value; - } - } - - throw new Exception("Failed to locate the .NET CLI Version"); - } + private static string GetDotNetCliVersion() + => typeof(ToolsetInfo).Assembly.GetCustomAttribute().Version; private static string ResolveCommand(string command) { diff --git a/src/Tests/Microsoft.NET.ToolPack.Tests/Microsoft.NET.ToolPack.Tests.csproj b/src/Tests/Microsoft.NET.ToolPack.Tests/Microsoft.NET.ToolPack.Tests.csproj index 6ae52baac9d3..f4cef1311421 100644 --- a/src/Tests/Microsoft.NET.ToolPack.Tests/Microsoft.NET.ToolPack.Tests.csproj +++ b/src/Tests/Microsoft.NET.ToolPack.Tests/Microsoft.NET.ToolPack.Tests.csproj @@ -12,7 +12,7 @@ Tests\$(MSBuildProjectName) - + @@ -32,6 +32,6 @@ - +