Skip to content

Commit f95e579

Browse files
committed
Pin the .NET Core SDK
1 parent 7cdddd2 commit f95e579

8 files changed

+287
-12
lines changed

.travis.yml

+17-6
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,24 @@
22
# see travis-ci.org for details
33

44
language: csharp
5-
dist: xenial
6-
dotnet: 2.1.802
75
mono: none
8-
osx_image: xcode8.3
96

10-
os:
11-
- osx
12-
- linux
7+
matrix:
8+
include:
9+
- os: linux
10+
dist: xenial
11+
before_install:
12+
- |
13+
wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb
14+
sudo dpkg -i packages-microsoft-prod.deb
15+
sudo apt-get update
16+
sudo apt-get install -y powershell
17+
- os: osx
18+
osx_image: xcode8.3
19+
before_install:
20+
- brew update # This is necessary to get pwsh 6.2 instead of some 6.0-preview that isn't named `pwsh`
21+
- brew cask install powershell
22+
fast_finish: true
1323

1424
before_install:
1525
- date -u
@@ -18,6 +28,7 @@ before_install:
1828

1929
install:
2030
- git fetch --unshallow
31+
- pwsh ./tools/Install-DotNetSdk.ps1 ; export PATH=~/.dotnet:$PATH
2132

2233
# Build libgit2, LibGit2Sharp and run the tests
2334
script:

CONTRIBUTING.md

+11-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ We love Pull Requests! Your contributions help make LibGit2Sharp great.
44

55
## Getting Started
66

7-
So you want to contribute to LibGit2Sharp. Great! Contributions take many forms from
7+
So you want to contribute to LibGit2Sharp. Great! Contributions take many forms from
88
submitting issues, writing documentation, to making code changes. We welcome it all.
99

1010
But first things first...
@@ -14,18 +14,25 @@ But first things first...
1414
* Clearly describe the issue including steps to reproduce when it is a bug.
1515
* Make sure you fill in the earliest version that you know has the issue.
1616
* Fork the repository on GitHub, then clone it using your favorite Git client.
17-
* Make sure the project builds and all tests pass on your machine by running
17+
* Make sure the project builds and all tests pass on your machine by running
1818
the `buildandtest.cmd` script on Windows or `buildandtest.sh` on Linux/Mac.
1919

2020
## LibGit2
2121

2222
LibGit2Sharp brings all the might and speed of libgit2, a native Git implementation, to the managed world of .Net and Mono.
23-
LibGit2 is a git submodule referencing the [libgit2 project](https://github.com/libgit2/libgit2). To learn more about
23+
LibGit2 is a git submodule referencing the [libgit2 project](https://github.com/libgit2/libgit2). To learn more about
2424
submodules read [here](http://git-scm.com/book/en/v2/Git-Tools-Submodules).
2525
To build libgit2 see [here](https://github.com/libgit2/libgit2sharp/wiki/How-to-build-x64-libgit2-and-LibGit2Sharp).
2626

2727
## Making Changes
2828

29+
Make sure you have the required .NET Core SDK and runtimes installed.
30+
The easiest way to do this is run our `tools\Install-DotNetSdk.ps1` script.
31+
Using the `-InstallLocality Machine` switch requires elevation but ensures
32+
that Visual Studio will be able to load the solution even when launched from a shortcut.
33+
34+
Then proceed to:
35+
2936
* Create a topic branch off master (don't work directly on master).
3037
* Implement your feature or fix your bug. Please following existing coding styles and do not introduce new ones.
3138
* Make atomic, focused commits with good commit messages.
@@ -42,7 +49,7 @@ Some things that will increase the chance that your pull request is accepted.
4249
* Following existing code conventions.
4350
* Including unit tests that would otherwise fail without the patch, but pass after applying it.
4451
* Updating the documentation and tests that are affected by the contribution.
45-
* If code from elsewhere is used, proper credit and a link to the source should exist in the code comments.
52+
* If code from elsewhere is used, proper credit and a link to the source should exist in the code comments.
4653
Then licensing issues can be checked against LibGit2Sharp's very permissive MIT based open source license.
4754
* Having a configured git client that converts line endings to LF. [See here.](https://help.github.com/articles/dealing-with-line-endings/).
4855
# Additional Resources

appveyor.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
version: '{build}'
22

3-
os: Visual Studio 2017
3+
os: Visual Studio 2019
44

55
branches:
66
only:
@@ -68,6 +68,8 @@ install:
6868
cinst curl -y
6969
}
7070
71+
./tools/Install-DotNetSdk.ps1
72+
7173
before_build:
7274
- ps: |
7375
msbuild "$Env:APPVEYOR_BUILD_FOLDER\LibGit2Sharp.sln" `

azure-pipelines.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,25 @@ variables:
1010
jobs:
1111
- job: Windows
1212
pool:
13-
vmImage: 'VS2017-Win2016'
13+
vmImage: 'windows-2019'
1414
steps:
15+
- pwsh: ./tools/Install-DotNetSdk.ps1
16+
displayName: Installing .NET Core SDK and runtimes
1517
- script: buildandtest.cmd
18+
displayName: Build and test
1619
- job: Linux
1720
pool:
1821
vmImage: 'Ubuntu 16.04'
1922
steps:
23+
- pwsh: ./tools/Install-DotNetSdk.ps1
24+
displayName: Installing .NET Core SDK and runtimes
2025
- script: ./buildandtest.sh
26+
displayName: Build and test
2127
- job: macOS
2228
pool:
2329
vmImage: 'macOS 10.13'
2430
steps:
31+
- pwsh: ./tools/Install-DotNetSdk.ps1
32+
displayName: Installing .NET Core SDK and runtimes
2533
- script: ./buildandtest.sh
34+
displayName: Build and test

global.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"sdk": {
3+
"version": "2.1.802"
4+
}
5+
}

tools/DotNetSdkVersion.ps1

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
$globalJson = Get-Content -Path "$PSScriptRoot\..\global.json" | ConvertFrom-Json
2+
$globalJson.sdk.version

tools/Install-DotNetSdk.ps1

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
<#
2+
.SYNOPSIS
3+
Installs the .NET SDK specified in the global.json file at the root of this repository,
4+
along with supporting .NET Core runtimes used for testing.
5+
.DESCRIPTION
6+
This MAY not require elevation, as the SDK and runtimes are installed locally to this repo location,
7+
unless `-InstallLocality machine` is specified.
8+
.PARAMETER InstallLocality
9+
A value indicating whether dependencies should be installed locally to the repo or at a per-user location.
10+
Per-user allows sharing the installed dependencies across repositories and allows use of a shared expanded package cache.
11+
Visual Studio will only notice and use these SDKs/runtimes if VS is launched from the environment that runs this script.
12+
Per-repo allows for high isolation, allowing for a more precise recreation of the environment within an Azure Pipelines build.
13+
When using 'repo', environment variables are set to cause the locally installed dotnet SDK to be used.
14+
Per-repo can lead to file locking issues when dotnet.exe is left running as a build server and can be mitigated by running `dotnet build-server shutdown`.
15+
Per-machine requires elevation and will download and install all SDKs and runtimes to machine-wide locations so all applications can find it.
16+
#>
17+
[CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='Medium')]
18+
Param (
19+
[ValidateSet('repo','user','machine')]
20+
[string]$InstallLocality='user'
21+
)
22+
23+
$DotNetInstallScriptRoot = "$PSScriptRoot/../obj/tools"
24+
if (!(Test-Path $DotNetInstallScriptRoot)) { New-Item -ItemType Directory -Path $DotNetInstallScriptRoot | Out-Null }
25+
$DotNetInstallScriptRoot = Resolve-Path $DotNetInstallScriptRoot
26+
27+
# Look up actual required .NET Core SDK version from global.json
28+
$sdkVersion = & "$PSScriptRoot/DotNetSdkVersion.ps1"
29+
30+
# Search for all .NET Core runtime versions referenced from MSBuild projects and arrange to install them.
31+
$runtimeVersions = @()
32+
Get-ChildItem "$PSScriptRoot\..\*.*proj" -Recurse |% {
33+
$projXml = [xml](Get-Content -Path $_)
34+
$targetFrameworks = $projXml.Project.PropertyGroup.TargetFramework
35+
if (!$targetFrameworks) {
36+
$targetFrameworks = $projXml.Project.PropertyGroup.TargetFrameworks
37+
if ($targetFrameworks) {
38+
$targetFrameworks = $targetFrameworks -Split ';'
39+
}
40+
}
41+
$targetFrameworks |? { $_ -match 'netcoreapp(\d+\.\d+)' } |% {
42+
$runtimeVersions += $Matches[1]
43+
}
44+
}
45+
46+
Function Get-FileFromWeb([Uri]$Uri, $OutDir) {
47+
$OutFile = Join-Path $OutDir $Uri.Segments[-1]
48+
if (!(Test-Path $OutFile)) {
49+
Write-Verbose "Downloading $Uri..."
50+
try {
51+
(New-Object System.Net.WebClient).DownloadFile($Uri, $OutFile)
52+
} finally {
53+
# This try/finally causes the script to abort
54+
}
55+
}
56+
57+
$OutFile
58+
}
59+
60+
Function Get-InstallerExe($Version, [switch]$Runtime) {
61+
$sdkOrRuntime = 'Sdk'
62+
if ($Runtime) { $sdkOrRuntime = 'Runtime' }
63+
64+
# Get the latest/actual version for the specified one
65+
if (([Version]$Version).Build -eq -1) {
66+
$versionInfo = -Split (Invoke-WebRequest -Uri "https://dotnetcli.blob.core.windows.net/dotnet/$sdkOrRuntime/$Version/latest.version" -UseBasicParsing)
67+
$Version = $versionInfo[-1]
68+
}
69+
70+
Get-FileFromWeb -Uri "https://dotnetcli.blob.core.windows.net/dotnet/$sdkOrRuntime/$Version/dotnet-$($sdkOrRuntime.ToLowerInvariant())-$Version-win-x64.exe" -OutDir "$DotNetInstallScriptRoot"
71+
}
72+
73+
Function Install-DotNet($Version, [switch]$Runtime) {
74+
if ($Runtime) { $sdkSubstring = '' } else { $sdkSubstring = 'SDK ' }
75+
Write-Host "Downloading .NET Core $sdkSubstring$Version..."
76+
$Installer = Get-InstallerExe -Version $Version -Runtime:$Runtime
77+
Write-Host "Installing .NET Core $sdkSubstring$Version..."
78+
cmd /c start /wait $Installer /install /quiet
79+
if ($LASTEXITCODE -ne 0) {
80+
throw "Failure to install .NET Core SDK"
81+
}
82+
}
83+
84+
if ($InstallLocality -eq 'machine') {
85+
if ($IsMacOS -or $IsLinux) {
86+
Write-Error "Installing the .NET Core SDK or runtime at a machine-wide location is only supported by this script on Windows."
87+
exit 1
88+
}
89+
90+
if ($PSCmdlet.ShouldProcess(".NET Core SDK $sdkVersion", "Install")) {
91+
Install-DotNet -Version $sdkVersion
92+
}
93+
94+
$runtimeVersions |% {
95+
if ($PSCmdlet.ShouldProcess(".NET Core runtime $_", "Install")) {
96+
Install-DotNet -Version $_ -Runtime
97+
}
98+
}
99+
100+
return
101+
}
102+
103+
$switches = @(
104+
'-Architecture','x64'
105+
)
106+
$envVars = @{
107+
# For locally installed dotnet, skip first time experience which takes a long time
108+
'DOTNET_SKIP_FIRST_TIME_EXPERIENCE' = 'true';
109+
}
110+
111+
if ($InstallLocality -eq 'repo') {
112+
$DotNetInstallDir = "$DotNetInstallScriptRoot/.dotnet"
113+
} elseif ($env:AGENT_TOOLSDIRECTORY) {
114+
$DotNetInstallDir = "$env:AGENT_TOOLSDIRECTORY/dotnet"
115+
} else {
116+
$DotNetInstallDir = Join-Path $HOME .dotnet
117+
}
118+
119+
Write-Host "Installing .NET Core SDK and runtimes to $DotNetInstallDir" -ForegroundColor Blue
120+
121+
if ($DotNetInstallDir) {
122+
$switches += '-InstallDir',$DotNetInstallDir
123+
$envVars['DOTNET_MULTILEVEL_LOOKUP'] = '0'
124+
$envVars['DOTNET_ROOT'] = $DotNetInstallDir
125+
}
126+
127+
if ($IsMacOS -or $IsLinux) {
128+
$DownloadUri = "https://dot.net/v1/dotnet-install.sh"
129+
$DotNetInstallScriptPath = "$DotNetInstallScriptRoot/dotnet-install.sh"
130+
} else {
131+
$DownloadUri = "https://dot.net/v1/dotnet-install.ps1"
132+
$DotNetInstallScriptPath = "$DotNetInstallScriptRoot/dotnet-install.ps1"
133+
}
134+
135+
if (-not (Test-Path $DotNetInstallScriptPath)) {
136+
Invoke-WebRequest -Uri $DownloadUri -OutFile $DotNetInstallScriptPath -UseBasicParsing
137+
if ($IsMacOS -or $IsLinux) {
138+
chmod +x $DotNetInstallScriptPath
139+
}
140+
}
141+
142+
if ($PSCmdlet.ShouldProcess(".NET Core SDK $sdkVersion", "Install")) {
143+
Invoke-Expression -Command "$DotNetInstallScriptPath -Version $sdkVersion $switches"
144+
} else {
145+
Invoke-Expression -Command "$DotNetInstallScriptPath -Version $sdkVersion $switches -DryRun"
146+
}
147+
148+
$switches += '-Runtime','dotnet'
149+
150+
$runtimeVersions | Get-Unique |% {
151+
if ($PSCmdlet.ShouldProcess(".NET Core runtime $_", "Install")) {
152+
Invoke-Expression -Command "$DotNetInstallScriptPath -Channel $_ $switches"
153+
} else {
154+
Invoke-Expression -Command "$DotNetInstallScriptPath -Channel $_ $switches -DryRun"
155+
}
156+
}
157+
158+
if ($PSCmdlet.ShouldProcess("Set DOTNET environment variables to discover these installed runtimes?")) {
159+
& "$PSScriptRoot/Set-EnvVars.ps1" -Variables $envVars -PrependPath $DotNetInstallDir | Out-Null
160+
}

tools/Set-EnvVars.ps1

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<#
2+
.SYNOPSIS
3+
Set environment variables in the environment.
4+
Azure Pipeline and CMD environments are considered.
5+
.PARAMETER Variables
6+
A hashtable of variables to be set.
7+
.OUTPUTS
8+
A boolean indicating whether the environment variables can be expected to propagate to the caller's environment.
9+
#>
10+
[CmdletBinding(SupportsShouldProcess=$true)]
11+
Param(
12+
[Parameter(Mandatory=$true, Position=1)]
13+
$Variables,
14+
[string[]]$PrependPath
15+
)
16+
17+
if ($Variables.Count -eq 0) {
18+
return $true
19+
}
20+
21+
$cmdInstructions = !$env:TF_BUILD -and !$env:GITHUB_ACTIONS -and $env:PS1UnderCmd -eq '1'
22+
if ($cmdInstructions) {
23+
Write-Warning "Environment variables have been set that will be lost because you're running under cmd.exe"
24+
Write-Host "Environment variables that must be set manually:" -ForegroundColor Blue
25+
} else {
26+
Write-Host "Environment variables set:" -ForegroundColor Blue
27+
$envVars
28+
if ($PrependPath) {
29+
Write-Host "Paths prepended to PATH: $PrependPath"
30+
}
31+
}
32+
33+
if ($env:TF_BUILD) {
34+
Write-Host "Azure Pipelines detected. Logging commands will be used to propagate environment variables and prepend path."
35+
}
36+
37+
if ($env:GITHUB_ACTIONS) {
38+
Write-Host "GitHub Actions detected. Logging commands will be used to propagate environment variables and prepend path."
39+
}
40+
41+
$Variables.GetEnumerator() |% {
42+
Set-Item -Path env:$($_.Key) -Value $_.Value
43+
44+
# If we're running in a cloud CI, set these environment variables so they propagate.
45+
if ($env:TF_BUILD) {
46+
Write-Host "##vso[task.setvariable variable=$($_.Key);]$($_.Value)"
47+
}
48+
if ($env:GITHUB_ACTIONS) {
49+
Write-Host "::set-env name=$($_.Key)::$($_.Value)"
50+
}
51+
52+
if ($cmdInstructions) {
53+
Write-Host "SET $($_.Key)=$($_.Value)"
54+
}
55+
}
56+
57+
$pathDelimiter = ';'
58+
if ($IsMacOS -or $IsLinux) {
59+
$pathDelimiter = ':'
60+
}
61+
62+
if ($PrependPath) {
63+
$PrependPath |% {
64+
$newPathValue = "$_$pathDelimiter$env:PATH"
65+
Set-Item -Path env:PATH -Value $newPathValue
66+
if ($cmdInstructions) {
67+
Write-Host "SET PATH=$newPathValue"
68+
}
69+
70+
if ($env:TF_BUILD) {
71+
Write-Host "##vso[task.prependpath]$_"
72+
}
73+
if ($env:GITHUB_ACTIONS) {
74+
Write-Host "::add-path::$_"
75+
}
76+
}
77+
}
78+
79+
return !$cmdInstructions

0 commit comments

Comments
 (0)