Skip to content
Draft
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
2 changes: 1 addition & 1 deletion eng/common/sdk-task.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $warnAsError = if ($noWarnAsError) { $false } else { $true }

function Print-Usage() {
Write-Host "Common settings:"
Write-Host " -task <value> Name of Arcade task (name of a project in SdkTasks directory of the Arcade SDK package)"
Write-Host " -task <value> Name of Arcade task (name of a project in toolset directory of the Arcade SDK package)"
Write-Host " -restore Restore dependencies"
Write-Host " -verbosity <value> Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]"
Write-Host " -help Print help and exit"
Expand Down
2 changes: 1 addition & 1 deletion eng/common/sdk-task.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

show_usage() {
echo "Common settings:"
echo " --task <value> Name of Arcade task (name of a project in SdkTasks directory of the Arcade SDK package)"
echo " --task <value> Name of Arcade task (name of a project in toolset directory of the Arcade SDK package)"
echo " --restore Restore dependencies"
echo " --verbosity <value> Msbuild verbosity: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]"
echo " --help Print help and exit"
Expand Down
96 changes: 79 additions & 17 deletions eng/common/tools.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,6 @@ function LocateVisualStudio([object]$vsRequirements = $null){
if (Get-Member -InputObject $GlobalJson.tools -Name 'vswhere') {
$vswhereVersion = $GlobalJson.tools.vswhere
} else {
# keep this in sync with the VSWhereVersion in DefaultVersions.props
$vswhereVersion = '3.1.7'
}

Expand Down Expand Up @@ -611,7 +610,17 @@ function GetNuGetPackageCachePath() {

# Returns a full path to an Arcade SDK task project file.
function GetSdkTaskProject([string]$taskName) {
return Join-Path (Split-Path (InitializeToolset) -Parent) "SdkTasks\$taskName.proj"
$toolsetDir = Split-Path (InitializeToolset) -Parent
$proj = Join-Path $toolsetDir "$taskName.proj"
if (Test-Path $proj) {
return $proj
}
# TODO: Remove this fallback once all supported versions use the new layout.
$legacyProj = Join-Path $toolsetDir "SdkTasks\$taskName.proj"
if (Test-Path $legacyProj) {
return $legacyProj
}
throw "Unable to find $taskName.proj in toolset at: $toolsetDir"
}

function InitializeNativeTools() {
Expand Down Expand Up @@ -648,35 +657,54 @@ function InitializeToolset() {
$nugetCache = GetNuGetPackageCachePath

$toolsetVersion = Read-ArcadeSdkVersion
$toolsetLocationFile = Join-Path $ToolsetDir "$toolsetVersion.txt"
$toolsetToolsDir = Join-Path $ToolsetDir $toolsetVersion

if (Test-Path $toolsetLocationFile) {
$path = Get-Content $toolsetLocationFile -TotalCount 1
if (Test-Path $path) {
return $global:_InitializeToolset = $path
}
# Check if the toolset has already been extracted
$toolsetBuildProj = $null
$buildProjPath = Join-Path $toolsetToolsDir 'Build.proj'

if (Test-Path $buildProjPath) {
$toolsetBuildProj = $buildProjPath
}

if ($toolsetBuildProj -ne $null) {
return $global:_InitializeToolset = $toolsetBuildProj
}

if (-not $restore) {
Write-PipelineTelemetryError -Category 'InitializeToolset' -Message "Toolset version $toolsetVersion has not been restored."
ExitWithExitCode 1
}

$buildTool = InitializeBuildTool
DotNet package download "Microsoft.DotNet.Arcade.Sdk@$toolsetVersion" --prerelease --output "$nugetCache"

$proj = Join-Path $ToolsetDir 'restore.proj'
$bl = if ($binaryLog) { '/bl:' + (Join-Path $LogDir 'ToolsetRestore.binlog') } else { '' }
$packageDir = Join-Path $nugetCache (Join-Path 'microsoft.dotnet.arcade.sdk' $toolsetVersion)
$packageToolsetDir = Join-Path $packageDir 'toolset'
$packageToolsDir = Join-Path $packageDir 'tools'

# TODO: Remove the tools/ check once all supported versions have the toolset folder.
if (!(Test-Path $packageToolsetDir) -and !(Test-Path $packageToolsDir)) {
Write-PipelineTelemetryError -Category 'InitializeToolset' -Message "Arcade SDK package does not contain a toolset or tools folder: $packageDir"
ExitWithExitCode 3
}

'<Project Sdk="Microsoft.DotNet.Arcade.Sdk"/>' | Set-Content $proj
New-Item -ItemType Directory -Path $toolsetToolsDir -Force | Out-Null

MSBuild-Core $proj $bl /t:__WriteToolsetLocation /clp:ErrorsOnly`;NoSummary /p:__ToolsetLocationOutputFile=$toolsetLocationFile
# Copy toolset if present at the package root (new layout), otherwise fall back to tools
if (Test-Path $packageToolsetDir) {
Copy-Item -Path "$packageToolsetDir\*" -Destination $toolsetToolsDir -Recurse -Force
} else {
# TODO: Remove this fallback once all supported versions have the toolset folder.
Copy-Item -Path "$packageToolsDir\*" -Destination $toolsetToolsDir -Recurse -Force
}

$path = Get-Content $toolsetLocationFile -Encoding UTF8 -TotalCount 1
if (!(Test-Path $path)) {
throw "Invalid toolset path: $path"
if (Test-Path $buildProjPath) {
$toolsetBuildProj = $buildProjPath
} else {
throw "Unable to find Build.proj in toolset at: $toolsetToolsDir"
}

return $global:_InitializeToolset = $path
return $global:_InitializeToolset = $toolsetBuildProj
}

function ExitWithExitCode([int] $exitCode) {
Expand Down Expand Up @@ -737,6 +765,40 @@ function MSBuild() {
MSBuild-Core @args
}

#
# Executes a dotnet command with arguments passed to the function.
# Terminates the script if the command fails.
#
function DotNet() {
$dotnetRoot = InitializeDotNetCli -install:$restore
$dotnetPath = Join-Path $dotnetRoot (GetExecutableFileName 'dotnet')

$cmdArgs = ""
foreach ($arg in $args) {
if ($null -ne $arg -and $arg.Trim() -ne "") {
if ($arg.EndsWith('\')) {
$arg = $arg + "\"
}
$cmdArgs += " `"$arg`""
}
}

$env:ARCADE_BUILD_TOOL_COMMAND = "`"$dotnetPath`" $cmdArgs"

$exitCode = Exec-Process $dotnetPath $cmdArgs

if ($exitCode -ne 0) {
Write-Host "dotnet command failed with exit code $exitCode. Check errors above." -ForegroundColor Red

if ($ci -and $env:SYSTEM_TEAMPROJECT -ne $null -and !$fromVMR) {
Write-PipelineSetResult -Result "Failed" -Message "dotnet command execution failed."
ExitWithExitCode 0
} else {
ExitWithExitCode $exitCode
}
}
}

#
# Executes msbuild (or 'dotnet msbuild') with arguments passed to the function.
# The arguments are automatically quoted.
Expand Down
85 changes: 66 additions & 19 deletions eng/common/tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -407,36 +407,49 @@ function InitializeToolset {
ReadGlobalVersion "Microsoft.DotNet.Arcade.Sdk"

local toolset_version=$_ReadGlobalVersion
local toolset_location_file="$toolset_dir/$toolset_version.txt"
local toolset_tools_dir="$toolset_dir/$toolset_version"

if [[ -a "$toolset_location_file" ]]; then
local path=`cat "$toolset_location_file"`
if [[ -a "$path" ]]; then
# return value
_InitializeToolset="$path"
return
fi
# Check if the toolset has already been extracted
local toolset_build_proj=""
if [[ -a "$toolset_tools_dir/Build.proj" ]]; then
toolset_build_proj="$toolset_tools_dir/Build.proj"
fi

if [[ -n "$toolset_build_proj" ]]; then
# return value
_InitializeToolset="$toolset_build_proj"
return
fi

if [[ "$restore" != true ]]; then
Write-PipelineTelemetryError -category 'InitializeToolset' "Toolset version $toolset_version has not been restored."
ExitWithExitCode 2
fi

local proj="$toolset_dir/restore.proj"
DotNet package download "Microsoft.DotNet.Arcade.Sdk@$toolset_version" --prerelease --output "$_GetNuGetPackageCachePath"

local package_dir="$_GetNuGetPackageCachePath/microsoft.dotnet.arcade.sdk/$toolset_version"

local bl=""
if [[ "$binary_log" == true ]]; then
bl="/bl:$log_dir/ToolsetRestore.binlog"
# TODO: Remove the tools/ check once all supported versions have the toolset folder.
if [[ ! -d "$package_dir/toolset" && ! -d "$package_dir/tools" ]]; then
Write-PipelineTelemetryError -category 'InitializeToolset' "Arcade SDK package does not contain a toolset or tools folder: $package_dir"
ExitWithExitCode 3
fi

echo '<Project Sdk="Microsoft.DotNet.Arcade.Sdk"/>' > "$proj"
MSBuild-Core "$proj" $bl /t:__WriteToolsetLocation /clp:ErrorsOnly\;NoSummary /p:__ToolsetLocationOutputFile="$toolset_location_file"
mkdir -p "$toolset_tools_dir"

local toolset_build_proj=`cat "$toolset_location_file"`
# Copy toolset if present at the package root (new layout), otherwise fall back to tools
if [[ -d "$package_dir/toolset" ]]; then
cp -r "$package_dir/toolset/." "$toolset_tools_dir"
else
# TODO: Remove this fallback once all supported versions have the toolset folder.
cp -r "$package_dir/tools/." "$toolset_tools_dir"
fi

if [[ ! -a "$toolset_build_proj" ]]; then
Write-PipelineTelemetryError -category 'Build' "Invalid toolset path: $toolset_build_proj"
if [[ -a "$toolset_tools_dir/Build.proj" ]]; then
toolset_build_proj="$toolset_tools_dir/Build.proj"
else
Write-PipelineTelemetryError -category 'Build' "Unable to find Build.proj in toolset at: $toolset_tools_dir"
ExitWithExitCode 3
fi

Expand All @@ -458,6 +471,26 @@ function StopProcesses {
return 0
}

function DotNet {
InitializeDotNetCli $restore

local dotnet_path="$_InitializeDotNetCli/dotnet"

export ARCADE_BUILD_TOOL_COMMAND="$dotnet_path $@"

"$dotnet_path" "$@" || {
local exit_code=$?
echo "dotnet command failed with exit code $exit_code. Check errors above."

if [[ "$ci" == true && -n ${SYSTEM_TEAMPROJECT:-} && "$from_vmr" != true ]]; then
Write-PipelineSetResult -result "Failed" -message "dotnet command execution failed."
ExitWithExitCode 0
else
ExitWithExitCode $exit_code
fi
}
}

function MSBuild {
local args=( "$@" )
if [[ "$pipelines_log" == true ]]; then
Expand Down Expand Up @@ -555,8 +588,22 @@ function GetDarc {

# Returns a full path to an Arcade SDK task project file.
function GetSdkTaskProject {
taskName=$1
echo "$(dirname $_InitializeToolset)/SdkTasks/$taskName.proj"
local taskName=$1
local toolsetDir
toolsetDir="$(dirname "$_InitializeToolset")"
local proj="$toolsetDir/$taskName.proj"
if [[ -a "$proj" ]]; then
echo "$proj"
return
fi
# TODO: Remove this fallback once all supported versions use the new layout.
local legacyProj="$toolsetDir/SdkTasks/$taskName.proj"
if [[ -a "$legacyProj" ]]; then
echo "$legacyProj"
return
fi
Write-PipelineTelemetryError -category 'Build' "Unable to find $taskName.proj in toolset at: $toolsetDir"
ExitWithExitCode 3
}

ResolvePath "${BASH_SOURCE[0]}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<None Include="$(_GeneratedVersionFilePath)"
Pack="true"
PackagePath="tools\DefaultVersions.Generated.props" />
<None Include="toolset/**/*.*"
Pack="true"
PackagePath="toolset/%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
Expand Down
12 changes: 1 addition & 11 deletions src/Microsoft.DotNet.Arcade.Sdk/sdk/Sdk.props
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. -->
<Project>

<PropertyGroup>
<!--
When the bootstrapper script initializes a repo it restores an empty project that imports the toolset SDK.
It invokes WriteToolsetLocation target with __ToolsetLocationOutputFile set to the path where the location of
SDK Build.proj entry point is to be stored. Suppress all other imports for that project.
-->
<_SuppressSdkImports>false</_SuppressSdkImports>
<_SuppressSdkImports Condition="'$(__ToolsetLocationOutputFile)' != ''">true</_SuppressSdkImports>
</PropertyGroup>

<Import Project="..\tools\Settings.props" Condition="!$(_SuppressSdkImports)" />
<Import Project="..\tools\Settings.props" />

</Project>
19 changes: 4 additions & 15 deletions src/Microsoft.DotNet.Arcade.Sdk/sdk/Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,10 @@
<_BeforeCommonTargetsHookUsed Condition="'$(_ArcadeBeforeCommonTargetsImported)' != 'true'">false</_BeforeCommonTargetsHookUsed>
</PropertyGroup>

<Import Project="..\tools\BeforeCommonTargets.targets" Condition="'$(_SuppressSdkImports)' != 'true' and '$(_ArcadeBeforeCommonTargetsImported)' != 'true' and '$(IsCrossTargetingBuild)' != 'true'"/>
<Import Project="..\tools\BeforeCommonTargets.CrossTargeting.targets" Condition="'$(_SuppressSdkImports)' != 'true' and '$(_ArcadeBeforeCommonTargetsImported)' != 'true' and '$(IsCrossTargetingBuild)' == 'true'"/>
<Import Project="..\tools\BeforeCommonTargets.targets" Condition="'$(_ArcadeBeforeCommonTargetsImported)' != 'true' and '$(IsCrossTargetingBuild)' != 'true'"/>
<Import Project="..\tools\BeforeCommonTargets.CrossTargeting.targets" Condition="'$(_ArcadeBeforeCommonTargetsImported)' != 'true' and '$(IsCrossTargetingBuild)' == 'true'"/>

<!--
Output the location of the Build.proj so that the build driver can find where it was restored.
Ideally we would have msbuild API to do that for an SDK: https://github.com/Microsoft/msbuild/issues/2992
-->
<Target Name="__WriteToolsetLocation" Outputs="$(__ToolsetLocationOutputFile)" Condition="'$(__ToolsetLocationOutputFile)' != ''">
<WriteLinesToFile File="$(__ToolsetLocationOutputFile)" Lines="$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\tools\Build.proj'))" Overwrite="true"/>
<ItemGroup>
<FileWrites Include="$(__ToolsetLocationOutputFile)" />
</ItemGroup>
</Target>

<Import Project="..\tools\Imports.targets" Condition="'$(_SuppressSdkImports)' != 'true' and '$(_SuppressAllTargets)' != 'true'" />
<Import Project="..\tools\Empty.targets" Condition="'$(_SuppressSdkImports)' != 'true' and '$(_SuppressAllTargets)' == 'true'" />
<Import Project="..\tools\Imports.targets" Condition="'$(_SuppressAllTargets)' != 'true' or '$(_SuppressSdkImports)' == 'false'" />
<Import Project="..\tools\Empty.targets" Condition="'$(_SuppressAllTargets)' == 'true'" />

</Project>
9 changes: 0 additions & 9 deletions src/Microsoft.DotNet.Arcade.Sdk/tools/BuildStep.props

This file was deleted.

19 changes: 19 additions & 0 deletions src/Microsoft.DotNet.Arcade.Sdk/tools/BuildTasks.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,23 @@
<ArcadeSdkBuildTasksAssembly>$(MSBuildThisFileDirectory)net\Microsoft.DotNet.Arcade.Sdk.dll</ArcadeSdkBuildTasksAssembly>
</PropertyGroup>

<UsingTask TaskName="Microsoft.DotNet.Arcade.Sdk.CalculateAssemblyAndFileVersions" AssemblyFile="$(ArcadeSdkBuildTasksAssembly)" Runtime="NET" />
<UsingTask TaskName="Microsoft.DotNet.Arcade.Sdk.CheckRequiredDotNetVersion" AssemblyFile="$(ArcadeSdkBuildTasksAssembly)" Runtime="NET" />
<UsingTask TaskName="Microsoft.DotNet.Arcade.Sdk.CompareVersions" AssemblyFile="$(ArcadeSdkBuildTasksAssembly)" Runtime="NET" />
<UsingTask TaskName="Microsoft.DotNet.Arcade.Sdk.DownloadFile" AssemblyFile="$(ArcadeSdkBuildTasksAssembly)" Runtime="NET" />
<UsingTask TaskName="Microsoft.DotNet.Arcade.Sdk.ExtractNgenMethodList" AssemblyFile="$(ArcadeSdkBuildTasksAssembly)" Runtime="NET" />
<UsingTask TaskName="Microsoft.DotNet.Arcade.Sdk.GenerateChecksums" AssemblyFile="$(ArcadeSdkBuildTasksAssembly)" Runtime="NET" />
<UsingTask TaskName="Microsoft.DotNet.Arcade.Sdk.GenerateResxSource" AssemblyFile="$(ArcadeSdkBuildTasksAssembly)" Runtime="NET" />
<UsingTask TaskName="Microsoft.DotNet.Arcade.Sdk.GenerateSourcePackageSourceLinkTargetsFile" AssemblyFile="$(ArcadeSdkBuildTasksAssembly)" Runtime="NET" />
<UsingTask TaskName="Microsoft.DotNet.Arcade.Sdk.GetAssemblyFullName" AssemblyFile="$(ArcadeSdkBuildTasksAssembly)" Runtime="NET" />
<UsingTask TaskName="Microsoft.DotNet.Arcade.Sdk.GetLicenseFilePath" AssemblyFile="$(ArcadeSdkBuildTasksAssembly)" Runtime="NET" />
<UsingTask TaskName="Microsoft.DotNet.Arcade.Sdk.GroupItemsBy" AssemblyFile="$(ArcadeSdkBuildTasksAssembly)" Runtime="NET" />
<UsingTask TaskName="Microsoft.DotNet.Arcade.Sdk.InstallDotNetCore" AssemblyFile="$(ArcadeSdkBuildTasksAssembly)" Runtime="NET" />
<UsingTask TaskName="Microsoft.DotNet.Arcade.Sdk.LocateDotNet" AssemblyFile="$(ArcadeSdkBuildTasksAssembly)" Runtime="NET" />
<UsingTask TaskName="Microsoft.DotNet.Arcade.Sdk.SaveItems" AssemblyFile="$(ArcadeSdkBuildTasksAssembly)" Runtime="NET" />
<UsingTask TaskName="Microsoft.DotNet.Arcade.Sdk.SetCorFlags" AssemblyFile="$(ArcadeSdkBuildTasksAssembly)" Runtime="NET" />
<UsingTask TaskName="Microsoft.DotNet.Arcade.Sdk.SingleError" AssemblyFile="$(ArcadeSdkBuildTasksAssembly)" Runtime="NET" />
<UsingTask TaskName="Microsoft.DotNet.Arcade.Sdk.Unsign" AssemblyFile="$(ArcadeSdkBuildTasksAssembly)" Runtime="NET" />
<UsingTask TaskName="Microsoft.DotNet.Arcade.Sdk.ValidateLicense" AssemblyFile="$(ArcadeSdkBuildTasksAssembly)" Runtime="NET" />

</Project>
5 changes: 3 additions & 2 deletions src/Microsoft.DotNet.Arcade.Sdk/tools/DefaultVersions.props
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@
<MicrosoftDotNetBuildTasksInstallersVersion Condition="'$(MicrosoftDotNetBuildTasksInstallersVersion)' == ''">$(ArcadeSdkVersion)</MicrosoftDotNetBuildTasksInstallersVersion>
<NUnitVersion Condition="'$(NUnitVersion)' == ''">3.12.0</NUnitVersion>
<NUnit3TestAdapterVersion Condition="'$(NUnit3TestAdapterVersion)' == ''">3.15.1</NUnit3TestAdapterVersion>
<!-- keep this in sync with $vswhereVersion in eng/common/tools.ps1 -->
<VSWhereVersion Condition="'$(VSWhereVersion)' == ''">3.1.7</VSWhereVersion>
<SNVersion Condition="'$(SNVersion)' == ''">1.0.0</SNVersion>
<MicrosoftDotNetBuildTasksVisualStudioVersion Condition="'$(MicrosoftDotNetBuildTasksVisualStudioVersion)' == ''">$(ArcadeSdkVersion)</MicrosoftDotNetBuildTasksVisualStudioVersion>
<MicrosoftDotNetSourceBuildTasksVersion Condition="'$(MicrosoftDotNetSourceBuildTasksVersion)' == ''">$(ArcadeSdkVersion)</MicrosoftDotNetSourceBuildTasksVersion>
Expand All @@ -105,6 +103,9 @@
<MicrosoftVisualStudioEngMicroBuildPluginsSwixBuildVersion Condition="'$(MicrosoftVisualStudioEngMicroBuildPluginsSwixBuildVersion)' == ''">1.1.286</MicrosoftVisualStudioEngMicroBuildPluginsSwixBuildVersion>
<MicrosoftSignedWixVersion Condition="'$(MicrosoftSignedWixVersion)' == ''">3.14.1-11027.2914512</MicrosoftSignedWixVersion>
<MicrosoftWixToolsetSdkVersion Condition="'$(MicrosoftWixToolsetSdkVersion)' == ''">5.0.2-dotnet.2811440</MicrosoftWixToolsetSdkVersion>

<MicrosoftDotNetBaselinesTasksVersion Condition="'$(MicrosoftDotNetBaselinesTasksVersion)' == ''">$(ArcadeSdkVersion)</MicrosoftDotNetBaselinesTasksVersion>
<MicrosoftDotNetSignCheckTaskVersion Condition="'$(MicrosoftDotNetSignCheckTaskVersion)' == ''">$(ArcadeSdkVersion)</MicrosoftDotNetSignCheckTaskVersion>
</PropertyGroup>

<!-- RestoreSources overrides - defines DotNetRestoreSources variable if available -->
Expand Down
11 changes: 0 additions & 11 deletions src/Microsoft.DotNet.Arcade.Sdk/tools/Directory.Build.props

This file was deleted.

Loading
Loading