diff --git a/src/core-sdk-tasks/UpdateRuntimeConfig.cs b/src/core-sdk-tasks/UpdateRuntimeConfig.cs new file mode 100644 index 000000000..8d8c73c63 --- /dev/null +++ b/src/core-sdk-tasks/UpdateRuntimeConfig.cs @@ -0,0 +1,70 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; +using Newtonsoft.Json.Linq; + +namespace Microsoft.DotNet.Build.Tasks +{ + public sealed class UpdateRuntimeConfig : Task + { + [Required] + public ITaskItem[] RuntimeConfigPaths { get; set; } + + [Required] + public string MicrosoftNetCoreAppVersion { get; set; } + + [Required] + public string MicrosoftAspNetCoreAppVersion { get; set; } + + public override bool Execute() + { + foreach (var file in RuntimeConfigPaths) + { + UpdateFile(file.ItemSpec); + } + + return true; + } + + private void UpdateFile(string file) + { + var text = File.ReadAllText(file); + JObject config = JObject.Parse(text); + var frameworks = config["runtimeOptions"]?["frameworks"]; + var framework = config["runtimeOptions"]?["framework"]; + if (frameworks != null) + { + foreach (var item in frameworks) + { + UpdateFramework(item); + } + } + else if (framework != null) + { + UpdateFramework(framework); + } + + File.WriteAllText(file, config.ToString()); + } + + private void UpdateFramework(JToken item) + { + var framework = (JObject)item; + var name = framework["name"].Value(); + if (name == "Microsoft.NETCore.App") + { + framework["version"] = MicrosoftNetCoreAppVersion; + } + else if (name == "Microsoft.AspNetCore.App") + { + framework["version"] = MicrosoftAspNetCoreAppVersion; + } + } + } +} \ No newline at end of file diff --git a/src/redist/targets/BuildCoreSdkTasks.targets b/src/redist/targets/BuildCoreSdkTasks.targets index d7692cebc..c87b22094 100644 --- a/src/redist/targets/BuildCoreSdkTasks.targets +++ b/src/redist/targets/BuildCoreSdkTasks.targets @@ -3,7 +3,7 @@ $(CoreSdkTargetFramework) net472 - + $(ArtifactsDir)tasks\bin\core-sdk-tasks\$(Configuration)\$(TaskTargetFramework)\core-sdk-tasks.dll $(RepoRoot)src\core-sdk-tasks\core-sdk-tasks.csproj @@ -27,6 +27,7 @@ + diff --git a/src/redist/targets/GenerateLayout.targets b/src/redist/targets/GenerateLayout.targets index e8d75b7ca..a83f6fddd 100644 --- a/src/redist/targets/GenerateLayout.targets +++ b/src/redist/targets/GenerateLayout.targets @@ -407,30 +407,15 @@ - - "version": ".*" - "version": "$(MicrosoftNETCoreAppRuntimePackageVersion)" - "version": "$(MicrosoftAspNetCoreAppRuntimePackageVersion)" - - - - - - + +