Modify GenerateLayout to work with runtime configs that contain more than one runtime (#10901) (#10947)
This commit is contained in:
parent
c026501c78
commit
66e7c4cf3b
3 changed files with 77 additions and 21 deletions
70
src/core-sdk-tasks/UpdateRuntimeConfig.cs
Normal file
70
src/core-sdk-tasks/UpdateRuntimeConfig.cs
Normal file
|
@ -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<string>();
|
||||||
|
if (name == "Microsoft.NETCore.App")
|
||||||
|
{
|
||||||
|
framework["version"] = MicrosoftNetCoreAppVersion;
|
||||||
|
}
|
||||||
|
else if (name == "Microsoft.AspNetCore.App")
|
||||||
|
{
|
||||||
|
framework["version"] = MicrosoftAspNetCoreAppVersion;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,6 +27,7 @@
|
||||||
<UsingTask TaskName="TarGzFileCreateFromDirectory" AssemblyFile="$(CoreSdkTaskDll)" />
|
<UsingTask TaskName="TarGzFileCreateFromDirectory" AssemblyFile="$(CoreSdkTaskDll)" />
|
||||||
<UsingTask TaskName="GenerateMsiVersionFromFullVersion" AssemblyFile="$(CoreSdkTaskDll)" />
|
<UsingTask TaskName="GenerateMsiVersionFromFullVersion" AssemblyFile="$(CoreSdkTaskDll)" />
|
||||||
<UsingTask TaskName="ReplaceFileContents" AssemblyFile="$(CoreSdkTaskDll)" />
|
<UsingTask TaskName="ReplaceFileContents" AssemblyFile="$(CoreSdkTaskDll)" />
|
||||||
|
<UsingTask TaskName="UpdateRuntimeConfig" AssemblyFile="$(CoreSdkTaskDll)" />
|
||||||
<UsingTask TaskName="Chmod" AssemblyFile="$(CoreSdkTaskDll)" />
|
<UsingTask TaskName="Chmod" AssemblyFile="$(CoreSdkTaskDll)" />
|
||||||
<UsingTask TaskName="DotNetDebTool" AssemblyFile="$(CoreSdkTaskDll)" />
|
<UsingTask TaskName="DotNetDebTool" AssemblyFile="$(CoreSdkTaskDll)" />
|
||||||
<UsingTask TaskName="BuildFPMToolPreReqs" AssemblyFile="$(CoreSdkTaskDll)"/>
|
<UsingTask TaskName="BuildFPMToolPreReqs" AssemblyFile="$(CoreSdkTaskDll)"/>
|
||||||
|
|
|
@ -407,30 +407,15 @@
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<Target Name="RetargetTools">
|
<Target Name="RetargetTools">
|
||||||
<PropertyGroup>
|
|
||||||
<ReplacementPattern>"version": ".*"</ReplacementPattern>
|
|
||||||
<ReplacementString>"version": "$(MicrosoftNETCoreAppRuntimePackageVersion)"</ReplacementString>
|
|
||||||
<AspNetCoreRuntimeReplacementString>"version": "$(MicrosoftAspNetCoreAppRuntimePackageVersion)"</AspNetCoreRuntimeReplacementString>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ToolRuntimeConfigPath Include="$(RedistLayoutPath)sdk/$(Version)/**/*.runtimeconfig.json" />
|
<ToolRuntimeConfigPath Include="$(RedistLayoutPath)sdk/$(Version)/**/*.runtimeconfig.json" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<!-- Update runtimeconfig files that target Microsoft.NETCore.App -->
|
<!-- Update runtimeconfig files for tools in the SDK to pin the shared frameworks to the one carried by this installer. -->
|
||||||
<ReplaceFileContents
|
<UpdateRuntimeConfig
|
||||||
InputFiles="@(ToolRuntimeConfigPath)"
|
RuntimeConfigPaths="@(ToolRuntimeConfigPath)"
|
||||||
DestinationFiles="@(ToolRuntimeConfigPath)"
|
MicrosoftNetCoreAppVersion="$(MicrosoftNETCoreAppRuntimePackageVersion)"
|
||||||
ReplacementPatterns="$(ReplacementPattern)"
|
MicrosoftAspNetCoreAppVersion="$(MicrosoftAspNetCoreAppRuntimePackageVersion)" />
|
||||||
ReplacementStrings="$(ReplacementString)"
|
|
||||||
FileMustContainText="Microsoft.NETCore.App" />
|
|
||||||
|
|
||||||
<!-- Update runtimeconfig files that target Microsoft.AspNetCore.App -->
|
|
||||||
<ReplaceFileContents
|
|
||||||
InputFiles="@(ToolRuntimeConfigPath)"
|
|
||||||
DestinationFiles="@(ToolRuntimeConfigPath)"
|
|
||||||
ReplacementPatterns="$(ReplacementPattern)"
|
|
||||||
ReplacementStrings="$(AspNetCoreRuntimeReplacementString)"
|
|
||||||
FileMustContainText="Microsoft.AspNetCore.App" />
|
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<Target Name="GenerateVersionFile"
|
<Target Name="GenerateVersionFile"
|
||||||
|
|
Loading…
Reference in a new issue