Merge branch 'rel/1.0.1' into Merge100To101
This commit is contained in:
commit
8fc6766785
2 changed files with 26 additions and 5 deletions
|
@ -45,8 +45,7 @@
|
||||||
<ReplaceFileContents
|
<ReplaceFileContents
|
||||||
InputFile="$(DebianConfigTemplateFile)"
|
InputFile="$(DebianConfigTemplateFile)"
|
||||||
DestinationFile="$(DebianConfigJsonFile)"
|
DestinationFile="$(DebianConfigJsonFile)"
|
||||||
ReplacementPatterns="@(DebianConfigTokenValues -> '%(Identity)')"
|
ReplacementItems="@(DebianConfigTokenValues)" />
|
||||||
ReplacementStrings="@(DebianConfigTokenValues -> '%(ReplacementString)')" />
|
|
||||||
|
|
||||||
<!-- Build SDK Deb package -->
|
<!-- Build SDK Deb package -->
|
||||||
<DotNetDebTool ToolPath="$(Stage0Directory)"
|
<DotNetDebTool ToolPath="$(Stage0Directory)"
|
||||||
|
|
|
@ -9,7 +9,12 @@ using Microsoft.Build.Framework;
|
||||||
namespace Microsoft.DotNet.Cli.Build
|
namespace Microsoft.DotNet.Cli.Build
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads contents of an input file, and searches for each ReplacementPattern passed in.
|
/// 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.
|
/// item in ReplacementStrings.
|
||||||
///
|
///
|
||||||
|
@ -27,14 +32,23 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
[Required]
|
[Required]
|
||||||
public string DestinationFile { get; set; }
|
public string DestinationFile { get; set; }
|
||||||
|
|
||||||
[Required]
|
public ITaskItem[] ReplacementItems { get; set; }
|
||||||
|
|
||||||
public ITaskItem[] ReplacementPatterns { get; set; }
|
public ITaskItem[] ReplacementPatterns { get; set; }
|
||||||
|
|
||||||
[Required]
|
|
||||||
public ITaskItem[] ReplacementStrings { get; set; }
|
public ITaskItem[] ReplacementStrings { get; set; }
|
||||||
|
|
||||||
public override bool Execute()
|
public override bool Execute()
|
||||||
{
|
{
|
||||||
|
if (ReplacementItems == null && ReplacementPatterns == null && ReplacementStrings == null)
|
||||||
|
{
|
||||||
|
throw new Exception($"ReplaceFileContents was called with no replacement values. Either pass ReplacementItems or ReplacementPatterns/ReplacementStrings properties.");
|
||||||
|
}
|
||||||
|
|
||||||
|
ReplacementItems = ReplacementItems ?? Array.Empty<ITaskItem>();
|
||||||
|
ReplacementPatterns = ReplacementPatterns ?? Array.Empty<ITaskItem>();
|
||||||
|
ReplacementStrings = ReplacementStrings ?? Array.Empty<ITaskItem>();
|
||||||
|
|
||||||
if (ReplacementPatterns.Length != ReplacementStrings.Length)
|
if (ReplacementPatterns.Length != ReplacementStrings.Length)
|
||||||
{
|
{
|
||||||
throw new Exception($"Expected {nameof(ReplacementPatterns)} (length {ReplacementPatterns.Length}) and {nameof(ReplacementStrings)} (length {ReplacementStrings.Length}) to have the same length.");
|
throw new Exception($"Expected {nameof(ReplacementPatterns)} (length {ReplacementPatterns.Length}) and {nameof(ReplacementStrings)} (length {ReplacementStrings.Length}) to have the same length.");
|
||||||
|
@ -57,6 +71,14 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
{
|
{
|
||||||
var outText = inputFileText;
|
var outText = inputFileText;
|
||||||
|
|
||||||
|
foreach (var replacementItem in ReplacementItems)
|
||||||
|
{
|
||||||
|
var replacementPattern = replacementItem.ItemSpec;
|
||||||
|
var replacementString = replacementItem.GetMetadata("ReplacementString");
|
||||||
|
|
||||||
|
outText = outText.Replace(replacementPattern, replacementString);
|
||||||
|
}
|
||||||
|
|
||||||
for (int i=0; i<ReplacementPatterns.Length; ++i)
|
for (int i=0; i<ReplacementPatterns.Length; ++i)
|
||||||
{
|
{
|
||||||
var replacementPattern = ReplacementPatterns[i].ItemSpec;
|
var replacementPattern = ReplacementPatterns[i].ItemSpec;
|
||||||
|
|
Loading…
Reference in a new issue