Skip to content

Commit

Permalink
.NET 8 installcredprovider scripts (#524)
Browse files Browse the repository at this point in the history
Add support for the new .NET 8 and .NET Framework 4.8.1 versions in the
`installcredprovider` command line scripts.

Invoke using the `$InstallNet8` or `$AddNetfx48` switch parameters for
the `installcredprovider.ps1` script, or
`USE_NET8_ARTIFACTS_CREDENTIAL_PROVIDER` for `installcredprovider.sh`
  • Loading branch information
cobya authored Oct 10, 2024
1 parent 3e4f3ca commit 2a2891c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ Dotnet needs the `netcore` version to be installed. NuGet and MSBuild need the `
[PowerShell helper script](helpers/installcredprovider.ps1)
- To install netcore, run `installcredprovider.ps1`
- e.g. `iex "& { $(irm https://aka.ms/install-artifacts-credprovider.ps1) }"`
- .NET 6 bits can be installed using `iex "& { $(irm https://aka.ms/install-artifacts-credprovider.ps1) } -InstallNet6"`
- .NET 8 bits can be installed using `iex "& { $(irm https://aka.ms/install-artifacts-credprovider.ps1) } -InstallNet8"`
- To install both netfx and netcore, run `installcredprovider.ps1 -AddNetfx`. The netfx version is needed for nuget.exe.
- e.g. `iex "& { $(irm https://aka.ms/install-artifacts-credprovider.ps1) } -AddNetfx"`
- .NET Framework 4.8.1 support is available using the `-AddNetFx48` flag

#### Manual installation on Windows

Expand Down Expand Up @@ -72,7 +75,7 @@ Examples:

Using the above is recommended, but as per [NuGet's plugin discovery rules](https:/NuGet/Home/wiki/NuGet-cross-plat-authentication-plugin#plugin-installation-and-discovery), alternatively you can install the credential provider to a location you prefer, and then set the environment variable NUGET_PLUGIN_PATHS to the .dll of the credential provider found in plugins\netcore\CredentialProvider.Microsoft\CredentialProvider.Microsoft.dll. For example, $env:NUGET_PLUGIN_PATHS="my-alternative-location\CredentialProvider.Microsoft.dll".

Users requiring .NET 6, such as ARM64 users, can manually download the .NET 6 version `Microsoft.Net6.NuGet.CredentialProvider` of the [1.0.0 release](https:/microsoft/artifacts-credprovider/releases/tag/v1.0.0).
Users requiring .NET 6, such as ARM64 users, can manually download the .NET 6 version `Microsoft.Net6.NuGet.CredentialProvider` of the [1.0.0 release](https:/microsoft/artifacts-credprovider/releases/tag/v1.0.0). Support for .NET 8 was added in [release 1.3.0](https:/microsoft/artifacts-credprovider/releases/tag/v1.3.0) and can be downloaded with the `Microsoft.Net8.NuGet.CredentialProvider` archive.

### Automatic usage
- MSBuild in Visual Studio Developer Command Prompt with Visual Studio 15.9+
Expand Down
35 changes: 32 additions & 3 deletions helpers/installcredprovider.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
param(
# whether or not to install netfx folder for nuget
[switch]$AddNetfx,
# whether or not to install netfx 4.8.1 folder for nuget
[switch]$AddNetfx48,
# override existing cred provider with the latest version
[switch]$Force,
# install the version specified
[string]$Version,
# install Net6 version of the netcore cred provider instead of NetCore3.1
[switch]$InstallNet6 = $true
# install the .NET 6 cred provider instead of NetCore3.1
[switch]$InstallNet6 = $true,
# install the .NET 8 cred provider instead of NetCore3.1
[switch]$InstallNet8
)

$script:ErrorActionPreference='Stop'
Expand All @@ -27,6 +31,19 @@ if ($Version.StartsWith("0.") -and $InstallNet6 -eq $True) {
Write-Error "You cannot install the .Net 6 version with versions lower than 1.0.0"
return
}
if (($Version.StartsWith("0.") -or $Version.StartsWith("1.0") -or $Version.StartsWith("1.1") -or $Version.StartsWith("1.2")) -and
($InstallNet8 -eq $True -or $AddNetfx48 -eq $True)) {
Write-Error "You cannot install the .Net 8 or NetFX 4.8.1 version or with versions lower than 1.3.0"
return
}
if ($AddNetfx -eq $True -and $AddNetfx48 -eq $True) {
Write-Error "Please select a single .Net framework version to install"
return
}
if ($InstallNet6 -eq $True -and $InstallNet8 -eq $True) {
# InstallNet6 defaults to true, in the case of .Net 8 install, overwrite
$InstallNet6 = $False
}

$userProfilePath = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::UserProfile);
if ($userProfilePath -ne '') {
Expand Down Expand Up @@ -94,9 +111,15 @@ if ($Version.StartsWith("0.")) {
if ($InstallNet6 -eq $True) {
$zipFile = "Microsoft.Net6.NuGet.CredentialProvider.zip"
}
if ($InstallNet8 -eq $True) {
$zipFile = "Microsoft.Net8.NuGet.CredentialProvider.zip"
}
if ($AddNetfx -eq $True) {
$zipFile = "Microsoft.NuGet.CredentialProvider.zip"
}
if ($AddNetfx48 -eq $True) {
$zipFile = "Microsoft.NetFx48.NuGet.CredentialProvider.zip"
}

function InstallZip {
Write-Verbose "Using $zipFile"
Expand Down Expand Up @@ -152,7 +175,7 @@ function InstallZip {
InstallZip

# Remove existing content and copy netfx directories to plugins directory
if ($AddNetfx -eq $True) {
if ($AddNetfx -eq $True -or $AddNetfx48 -eq $True) {
if ($netfxExists) {
Write-Verbose "Removing existing content from $fullNetfxCredProviderPath"
Remove-Item $fullNetfxCredProviderPath -Force -Recurse
Expand All @@ -169,6 +192,12 @@ if ($AddNetfx -eq $True -and $InstallNet6 -eq $True) {
Write-Verbose "Installing Net6"
InstallZip
}
if ($AddNetfx -eq $True -and $InstallNet8 -eq $True) {
$zipFile = "Microsoft.Net8.NuGet.CredentialProvider.zip"
Write-Verbose "Installing Net8"
InstallZip
}

# Remove existing content and copy netcore directories to plugins directory
if ($netcoreExists) {
Write-Verbose "Removing existing content from $fullNetcoreCredProviderPath"
Expand Down
12 changes: 11 additions & 1 deletion helpers/installcredprovider.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ if [ -z ${USE_NET6_ARTIFACTS_CREDENTIAL_PROVIDER} ] || [ ${USE_NET6_ARTIFACTS_CR
# throw if version starts with 0. (net6 not supported)
case ${AZURE_ARTIFACTS_CREDENTIAL_PROVIDER_VERSION} in
0.*|v0.*)
echo "ERROR: To install NET6 cred provider using the USE_NET6_ARTIFACTS_CREDENTIAL_PROVIDER variable, version to be installed must be 1.0.0. or greater. Check your AZURE_ARTIFACTS_CREDENTIAL_PROVIDER_VERSION variable."
echo "ERROR: To install NET6 cred provider using the USE_NET6_ARTIFACTS_CREDENTIAL_PROVIDER variable, version to be installed must be 1.0.0 or greater. Check your AZURE_ARTIFACTS_CREDENTIAL_PROVIDER_VERSION variable."
exit 1
;;
esac
else if [ -z ${USE_NET8_ARTIFACTS_CREDENTIAL_PROVIDER} ] || [ ${USE_NET8_ARTIFACTS_CREDENTIAL_PROVIDER} != "false" ]; then
FILE="Microsoft.Net8.NuGet.CredentialProvider.tar.gz"

# throw if version starts < 1.3.0. (net8 not supported)
case ${AZURE_ARTIFACTS_CREDENTIAL_PROVIDER_VERSION} in
0.*|v0.*|1.0.*|v1.0.*|1.1.*|v1.1.*|1.2.*|v1.2.*)
echo "ERROR: To install NET8 cred provider using the USE_NET8_ARTIFACTS_CREDENTIAL_PROVIDER variable, version to be installed must be 1.3.0 or greater. Check your AZURE_ARTIFACTS_CREDENTIAL_PROVIDER_VERSION variable."
exit 1
;;
esac
Expand Down

4 comments on commit 2a2891c

@MehmetKinsey
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have broken the script

@jayrafolsperez-mb
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're getting this error on our pipelines from possibly this update:

error: "process \"/bin/sh -c wget -qO- https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh | sh\" did not complete successfully: exit code: 2"
#7 0.227 sh: 70: Syntax error: end of file unexpected (expecting "fi")

@MehmetKinsey
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice that all checks passed, with a typo else if => elif, breaking the script=) perhaps you need some real checks

@chrisosb
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When running the updated script I now get an HTTP Not Found error when downloading:
https:/Microsoft/artifacts-credprovider/releases/latest/download/Microsoft.Net8.NuGet.CredentialProvider.tar.gz

the previous version without the .Net8 in the url worked
https:/Microsoft/artifacts-credprovider/releases/latest/download/Microsoft.NuGet.CredentialProvider.tar.gz

This is breaking our builds

Please sign in to comment.