-
Notifications
You must be signed in to change notification settings - Fork 383
Support major.minor version format in global.json runtimes #16420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
9332d89
3751172
920366b
97dc47d
9b711e9
15bcdb5
14016c4
a9584e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,4 +136,4 @@ node_modules/ | |
| .idea/ | ||
|
|
||
| # vscode python env files | ||
| .env | ||
| .env.nuget/nuget.exe | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -291,6 +291,7 @@ function InstallDotNet([string] $dotnetRoot, | |
| [bool] $skipNonVersionedFiles = $false, | ||
| [string] $runtimeSourceFeed = '', | ||
| [string] $runtimeSourceFeedKey = '', | ||
| [string] $channel = '', | ||
| [switch] $noPath) { | ||
|
|
||
| $dotnetVersionLabel = "'sdk v$version'" | ||
|
|
@@ -301,21 +302,36 @@ function InstallDotNet([string] $dotnetRoot, | |
| if ($runtime -eq "dotnet") { $runtimePath = $runtimePath + "\Microsoft.NETCore.App" } | ||
| if ($runtime -eq "aspnetcore") { $runtimePath = $runtimePath + "\Microsoft.AspNetCore.App" } | ||
| if ($runtime -eq "windowsdesktop") { $runtimePath = $runtimePath + "\Microsoft.WindowsDesktop.App" } | ||
| $runtimePath = $runtimePath + "\" + $version | ||
|
|
||
| $dotnetVersionLabel = "runtime toolset '$runtime/$architecture v$version'" | ||
|
|
||
| if (Test-Path $runtimePath) { | ||
| Write-Host " Runtime toolset '$runtime/$architecture v$version' already installed." | ||
| $installSuccess = $true | ||
| Exit | ||
|
|
||
| # When using channel, we can't check for an existing installation by version | ||
| # since we don't know which version will be installed | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mconnew would this be a problem for you? it means we'd run dotnet-install.ps1 everytime
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @akoeplinger, would that only be when running restore? If running |
||
| if (-not $channel) { | ||
| $runtimePath = $runtimePath + "\" + $version | ||
| $dotnetVersionLabel = "runtime toolset '$runtime/$architecture v$version'" | ||
|
|
||
| if (Test-Path $runtimePath) { | ||
| Write-Host " Runtime toolset '$runtime/$architecture v$version' already installed." | ||
| $installSuccess = $true | ||
| return | ||
| } | ||
| } else { | ||
| $dotnetVersionLabel = "runtime toolset '$runtime/$architecture channel $channel'" | ||
| } | ||
| } | ||
|
|
||
| $installScript = GetDotNetInstallScript $dotnetRoot | ||
| $installParameters = @{ | ||
| Version = $version | ||
| InstallDir = $dotnetRoot | ||
|
|
||
| # Use -Channel if specified, otherwise use -Version | ||
| if ($channel) { | ||
| $installParameters = @{ | ||
| Channel = $channel | ||
| InstallDir = $dotnetRoot | ||
| } | ||
| } else { | ||
| $installParameters = @{ | ||
| Version = $version | ||
| InstallDir = $dotnetRoot | ||
| } | ||
| } | ||
|
|
||
| if ($architecture) { $installParameters.Architecture = $architecture } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.IO; | ||
| using System.Reflection; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.DotNet.Arcade.Sdk.Tests | ||
| { | ||
| public class InstallDotNetCoreTests | ||
| { | ||
| [Theory] | ||
| [InlineData("8.0", true)] | ||
| [InlineData("10.0", true)] | ||
| [InlineData("3.1", true)] | ||
| [InlineData("8.0.22", false)] | ||
| [InlineData("10.0.1", false)] | ||
| [InlineData("8.0.0-preview.1", false)] | ||
| [InlineData("", false)] | ||
| [InlineData(null, false)] | ||
| [InlineData("8", false)] | ||
| [InlineData("8.0.1.2", false)] | ||
| [InlineData("v8.0", false)] | ||
| [InlineData("8.x", false)] | ||
| public void IsTwoPartVersion_DetectsCorrectFormat(string versionString, bool expected) | ||
| { | ||
| // Use reflection to call the private method | ||
| var task = new InstallDotNetCore(); | ||
| var method = typeof(InstallDotNetCore).GetMethod("IsTwoPartVersion", BindingFlags.NonPublic | BindingFlags.Instance); | ||
|
|
||
| var result = (bool)method.Invoke(task, new object[] { versionString }); | ||
|
|
||
| Assert.Equal(expected, result); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,8 +106,16 @@ public override bool Execute() | |
| } | ||
|
|
||
| SemanticVersion version = null; | ||
| string channel = null; | ||
|
|
||
| // Check if the version is in major.minor format (e.g., "8.0", "10.0") | ||
| // This format should use the -channel parameter instead of -version | ||
| if (IsTwoPartVersion(item.Key)) | ||
| { | ||
| channel = item.Key; | ||
| } | ||
| // Try to parse version | ||
| if (!SemanticVersion.TryParse(item.Key, out version)) | ||
| else if (!SemanticVersion.TryParse(item.Key, out version)) | ||
| { | ||
| var propertyName = item.Key.Trim(s_keyTrimChars); | ||
|
|
||
|
|
@@ -123,9 +131,12 @@ public override bool Execute() | |
| } | ||
| } | ||
|
|
||
| if (version != null) | ||
| if (version != null || channel != null) | ||
| { | ||
| string arguments = $"-runtime \"{runtimeItem.Key}\" -version \"{version.ToNormalizedString()}\""; | ||
| string arguments = channel != null | ||
| ? $"-runtime \"{runtimeItem.Key}\" -channel \"{channel}\"" | ||
| : $"-runtime \"{runtimeItem.Key}\" -version \"{version.ToNormalizedString()}\""; | ||
|
|
||
| if (!string.IsNullOrEmpty(architecture)) | ||
| { | ||
| arguments += $" -architecture {architecture}"; | ||
|
|
@@ -204,6 +215,27 @@ private string GetArchitecture(string architecture) | |
| return null; | ||
| } | ||
|
|
||
| /* | ||
| * Checks if a version string is in major.minor format (e.g., "8.0", "10.0"). | ||
| * Returns true if the version has exactly two numeric parts separated by a dot. | ||
| */ | ||
| private bool IsTwoPartVersion(string versionString) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(versionString)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot Please use a regex for this detection.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated to use regex pattern |
||
| { | ||
| return false; | ||
| } | ||
|
|
||
| var parts = versionString.Split('.'); | ||
| if (parts.Length != 2) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| // Both parts must be valid integers | ||
| return int.TryParse(parts[0], out _) && int.TryParse(parts[1], out _); | ||
| } | ||
|
|
||
| /* | ||
| * Parses a json token of this format | ||
| * { (runtime): [(version), ..., (version)] } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Remove this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Reverted .gitignore to original state in commit 14016c4.