Skip to content

Commit bddce54

Browse files
committed
Use default runtime version in runtimeconfig.json same as MSBuild-based build would
1 parent 629ad2c commit bddce54

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/Cli/dotnet/Commands/Run/CSharpCompilerCommand.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Microsoft.DotNet.Cli.Utils.Extensions;
1313
using Microsoft.NET.HostModel.AppHost;
1414
using NuGet.Configuration;
15+
using NuGet.Versioning;
1516

1617
namespace Microsoft.DotNet.Cli.Commands.Run;
1718

@@ -44,6 +45,7 @@ internal sealed partial class CSharpCompilerCommand
4445
private static string ClientDirectory => field ??= Path.Combine(SdkPath, "Roslyn", "bincore");
4546
private static string NuGetCachePath => field ??= SettingsUtility.GetGlobalPackagesFolder(Settings.LoadDefaultSettings(null));
4647
internal static string RuntimeVersion => field ??= RuntimeInformation.FrameworkDescription.Split(' ').Last();
48+
private static string DefaultRuntimeVersion => field ??= GetDefaultRuntimeVersion();
4749
private static string TargetFrameworkVersion => Product.TargetFrameworkVersion;
4850

4951
public required string EntryPointFileFullPath { get; init; }
@@ -285,7 +287,7 @@ private void PrepareAuxiliaryFiles(out string rspPath)
285287
"tfm": "net{{TargetFrameworkVersion}}",
286288
"framework": {
287289
"name": "Microsoft.NETCore.App",
288-
"version": {{JsonSerializer.Serialize(RuntimeVersion)}}
290+
"version": {{JsonSerializer.Serialize(DefaultRuntimeVersion)}}
289291
},
290292
"configProperties": {
291293
"EntryPointFilePath": {{JsonSerializer.Serialize(EntryPointFileFullPath)}},
@@ -387,4 +389,19 @@ public static bool IsPathOption(string arg, out int colonIndex)
387389
colonIndex = -1;
388390
return false;
389391
}
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+
}
390407
}

0 commit comments

Comments
 (0)