Removing the IsCrossTargetBuild from migrated scripts when there is only a single TFM
This commit is contained in:
parent
19b4bad315
commit
e9561b3679
2 changed files with 54 additions and 23 deletions
|
@ -28,16 +28,21 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
|
||||
foreach (var scriptSet in scripts)
|
||||
{
|
||||
MigrateScriptSet(csproj, migrationRuleInputs.CommonPropertyGroup, scriptSet.Value, scriptSet.Key);
|
||||
MigrateScriptSet(
|
||||
csproj,
|
||||
scriptSet.Value,
|
||||
scriptSet.Key,
|
||||
migrationRuleInputs.ProjectContexts.Count() > 1);
|
||||
}
|
||||
}
|
||||
|
||||
public ProjectTargetElement MigrateScriptSet(ProjectRootElement csproj,
|
||||
ProjectPropertyGroupElement propertyGroup,
|
||||
public ProjectTargetElement MigrateScriptSet(
|
||||
ProjectRootElement csproj,
|
||||
IEnumerable<string> scriptCommands,
|
||||
string scriptSetName)
|
||||
string scriptSetName,
|
||||
bool isMultiTFM)
|
||||
{
|
||||
var target = CreateTarget(csproj, scriptSetName);
|
||||
var target = CreateTarget(csproj, scriptSetName, isMultiTFM);
|
||||
foreach (var scriptCommand in scriptCommands)
|
||||
{
|
||||
if (CommandIsNotNeededInMSBuild(scriptCommand))
|
||||
|
@ -94,7 +99,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
return path.StartsWith("/") || path.Substring(1).StartsWith(":\\");
|
||||
}
|
||||
|
||||
private ProjectTargetElement CreateTarget(ProjectRootElement csproj, string scriptSetName)
|
||||
private ProjectTargetElement CreateTarget(ProjectRootElement csproj, string scriptSetName, bool isMultiTFM)
|
||||
{
|
||||
var targetName = $"{scriptSetName[0].ToString().ToUpper()}{string.Concat(scriptSetName.Skip(1))}Script";
|
||||
|
||||
|
@ -117,12 +122,19 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
target.AfterTargets = targetHookInfo.TargetName;
|
||||
}
|
||||
|
||||
// Run Scripts After each inner build
|
||||
target.Condition = " '$(IsCrossTargetingBuild)' != 'true' ";
|
||||
if (isMultiTFM)
|
||||
{
|
||||
ConditionTargetToRunScriptsAfterEachInnerBuild(target);
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
private void ConditionTargetToRunScriptsAfterEachInnerBuild(ProjectTargetElement target)
|
||||
{
|
||||
target.Condition = " '$(IsCrossTargetingBuild)' != 'true' ";
|
||||
}
|
||||
|
||||
private void AddExec(ProjectTargetElement target, string command)
|
||||
{
|
||||
var task = target.AddTask("Exec");
|
||||
|
|
|
@ -15,6 +15,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
{
|
||||
public class GivenThatIWantToMigrateScripts : TestBase
|
||||
{
|
||||
private const bool IsMultiTFM = true;
|
||||
|
||||
[Theory]
|
||||
[InlineData("compile:TargetFramework", "$(TargetFramework)")]
|
||||
[InlineData("publish:TargetFramework", "$(TargetFramework)")]
|
||||
|
@ -65,9 +67,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
|
||||
var target = scriptMigrationRule.MigrateScriptSet(
|
||||
mockProj,
|
||||
mockProj.AddPropertyGroup(),
|
||||
commands,
|
||||
scriptName);
|
||||
scriptName,
|
||||
IsMultiTFM);
|
||||
|
||||
target.BeforeTargets.Should().Be(targetName);
|
||||
}
|
||||
|
@ -85,9 +87,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
|
||||
var target = scriptMigrationRule.MigrateScriptSet(
|
||||
mockProj,
|
||||
mockProj.AddPropertyGroup(),
|
||||
commands,
|
||||
scriptName);
|
||||
scriptName,
|
||||
IsMultiTFM);
|
||||
|
||||
target.AfterTargets.Should().Be(targetName);
|
||||
}
|
||||
|
@ -107,9 +109,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
|
||||
var target = scriptMigrationRule.MigrateScriptSet(
|
||||
mockProj,
|
||||
mockProj.AddPropertyGroup(),
|
||||
commands,
|
||||
scriptName);
|
||||
scriptName,
|
||||
IsMultiTFM);
|
||||
|
||||
foreach (var task in target.Tasks)
|
||||
{
|
||||
|
@ -143,9 +145,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
|
||||
var target = scriptMigrationRule.MigrateScriptSet(
|
||||
mockProj,
|
||||
mockProj.AddPropertyGroup(),
|
||||
commands,
|
||||
scriptName);
|
||||
scriptName,
|
||||
IsMultiTFM);
|
||||
|
||||
target.Tasks.Count().Should().Be(commands.Length);
|
||||
|
||||
foreach (var task in target.Tasks)
|
||||
|
@ -172,9 +175,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
|
||||
var target = scriptMigrationRule.MigrateScriptSet(
|
||||
mockProj,
|
||||
mockProj.AddPropertyGroup(),
|
||||
commands,
|
||||
"postpublish");
|
||||
"postpublish",
|
||||
IsMultiTFM);
|
||||
target.Tasks.Should().BeEmpty();
|
||||
}
|
||||
|
||||
|
@ -186,7 +189,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void MigratingScriptsCreatesTargetWithIsCrossTargettingBuildNotEqualTrueCondition()
|
||||
public void MigratingScriptsWithMultiTFMCreatesTargetWithIsCrossTargettingBuildNotEqualTrueCondition()
|
||||
{
|
||||
var scriptMigrationRule = new MigrateScriptsRule();
|
||||
ProjectRootElement mockProj = ProjectRootElement.Create();
|
||||
|
@ -195,12 +198,28 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
|
||||
var target = scriptMigrationRule.MigrateScriptSet(
|
||||
mockProj,
|
||||
mockProj.AddPropertyGroup(),
|
||||
commands,
|
||||
"prepublish");
|
||||
"prepublish",
|
||||
IsMultiTFM);
|
||||
target.Condition.Should().Be(" '$(IsCrossTargetingBuild)' != 'true' ");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MigratingScriptsWithSingleTFMDoesNotCreateTargetWithIsCrossTargettingBuild()
|
||||
{
|
||||
var scriptMigrationRule = new MigrateScriptsRule();
|
||||
ProjectRootElement mockProj = ProjectRootElement.Create();
|
||||
|
||||
var commands = new[] { "compile:FullTargetFramework", "compile:Configuration"};
|
||||
|
||||
var target = scriptMigrationRule.MigrateScriptSet(
|
||||
mockProj,
|
||||
commands,
|
||||
"prepublish",
|
||||
false);
|
||||
target.Condition.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MigratingScriptsThrowsOnInvalidScriptSet()
|
||||
{
|
||||
|
@ -211,9 +230,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
|
||||
Action action = () => scriptMigrationRule.MigrateScriptSet(
|
||||
mockProj,
|
||||
mockProj.AddPropertyGroup(),
|
||||
commands,
|
||||
"invalidScriptSet");
|
||||
"invalidScriptSet",
|
||||
IsMultiTFM);
|
||||
|
||||
action.ShouldThrow<MigrationException>()
|
||||
.WithMessage("MIGRATE1019::Unsupported Script Event Hook: invalidScriptSet is an unsupported script event hook for project migration");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue