Getting Started - VS Code guidance
By using free software anyone in Arup can create libraries for ArupCompute.
Installation
.Net Core SDK
To install .Net Core SDK 2.2 request it from Arup apps.
To ensure that the .Net Core SDK has downloaded and installed properly from ArupApps open up a terminal (either PowerShell or the command prompt) and type the command dotnet --info
. You should see some runtime, host and SDK versioning information printed. If instead you see an error (dotnet is not recognized as an internal or external command
) raise a ticket with IT support.
VS Code
To install Visual Studio Code download it from the VS Code website. Ensure that you select the 'User Installer' as this will install without admin privileges.
C# extension
VS Code does not natively support any programming languages, instead this is enabled by installing extensions. For this tutorial we will install the C# plugin.
Create a new library with the scaffolding script
Because there are quite a few steps to creating a new C# library and configuring the various ArupCompute libraries this scaffolding script has been created
- Unzip the arupcompute-scaffold folder
- Run the arupcompute-scaffold.ps1 script using PowerShell
- You will be prompted for a project name, type on in and then press enter for it to run
The script will then:
- Create a C# class library
- Create a C# test project
- Link the two together with a
.sln
(solution) file - Install the Azure Artefacts credential provider
- Add the relevant ArupCompute libraries into your projects
You can now move on to to the next section.
Creating a new C# library manually
Skip this whole section if you have used the scaffolding script
- Create a new folder on your hard drive
- Open up a terminal within the folder
- Run the command
dotnet new classlib
The library will be created at the path the command prompt is in. You can move down directories with the command cd <foldername>
, and move up with cd ..
All subsequent dotnet
commands must be executed from the same directory as your <myprojectname>.csproj
file.
Linking the ArupCompute .Net SDK
In subsequent sections of the tutorial we will need to utilise a library that has been written to interface our code with ArupCompute. The following steps show how to access and install that library.
Ensuring access
This library is hosted and protected on an Arup code repository. To ensure you have access first click on this link and accept any login requests that appear.
If successful you should see some data like in the image below.
Installation of Azure Artefacts credential provider
To install the Azure Artefacts credential provider:
- Open up a new powershell window
- Paste in the code below
- Press enter
# A PowerShell script that adds the latest version of the Azure Artifacts credential provider
# plugin for Dotnet and/or NuGet to ~/.nuget/plugins directory
# To install netcore, run installcredprovider.ps1
# To install netcore and netfx, run installcredprovider.ps1 -AddNetfx
# To overwrite existing plugin with the latest version, run installcredprovider.ps1 -Force
# To use a specific version of a credential provider, run installcredprovider.ps1 -Version "0.1.17" or installcredprovider.ps1 -Version "0.1.17" -Force
# More: https://github.com/Microsoft/artifacts-credprovider/blob/master/README.md
param(
# whether or not to install netfx folder for nuget
[switch]$AddNetfx,
# override existing cred provider with the latest version
[switch]$Force,
# install the version specified
[string]$Version
)
$script:ErrorActionPreference='Stop'
# Without this, System.Net.WebClient.DownloadFile will fail on a client with TLS 1.0/1.1 disabled
if ([Net.ServicePointManager]::SecurityProtocol.ToString().Split(',').Trim() -notcontains 'Tls12') {
[Net.ServicePointManager]::SecurityProtocol += [Net.SecurityProtocolType]::Tls12
}
$profilePath = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::UserProfile)
$tempPath = [System.IO.Path]::GetTempPath()
$pluginLocation = [System.IO.Path]::Combine($profilePath, ".nuget", "plugins");
$tempZipLocation = [System.IO.Path]::Combine($tempPath, "CredProviderZip");
$localNetcoreCredProviderPath = [System.IO.Path]::Combine("netcore", "CredentialProvider.Microsoft");
$localNetfxCredProviderPath = [System.IO.Path]::Combine("netfx", "CredentialProvider.Microsoft");
$fullNetfxCredProviderPath = [System.IO.Path]::Combine($pluginLocation, $localNetfxCredProviderPath)
$fullNetcoreCredProviderPath = [System.IO.Path]::Combine($pluginLocation, $localNetcoreCredProviderPath)
$netfxExists = Test-Path -Path ($fullNetfxCredProviderPath)
$netcoreExists = Test-Path -Path ($fullNetcoreCredProviderPath)
# Check if plugin already exists if -Force swich is not set
if (!$Force) {
if ($AddNetfx -eq $True -and $netfxExists -eq $True -and $netcoreExists -eq $True) {
Write-Host "The netcore and netfx Credential Providers are already in $pluginLocation"
return
}
if ($AddNetfx -eq $False -and $netcoreExists -eq $True) {
Write-Host "The netcore Credential Provider is already in $pluginLocation"
return
}
}
# Get the zip file from the GitHub release
$releaseUrlBase = "https://api.github.com/repos/Microsoft/artifacts-credprovider/releases"
$versionError = "Unable to find the release version $Version from $releaseUrlBase"
$releaseId = "latest"
if (![string]::IsNullOrEmpty($Version)) {
try {
$releases = Invoke-WebRequest -UseBasicParsing $releaseUrlBase
$releaseJson = $releases | ConvertFrom-Json
$correctReleaseVersion = $releaseJson | ? { $_.name -eq $Version }
$releaseId = $correctReleaseVersion.id
} catch {
Write-Error $versionError
return
}
}
if (!$releaseId) {
Write-Error $versionError
return
}
$releaseUrl = [System.IO.Path]::Combine($releaseUrlBase, $releaseId)
$releaseUrl = $releaseUrl.Replace("\","/")
$zipFile = "Microsoft.NetCore2.NuGet.CredentialProvider.zip"
if ($AddNetfx -eq $True) {
$zipFile = "Microsoft.NuGet.CredentialProvider.zip"
}
Write-Verbose "Using $zipFile"
$zipErrorString = "Unable to resolve the Credential Provider zip file from $releaseUrl"
try {
Write-Host "Fetching release $releaseUrl"
$release = Invoke-WebRequest -UseBasicParsing $releaseUrl
$releaseJson = $release.Content | ConvertFrom-Json
$zipAsset = $releaseJson.assets | ? { $_.name -eq $zipFile }
$packageSourceUrl = $zipAsset.browser_download_url
} catch {
Write-Error $zipErrorString
return
}
if (!$packageSourceUrl) {
Write-Error $zipErrorString
return
}
# Create temporary location for the zip file handling
Write-Verbose "Creating temp directory for the Credential Provider zip: $tempZipLocation"
if (Test-Path -Path $tempZipLocation) {
Remove-Item $tempZipLocation -Force -Recurse
}
New-Item -ItemType Directory -Force -Path $tempZipLocation
# Download credential provider zip to the temp location
$pluginZip = ([System.IO.Path]::Combine($tempZipLocation, $zipFile))
Write-Host "Downloading $packageSourceUrl to $pluginZip"
try {
$client = New-Object System.Net.WebClient
$client.DownloadFile($packageSourceUrl, $pluginZip)
} catch {
Write-Error "Unable to download $packageSourceUrl to the location $pluginZip"
}
# Extract zip to temp directory
Write-Host "Extracting zip to the Credential Provider temp directory $tempZipLocation"
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($pluginZip, $tempZipLocation)
# Remove existing content and copy netcore (and netfx) directories to plugins directory
if ($netcoreExists) {
Write-Verbose "Removing existing content from $fullNetcoreCredProviderPath"
Remove-Item $fullNetcoreCredProviderPath -Force -Recurse
}
$tempNetcorePath = [System.IO.Path]::Combine($tempZipLocation, "plugins", $localNetcoreCredProviderPath)
Write-Verbose "Copying Credential Provider from $tempNetcorePath to $fullNetcoreCredProviderPath"
Copy-Item $tempNetcorePath -Destination $fullNetcoreCredProviderPath -Force -Recurse
if ($AddNetfx -eq $True) {
if ($netfxExists) {
Write-Verbose "Removing existing content from $fullNetfxCredProviderPath"
Remove-Item $fullNetfxCredProviderPath -Force -Recurse
}
$tempNetfxPath = [System.IO.Path]::Combine($tempZipLocation, "plugins", $localNetfxCredProviderPath)
Write-Verbose "Copying Credential Provider from $tempNetfxPath to $fullNetfxCredProviderPath"
Copy-Item $tempNetfxPath -Destination $fullNetfxCredProviderPath -Force -Recurse
}
# Remove $tempZipLocation directory
Write-Verbose "Removing the Credential Provider temp directory $tempZipLocation"
Remove-Item $tempZipLocation -Force -Recurse
Write-Host "Credential Provider installed successfully"
Adding reference libraries to our project
To add the reference libraries run the commands:
dotnet add package Arup.Compute.DotNetSdk --interactive