Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Add script to install the .NET Core SDK
Browse files Browse the repository at this point in the history
This works on local dev boxes and on Azure Pipeline agents so that the SDK version we need is always installed on-demand.
  • Loading branch information
AArnott committed Apr 24, 2020
1 parent e477b31 commit 3bae7d9
Show file tree
Hide file tree
Showing 14 changed files with 533 additions and 224 deletions.
39 changes: 39 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Contributing

This project has adopted the [Microsoft Open Source Code of
Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct
FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com)
with any additional questions or comments.

For our general contributing guidelines please see [our dotnet/runtime contributing guide](https://github.com/dotnet/runtime/blob/master/CONTRIBUTING.md).

## Best practices

* Use Windows PowerShell or [PowerShell Core][pwsh] (including on Linux/OSX) to run .ps1 scripts.
Some scripts set environment variables to help you, but they are only retained if you use PowerShell as your shell.

## Prerequisites

All dependencies can be installed by running the `init.ps1` script at the root of the repository
using Windows PowerShell or [PowerShell Core][pwsh] (on any OS).

The only prerequisite for building, testing, and deploying from this repository
is the [.NET SDK](https://get.dot.net/).
You should install the version specified in `global.json` or a later version within
the same major.minor.Bxx "hundreds" band.
For example if 2.2.300 is specified, you may install 2.2.300, 2.2.301, or 2.2.310
while the 2.2.400 version would not be considered compatible by .NET SDK.
See [.NET Core Versioning](https://docs.microsoft.com/en-us/dotnet/core/versions/) for more information.

The development experience is best with [Visual Studio][VisualStudio].

## Building

This repository can be built on Windows, Linux, and OSX.

Building, testing, and packing this repository can be done by using the standard dotnet CLI commands (e.g. `dotnet build`, `dotnet test`, `dotnet pack`, etc.).

[pwsh]: https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell?view=powershell-6
[VisualStudio]: https://docs.microsoft.com/dotnet/core/install/sdk?pivots=os-windows#install-with-visual-studio
46 changes: 21 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,46 @@
This repository contains the source code for .NET Portability Analyzer tools and
dependencies.

|Branch|Build Status|
|---|---|
|master|[![][BuildStatus-Master]][myget]|
|dev|[![][BuildStatus-Dev]][myget]|
|Branch|Build Status
|---|---|---|
|master|[![Build Status](https://devdiv.visualstudio.com/DevDiv/_apis/build/status/CoreFxTools/dotnet-apiport-yaml?branchName=master)](https://devdiv.visualstudio.com/DevDiv/_build/latest?definitionId=12912&branchName=master)
|dev|[![Build Status](https://devdiv.visualstudio.com/DevDiv/_apis/build/status/CoreFxTools/dotnet-apiport-yaml?branchName=dev)](https://devdiv.visualstudio.com/DevDiv/_build/latest?definitionId=12912&branchName=dev)

For a quick introduction, check out [this video on Channel 9][Channel 9 Video]:

[<img src="https://sec.ch9.ms/ch9/031c/f3d7672b-dd71-4a18-a8b4-37573c08031c/DotNetPortabilityAnalyzer_960.jpg" width="480" />][Channel 9 Video]

## Using this Repository
There is a Visual Studio extension available for VS 2017 and VS 2019: [.NET Portability Analyzer](https://marketplace.visualstudio.com/items?itemName=ConnieYau.NETPortabilityAnalyzer)

### Windows
There is a Visual Studio extension available for VS2017: [.NET Portability Analyzer](https://marketplace.visualstudio.com/items?itemName=ConnieYau.NETPortabilityAnalyzer)
## Using this Repository

Download and build for yourself:
1. Install [Visual Studio 2017 with .NET Core Workload][Visual Studio 2017]
2. Building:
* Visual Studio: `PortabilityTools.sln`
* Powershell: `.\build.ps1 -Configuration Debug -Platform AnyCPU`
See our [contributing guide](CONTRIBUTING.md) for instructions to
build and run from the source code in this repo.

### Linux/Mac
Sample usage to run the analysis from the command line:

1. Install [.NET Core SDK](https://dotnet.microsoft.com/download)
2. Execute: `build.sh`
3. Go to: `bin/Debug/ApiPort/netcoreapp2.1`
4. Run ApiPort by executing: `dotnet ApiPort.dll`
* Example: `dotnet ApiPort.dll listTargets`
* Example: `dotnet ApiPort.dll analyze -f Foo.dll -r HTML`
5. For convenience, create an alias command adding the following to your `~/.bash_profile`. Replace `{dotnet-apiport-folder}` with the path where you cloned the repo.
```ps1
./init.ps1
dotnet build src/ApiPort/ApiPort/ApiPort.csproj
dotnet bin/Debug/ApiPort/netcoreapp2.1/ApiPort.dll -- listTargets
dotnet bin/Debug/ApiPort/netcoreapp2.1/ApiPort.dll -- analyze -f Foo.dll -r HTML
```

If using bash for your shell, for convenience you may create an alias command adding the following to your `~/.bash_profile`. Replace `{dotnet-apiport-folder}` with the path where you cloned the repo.

```bash
alias apiport="dotnet {dotnet-apiport-folder}/bin/Debug/ApiPort/netcoreapp2.1/ApiPort.dll"
```
This will alow you to use apiport globally from the command line: `apiport analyze -f Foo.dll -r HTML`

This will allow you to use apiport globally from the command line: `apiport analyze -f Foo.dll -r HTML`

## Documentation

* [Introduction](docs/HowTo)
* [Platform Portability](docs/HowTo/PlatformPortability.md)
* [Breaking Changes](docs/HowTo/BreakingChanges.md)
* [.NET Portability Analyzer (Console application)](docs/Console)
* [.NET Core application](docs/Console/README.md#using-net-core-application)
* [.NET Core application](docs/Console/README.md#using-net-core-application)
* [.NET Portability Analyzer (Visual Studio extension)](docs/VSExtension)

## Projects
Expand Down Expand Up @@ -93,8 +92,6 @@ For an overview of all the .NET related projects, have a look at the

This project is licensed under the [MIT license](LICENSE).

[BuildStatus-Master]: https://devdiv.visualstudio.com/_apis/public/build/definitions/0bdbc590-a062-4c3f-b0f6-9383f67865ee/484/badge
[BuildStatus-Dev]: https://devdiv.visualstudio.com/_apis/public/build/definitions/0bdbc590-a062-4c3f-b0f6-9383f67865ee/7913/badge
[Channel 9 Video]: https://channel9.msdn.com/Blogs/Seth-Juarez/A-Brief-Look-at-the-NET-Portability-Analyzer
[Contributing Guide]: https://github.com/dotnet/corefx/wiki/Contributing
[Developer Guide]: https://github.com/dotnet/corefx/wiki/Developer-Guide
Expand All @@ -105,5 +102,4 @@ This project is licensed under the [MIT license](LICENSE).
[PR-Open]: https://github.com/Microsoft/dotnet-apiport/pulls?q=is%3Aopen+is%3Apr
[myget]: https://dotnet.myget.org/gallery/dotnet-apiport
[System.Reflection.Metadata]: https://github.com/dotnet/corefx/tree/master/src/System.Reflection.Metadata
[Visual Studio 2017]: https://docs.microsoft.com/dotnet/core/install/sdk?pivots=os-windows#install-with-visual-studio
[VSIX Gallery]: http://vsixgallery.com/extension/55d15546-28ca-40dc-af23-dfa503e9c5fe
3 changes: 2 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- checkout: self
clean: true

- powershell: .\init.ps1
- powershell: .\init.ps1 -UpgradePrerequisites -NoRestore
displayName: init.ps1 script

- task: securedevelopmentteam.vss-secure-development-tools.build-task-policheck.PoliCheck@1
Expand Down Expand Up @@ -195,6 +195,7 @@ jobs:
tests/**/*[Tt]ests/*.csproj
!tests/**/*/ApiPortVS.Tests.csproj
arguments: '--configuration $(BuildConfiguration) --framework $(BuildNetCoreAppTarget) --no-build'
enabled: false # it wasn't testing anything anyway.

- task: DotNetCoreCLI@2
displayName: dotnet publish
Expand Down
22 changes: 22 additions & 0 deletions azure-pipelines/Get-NuGetTool.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<#
.SYNOPSIS
Downloads the NuGet.exe tool and returns the path to it.
.PARAMETER NuGetVersion
The version of the NuGet tool to acquire.
#>
Param(
[Parameter()]
[string]$NuGetVersion='5.2.0'
)

$toolsPath = & "$PSScriptRoot\Get-TempToolsPath.ps1"
$binaryToolsPath = Join-Path $toolsPath $NuGetVersion
if (!(Test-Path $binaryToolsPath)) { $null = mkdir $binaryToolsPath }
$nugetPath = Join-Path $binaryToolsPath nuget.exe

if (!(Test-Path $nugetPath)) {
Write-Host "Downloading nuget.exe $NuGetVersion..." -ForegroundColor Yellow
(New-Object System.Net.WebClient).DownloadFile("https://dist.nuget.org/win-x86-commandline/v$NuGetVersion/NuGet.exe", $nugetPath)
}

return (Resolve-Path $nugetPath).Path
14 changes: 14 additions & 0 deletions azure-pipelines/Get-ProcDump.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<#
.SYNOPSIS
Downloads 32-bit and 64-bit procdump executables and returns the path to where they were installed.
#>
$version = '0.0.1'
$baseDir = "$PSScriptRoot\..\obj\tools"
$procDumpToolPath = "$baseDir\procdump.$version\bin"
if (-not (Test-Path $procDumpToolPath)) {
if (-not (Test-Path $baseDir)) { New-Item -Type Directory -Path $baseDir | Out-Null }
$baseDir = (Resolve-Path $baseDir).Path # Normalize it
& (& $PSScriptRoot\Get-NuGetTool.ps1) install procdump -version $version -PackageSaveMode nuspec -OutputDirectory $baseDir -Source https://api.nuget.org/v3/index.json | Out-Null
}

(Resolve-Path $procDumpToolPath).Path
13 changes: 13 additions & 0 deletions azure-pipelines/Get-TempToolsPath.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
if ($env:AGENT_TEMPDIRECTORY) {
$path = "$env:AGENT_TEMPDIRECTORY\$env:BUILD_BUILDID"
} elseif ($env:localappdata) {
$path = "$env:localappdata\gitrepos\tools"
} else {
$path = "$PSScriptRoot\..\obj\tools"
}

if (!(Test-Path $path)) {
New-Item -ItemType Directory -Path $Path | Out-Null
}

(Resolve-Path $path).Path
79 changes: 79 additions & 0 deletions azure-pipelines/Set-EnvVars.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<#
.SYNOPSIS
Set environment variables in the environment.
Azure Pipeline and CMD environments are considered.
.PARAMETER Variables
A hashtable of variables to be set.
.OUTPUTS
A boolean indicating whether the environment variables can be expected to propagate to the caller's environment.
#>
[CmdletBinding(SupportsShouldProcess=$true)]
Param(
[Parameter(Mandatory=$true, Position=1)]
$Variables,
[string[]]$PrependPath
)

if ($Variables.Count -eq 0) {
return $true
}

$cmdInstructions = !$env:TF_BUILD -and !$env:GITHUB_ACTIONS -and $env:PS1UnderCmd -eq '1'
if ($cmdInstructions) {
Write-Warning "Environment variables have been set that will be lost because you're running under cmd.exe"
Write-Host "Environment variables that must be set manually:" -ForegroundColor Blue
} else {
Write-Host "Environment variables set:" -ForegroundColor Blue
Write-Host ($Variables | Out-String)
if ($PrependPath) {
Write-Host "Paths prepended to PATH: $PrependPath"
}
}

if ($env:TF_BUILD) {
Write-Host "Azure Pipelines detected. Logging commands will be used to propagate environment variables and prepend path."
}

if ($env:GITHUB_ACTIONS) {
Write-Host "GitHub Actions detected. Logging commands will be used to propagate environment variables and prepend path."
}

$Variables.GetEnumerator() |% {
Set-Item -Path env:$($_.Key) -Value $_.Value

# If we're running in a cloud CI, set these environment variables so they propagate.
if ($env:TF_BUILD) {
Write-Host "##vso[task.setvariable variable=$($_.Key);]$($_.Value)"
}
if ($env:GITHUB_ACTIONS) {
Write-Host "::set-env name=$($_.Key)::$($_.Value)"
}

if ($cmdInstructions) {
Write-Host "SET $($_.Key)=$($_.Value)"
}
}

$pathDelimiter = ';'
if ($IsMacOS -or $IsLinux) {
$pathDelimiter = ':'
}

if ($PrependPath) {
$PrependPath |% {
$newPathValue = "$_$pathDelimiter$env:PATH"
Set-Item -Path env:PATH -Value $newPathValue
if ($cmdInstructions) {
Write-Host "SET PATH=$newPathValue"
}

if ($env:TF_BUILD) {
Write-Host "##vso[task.prependpath]$_"
}
if ($env:GITHUB_ACTIONS) {
Write-Host "::add-path::$_"
}
}
}

return !$cmdInstructions
2 changes: 2 additions & 0 deletions azure-pipelines/variables/DotNetSdkVersion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$globalJson = Get-Content -Path "$PSScriptRoot\..\..\global.json" | ConvertFrom-Json
$globalJson.sdk.version
Loading

0 comments on commit 3bae7d9

Please sign in to comment.