Stamp runtimeconfigs with M.AspNetCore.App versions

The installer currently updates all runtimeconfig files with the M.NETCore.App version
regardless of the runtime they are targeting. This causes issues with dotnet-watch
which is targeting the AspNetCore shared runtime as of 5.0-preview8. This change
updates the targets \ task to be more discerning.
This commit is contained in:
Pranav K 2020-09-14 10:35:11 -07:00
parent 03c8593ee0
commit 45264fac2a
No known key found for this signature in database
GPG key ID: F748807460A27E91
2 changed files with 31 additions and 8 deletions

View file

@ -12,18 +12,18 @@ namespace Microsoft.DotNet.Cli.Build
{
/// <summary>
/// Reads contents of an input file, and searches for each replacement passed in.
///
///
/// When ReplacementItems is matched, it will replace the Include/ItemSpec with the corresponding
/// ReplacementString metadata value. This can be useful if the ReplacementString is a value that
/// cannot be represented by ITaskItem.ItemSpec (like string.Empty).
///
/// When a ReplacementPattern is matched it will replace it with the string of the corresponding (by index)
///
/// When a ReplacementPattern is matched it will replace it with the string of the corresponding (by index)
/// item in ReplacementStrings.
///
/// For example, if 2 ReplacementPatterns are passed in, 2 ReplacementStrings must also passed in and the first
///
/// For example, if 2 ReplacementPatterns are passed in, 2 ReplacementStrings must also passed in and the first
/// pattern will be replaced with the first string, and the second pattern replaced with the second string.
///
/// ReplacementPattern could easily be a regex, but it isn't needed for current use cases, so leaving this
///
/// ReplacementPattern could easily be a regex, but it isn't needed for current use cases, so leaving this
/// as just a string that will be replaced.
/// </summary>
public class ReplaceFileContents : Task
@ -40,6 +40,11 @@ namespace Microsoft.DotNet.Cli.Build
public ITaskItem[] ReplacementStrings { get; set; }
/// <summary>
/// Gets or sets a string that a file must contain for the replacement to be performed.
/// </summary>
public string FileMustContainText { get; set; }
public override bool Execute()
{
if (ReplacementItems == null && ReplacementPatterns == null && ReplacementStrings == null)
@ -81,6 +86,12 @@ namespace Microsoft.DotNet.Cli.Build
public void ReplaceContents(string inputFile, string destinationFile)
{
string inputFileText = File.ReadAllText(inputFile);
if (!string.IsNullOrEmpty(FileMustContainText) && !inputFileText.Contains(FileMustContainText))
{
Log.LogMessage(MessageImportance.Low, $"Skipping replacement on `{inputFile}` because it does not contain the text '{FileMustContainText}'.");
return;
}
string outputFileText = ReplacePatterns(inputFileText);
WriteOutputFile(destinationFile, outputFileText);

View file

@ -403,15 +403,27 @@
<PropertyGroup>
<ReplacementPattern>"version": ".*"</ReplacementPattern>
<ReplacementString>"version": "$(MicrosoftNETCoreAppRuntimePackageVersion)"</ReplacementString>
<AspNetCoreRuntimeReplacementString>"version": "$(MicrosoftAspNetCoreAppRuntimePackageVersion)"</AspNetCoreRuntimeReplacementString>
</PropertyGroup>
<ItemGroup>
<ToolRuntimeConfigPath Include="$(RedistLayoutPath)sdk/$(Version)/**/*.runtimeconfig.json" />
</ItemGroup>
<!-- Update runtimeconfig files that target Microsoft.NETCore.App -->
<ReplaceFileContents
InputFiles="@(ToolRuntimeConfigPath)"
DestinationFiles="@(ToolRuntimeConfigPath)"
ReplacementPatterns="$(ReplacementPattern)"
ReplacementStrings="$(ReplacementString)" />
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 Name="GenerateVersionFile"