Skip to content

Commit 64fcd93

Browse files
committed
Use Microsoft.DotNet.Arcade.Sdk
"Imitation is the sincerest form of flattery". Copy implementations from the Microsoft.DotNet.Arcade.Sdk, that is used by .NET projects https://github.com/dotnet/arcade/blob/master/Documentation/ArcadeSdk.md. This SDK offers a number features and provides a number of tasks such as clean, restore, build, rebuild, test, etc. Which both work from Visual Studio and command line. I decided against using the actual package for a number of reasons: 1. The package isn't published to nuget.org. 2. The package is being actively developed, and may be causing unnecessary overhead, if the package maintainers modify behaviours. 3. The package contains significantly more functionality, catering for the Microsoft .NET development process. 4. The package would require a significant number of adjustments to the project and its structure, to make use of it. Taking a limited subset of SDK provides a greater control over the executed targets and their configurations. Notable changes include: * Builds can now be initiated from commands line via `.\build.cmd`. There are a number of switches are/will be available such as: `-test`, `-clean`. * All artifacts are now redirected to .\artifacts folder, that includes binaries, obj, logs and test results. * All plugins binaries are places under .\artifacts\bin\GitExtensions\[configuration]\Plugins. This will allow for a more streamlined plugin development.
1 parent ab60322 commit 64fcd93

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1690
-66
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,5 @@ GitStatus.txt
7373
OpenCover.GitExtensions.xml
7474
tree.txt
7575
*.binlog
76+
artifacts/
77+
.tools/vswhere/

.nuget/NuGet.Config

-6
This file was deleted.

.nuget/NuGet.exe

-5.42 MB
Binary file not shown.

.nuget/packages.config

-6
This file was deleted.
File renamed without changes.
File renamed without changes.

.vscode/launch.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "PowerShell: Interactive Session",
9+
"type": "PowerShell",
10+
"request": "launch",
11+
"cwd": ""
12+
}
13+
]
14+
}

Build/Build.ps1

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
[CmdletBinding(PositionalBinding=$false)]
2+
Param(
3+
[string] $version,
4+
[string][Alias('c')] $configuration = "Debug",
5+
[string][Alias('v')] $verbosity = "minimal",
6+
[switch] $restore,
7+
[switch][Alias('b')]$build,
8+
[switch] $rebuild,
9+
[switch] $clean,
10+
[switch][Alias('t')] $test,
11+
[switch][Alias('bl')] $binaryLog,
12+
[string] $platform = $null,
13+
[switch] $help,
14+
[Parameter(ValueFromRemainingArguments=$true)][String[]]$properties
15+
)
16+
17+
. $PSScriptRoot\tools.ps1
18+
19+
# break on errors
20+
Set-StrictMode -Version Latest
21+
$ErrorActionPreference = "Stop"
22+
$PSDefaultParameterValues['*:ErrorAction'] = 'Stop'
23+
24+
$env:SKIP_PAUSE=1
25+
$TfmConfiguration = "$Configuration\net461";
26+
27+
28+
function Build {
29+
$toolsetBuildProj = Resolve-Path 'Build\tools\Build.proj'
30+
Write-Host $toolsetBuildProj
31+
32+
# build the solution
33+
$bl = if ($binaryLog) { "/bl:" + (Join-Path $LogDir "build.binlog") } else { "" }
34+
$platformArg = if ($platform) { "/p:Platform=$platform" } else { "" }
35+
36+
MSBuild $toolsetBuildProj `
37+
$bl `
38+
$platformArg `
39+
/p:Configuration=$configuration `
40+
/p:RepoRoot=$RepoRoot `
41+
/p:Restore=$restore `
42+
/p:Build=$build `
43+
/p:Rebuild=$rebuild `
44+
@properties;
45+
}
46+
47+
try {
48+
Push-Location $PSScriptRoot\..\
49+
50+
if ($clean) {
51+
if (Test-Path $ArtifactsDir) {
52+
Remove-Item -Recurse -Force $ArtifactsDir
53+
Write-Host 'Artifacts directory deleted.'
54+
}
55+
exit 0
56+
}
57+
58+
Build
59+
}
60+
catch {
61+
Write-Host $_.Exception -ForegroundColor Red
62+
return -1
63+
}
64+
finally {
65+
Pop-Location
66+
}

Build/pipeline-logging-functions.ps1

+234
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
# Source for this file was taken from https://github.com/microsoft/azure-pipelines-task-lib/blob/11c9439d4af17e6475d9fe058e6b2e03914d17e6/powershell/VstsTaskSdk/LoggingCommandFunctions.ps1 and modified.
2+
3+
# NOTE: You should not be calling these method directly as they are likely to change. Instead you should be calling the Write-Pipeline* functions defined in tools.ps1
4+
5+
$script:loggingCommandPrefix = '';
6+
$script:loggingCommandEscapeMappings = @( # TODO: WHAT ABOUT "="? WHAT ABOUT "%"?
7+
New-Object psobject -Property @{ Token = ';' ; Replacement = '%3B' }
8+
New-Object psobject -Property @{ Token = "`r" ; Replacement = '%0D' }
9+
New-Object psobject -Property @{ Token = "`n" ; Replacement = '%0A' }
10+
New-Object psobject -Property @{ Token = "]" ; Replacement = '%5D' }
11+
)
12+
# TODO: BUG: Escape % ???
13+
# TODO: Add test to verify don't need to escape "=".
14+
15+
function Write-PipelineTelemetryError {
16+
[CmdletBinding()]
17+
param(
18+
[Parameter(Mandatory = $true)]
19+
[string]$Category,
20+
[Parameter(Mandatory = $true)]
21+
[string]$Message,
22+
[Parameter(Mandatory = $false)]
23+
[string]$Type = 'error',
24+
[string]$ErrCode,
25+
[string]$SourcePath,
26+
[string]$LineNumber,
27+
[string]$ColumnNumber,
28+
[switch]$AsOutput)
29+
30+
$PSBoundParameters.Remove("Category") | Out-Null
31+
32+
$Message = "($Category) $Message"
33+
$PSBoundParameters.Remove("Message") | Out-Null
34+
$PSBoundParameters.Add("Message", $Message)
35+
36+
Write-PipelineTaskError @PSBoundParameters
37+
}
38+
39+
function Write-PipelineTaskError {
40+
[CmdletBinding()]
41+
param(
42+
[Parameter(Mandatory = $true)]
43+
[string]$Message,
44+
[Parameter(Mandatory = $false)]
45+
[string]$Type = 'error',
46+
[string]$ErrCode,
47+
[string]$SourcePath,
48+
[string]$LineNumber,
49+
[string]$ColumnNumber,
50+
[switch]$AsOutput)
51+
52+
if(!$ci) {
53+
if($Type -eq 'error') {
54+
Write-Host $Message -ForegroundColor Red
55+
return
56+
}
57+
elseif ($Type -eq 'warning') {
58+
Write-Host $Message -ForegroundColor Yellow
59+
return
60+
}
61+
}
62+
63+
if(($Type -ne 'error') -and ($Type -ne 'warning')) {
64+
Write-Host $Message
65+
return
66+
}
67+
if(-not $PSBoundParameters.ContainsKey('Type')) {
68+
$PSBoundParameters.Add('Type', 'error')
69+
}
70+
Write-LogIssue @PSBoundParameters
71+
}
72+
73+
function Write-PipelineSetVariable {
74+
[CmdletBinding()]
75+
param(
76+
[Parameter(Mandatory = $true)]
77+
[string]$Name,
78+
[string]$Value,
79+
[switch]$Secret,
80+
[switch]$AsOutput,
81+
[bool]$IsMultiJobVariable=$true)
82+
83+
if($ci) {
84+
Write-LoggingCommand -Area 'task' -Event 'setvariable' -Data $Value -Properties @{
85+
'variable' = $Name
86+
'isSecret' = $Secret
87+
'isOutput' = $IsMultiJobVariable
88+
} -AsOutput:$AsOutput
89+
}
90+
}
91+
92+
function Write-PipelinePrependPath {
93+
[CmdletBinding()]
94+
param(
95+
[Parameter(Mandatory=$true)]
96+
[string]$Path,
97+
[switch]$AsOutput)
98+
if($ci) {
99+
Write-LoggingCommand -Area 'task' -Event 'prependpath' -Data $Path -AsOutput:$AsOutput
100+
}
101+
}
102+
103+
<########################################
104+
# Private functions.
105+
########################################>
106+
function Format-LoggingCommandData {
107+
[CmdletBinding()]
108+
param([string]$Value, [switch]$Reverse)
109+
110+
if (!$Value) {
111+
return ''
112+
}
113+
114+
if (!$Reverse) {
115+
foreach ($mapping in $script:loggingCommandEscapeMappings) {
116+
$Value = $Value.Replace($mapping.Token, $mapping.Replacement)
117+
}
118+
} else {
119+
for ($i = $script:loggingCommandEscapeMappings.Length - 1 ; $i -ge 0 ; $i--) {
120+
$mapping = $script:loggingCommandEscapeMappings[$i]
121+
$Value = $Value.Replace($mapping.Replacement, $mapping.Token)
122+
}
123+
}
124+
125+
return $Value
126+
}
127+
128+
function Format-LoggingCommand {
129+
[CmdletBinding()]
130+
param(
131+
[Parameter(Mandatory = $true)]
132+
[string]$Area,
133+
[Parameter(Mandatory = $true)]
134+
[string]$Event,
135+
[string]$Data,
136+
[hashtable]$Properties)
137+
138+
# Append the preamble.
139+
[System.Text.StringBuilder]$sb = New-Object -TypeName System.Text.StringBuilder
140+
$null = $sb.Append($script:loggingCommandPrefix).Append($Area).Append('.').Append($Event)
141+
142+
# Append the properties.
143+
if ($Properties) {
144+
$first = $true
145+
foreach ($key in $Properties.Keys) {
146+
[string]$value = Format-LoggingCommandData $Properties[$key]
147+
if ($value) {
148+
if ($first) {
149+
$null = $sb.Append(' ')
150+
$first = $false
151+
} else {
152+
$null = $sb.Append(';')
153+
}
154+
155+
$null = $sb.Append("$key=$value")
156+
}
157+
}
158+
}
159+
160+
# Append the tail and output the value.
161+
$Data = Format-LoggingCommandData $Data
162+
$sb.Append($Data).ToString()
163+
}
164+
165+
function Write-LoggingCommand {
166+
[CmdletBinding(DefaultParameterSetName = 'Parameters')]
167+
param(
168+
[Parameter(Mandatory = $true, ParameterSetName = 'Parameters')]
169+
[string]$Area,
170+
[Parameter(Mandatory = $true, ParameterSetName = 'Parameters')]
171+
[string]$Event,
172+
[Parameter(ParameterSetName = 'Parameters')]
173+
[string]$Data,
174+
[Parameter(ParameterSetName = 'Parameters')]
175+
[hashtable]$Properties,
176+
[Parameter(Mandatory = $true, ParameterSetName = 'Object')]
177+
$Command,
178+
[switch]$AsOutput)
179+
180+
if ($PSCmdlet.ParameterSetName -eq 'Object') {
181+
Write-LoggingCommand -Area $Command.Area -Event $Command.Event -Data $Command.Data -Properties $Command.Properties -AsOutput:$AsOutput
182+
return
183+
}
184+
185+
$command = Format-LoggingCommand -Area $Area -Event $Event -Data $Data -Properties $Properties
186+
if ($AsOutput) {
187+
$command
188+
} else {
189+
Write-Host $command
190+
}
191+
}
192+
193+
function Write-LogIssue {
194+
[CmdletBinding()]
195+
param(
196+
[ValidateSet('warning', 'error')]
197+
[Parameter(Mandatory = $true)]
198+
[string]$Type,
199+
[string]$Message,
200+
[string]$ErrCode,
201+
[string]$SourcePath,
202+
[string]$LineNumber,
203+
[string]$ColumnNumber,
204+
[switch]$AsOutput)
205+
206+
$command = Format-LoggingCommand -Area 'task' -Event 'logissue' -Data $Message -Properties @{
207+
'type' = $Type
208+
'code' = $ErrCode
209+
'sourcepath' = $SourcePath
210+
'linenumber' = $LineNumber
211+
'columnnumber' = $ColumnNumber
212+
}
213+
if ($AsOutput) {
214+
return $command
215+
}
216+
217+
if ($Type -eq 'error') {
218+
$foregroundColor = $host.PrivateData.ErrorForegroundColor
219+
$backgroundColor = $host.PrivateData.ErrorBackgroundColor
220+
if ($foregroundColor -isnot [System.ConsoleColor] -or $backgroundColor -isnot [System.ConsoleColor]) {
221+
$foregroundColor = [System.ConsoleColor]::Red
222+
$backgroundColor = [System.ConsoleColor]::Black
223+
}
224+
} else {
225+
$foregroundColor = $host.PrivateData.WarningForegroundColor
226+
$backgroundColor = $host.PrivateData.WarningBackgroundColor
227+
if ($foregroundColor -isnot [System.ConsoleColor] -or $backgroundColor -isnot [System.ConsoleColor]) {
228+
$foregroundColor = [System.ConsoleColor]::Yellow
229+
$backgroundColor = [System.ConsoleColor]::Black
230+
}
231+
}
232+
233+
Write-Host $command -ForegroundColor $foregroundColor -BackgroundColor $backgroundColor
234+
}

Build/sdk/Sdk.props

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
3+
<Project>
4+
<PropertyGroup>
5+
<!--
6+
When the bootstrapper script initializes a repo it restores an empty project that imports the toolset SDK.
7+
It invokes WriteToolsetLocation target with __ToolsetLocationOutputFile set to the path where the location of
8+
SDK Build.proj entry point is to be stored. Suppress all other imports for that project.
9+
-->
10+
<_SuppressSdkImports>false</_SuppressSdkImports>
11+
<_SuppressSdkImports Condition="'$(__ToolsetLocationOutputFile)' != ''">true</_SuppressSdkImports>
12+
</PropertyGroup>
13+
14+
<Import Project="..\tools\Settings.props" Condition="!$(_SuppressSdkImports)" />
15+
16+
</Project>

Build/sdk/Sdk.targets

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
3+
<Project>
4+
<!--
5+
If a project specifies ExcludeFromSourceBuild=true during a source build suppress all targets and emulate a no-op
6+
(empty common targets like Restore, Build, Pack, etc.).
7+
-->
8+
<PropertyGroup>
9+
<_SuppressAllTargets>false</_SuppressAllTargets>
10+
<_SuppressAllTargets Condition="'$(DotNetBuildFromSource)' == 'true' and '$(ExcludeFromSourceBuild)' == 'true'">true</_SuppressAllTargets>
11+
</PropertyGroup>
12+
13+
<!--
14+
Output the location of the Build.proj so that the build driver can find where it was restored.
15+
Ideally we would have msbuild API to do that for an SDK: https://github.com/Microsoft/msbuild/issues/2992
16+
-->
17+
<Target Name="__WriteToolsetLocation" Outputs="$(__ToolsetLocationOutputFile)" Condition="'$(__ToolsetLocationOutputFile)' != ''">
18+
<WriteLinesToFile File="$(__ToolsetLocationOutputFile)" Lines="$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\tools\Build.proj'))" Overwrite="true"/>
19+
<ItemGroup>
20+
<FileWrites Include="$(__ToolsetLocationOutputFile)" />
21+
</ItemGroup>
22+
</Target>
23+
24+
<Import Project="..\tools\Imports.targets" Condition="!$(_SuppressSdkImports) and !$(_SuppressAllTargets)" />
25+
<Import Project="..\tools\Empty.targets" Condition="!$(_SuppressSdkImports) and $(_SuppressAllTargets)"/>
26+
</Project>

0 commit comments

Comments
 (0)