|
12 | 12 | using Microsoft.DotNet.Cli.Utils.Extensions; |
13 | 13 | using Microsoft.NET.HostModel.AppHost; |
14 | 14 | using NuGet.Configuration; |
| 15 | +using NuGet.Versioning; |
15 | 16 |
|
16 | 17 | namespace Microsoft.DotNet.Cli.Commands.Run; |
17 | 18 |
|
@@ -44,6 +45,7 @@ internal sealed partial class CSharpCompilerCommand |
44 | 45 | private static string ClientDirectory => field ??= Path.Combine(SdkPath, "Roslyn", "bincore"); |
45 | 46 | private static string NuGetCachePath => field ??= SettingsUtility.GetGlobalPackagesFolder(Settings.LoadDefaultSettings(null)); |
46 | 47 | internal static string RuntimeVersion => field ??= RuntimeInformation.FrameworkDescription.Split(' ').Last(); |
| 48 | + private static string DefaultRuntimeVersion => field ??= GetDefaultRuntimeVersion(); |
47 | 49 | private static string TargetFrameworkVersion => Product.TargetFrameworkVersion; |
48 | 50 |
|
49 | 51 | public required string EntryPointFileFullPath { get; init; } |
@@ -285,7 +287,7 @@ private void PrepareAuxiliaryFiles(out string rspPath) |
285 | 287 | "tfm": "net{{TargetFrameworkVersion}}", |
286 | 288 | "framework": { |
287 | 289 | "name": "Microsoft.NETCore.App", |
288 | | - "version": {{JsonSerializer.Serialize(RuntimeVersion)}} |
| 290 | + "version": {{JsonSerializer.Serialize(DefaultRuntimeVersion)}} |
289 | 291 | }, |
290 | 292 | "configProperties": { |
291 | 293 | "EntryPointFilePath": {{JsonSerializer.Serialize(EntryPointFileFullPath)}}, |
@@ -387,4 +389,19 @@ public static bool IsPathOption(string arg, out int colonIndex) |
387 | 389 | colonIndex = -1; |
388 | 390 | return false; |
389 | 391 | } |
| 392 | + |
| 393 | + /// <summary> |
| 394 | + /// See <c>GenerateDefaultRuntimeFrameworkVersion</c>. |
| 395 | + /// </summary> |
| 396 | + private static string GetDefaultRuntimeVersion() |
| 397 | + { |
| 398 | + if (NuGetVersion.TryParse(RuntimeVersion, out var version)) |
| 399 | + { |
| 400 | + return version.IsPrerelease && version.Patch == 0 ? |
| 401 | + RuntimeVersion : |
| 402 | + new NuGetVersion(version.Major, version.Minor, 0).ToFullString(); |
| 403 | + } |
| 404 | + |
| 405 | + return RuntimeVersion; |
| 406 | + } |
390 | 407 | } |
0 commit comments