Show meaningful error when failing to migrate invalid scripts (#4842)
This commit is contained in:
parent
7312e1cb3a
commit
4af30914c9
3 changed files with 25 additions and 1 deletions
|
@ -31,6 +31,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
public static Func<string, MigrationError> MIGRATE1018
|
||||
=> (message) => new MigrationError(nameof(MIGRATE1018), "Dependency Project not found", message);
|
||||
|
||||
public static Func<string, MigrationError> MIGRATE1019
|
||||
=> (message) => new MigrationError(nameof(MIGRATE1019), "Unsupported Script Event Hook", message);
|
||||
|
||||
// Potentially Temporary (Point in Time) Errors
|
||||
public static Func<string, MigrationError> MIGRATE20011
|
||||
=> (message) => new MigrationError(nameof(MIGRATE20011), "Multi-TFM", message);
|
||||
|
|
|
@ -87,7 +87,14 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
|||
private ProjectTargetElement CreateTarget(ProjectRootElement csproj, string scriptSetName)
|
||||
{
|
||||
var targetName = $"{scriptSetName[0].ToString().ToUpper()}{string.Concat(scriptSetName.Skip(1))}Script";
|
||||
var targetHookInfo = ScriptSetToMSBuildHookTargetMap[scriptSetName];
|
||||
|
||||
TargetHookInfo targetHookInfo;
|
||||
if(!ScriptSetToMSBuildHookTargetMap.TryGetValue(scriptSetName, out targetHookInfo))
|
||||
{
|
||||
MigrationErrorCodes.MIGRATE1019(
|
||||
$"{scriptSetName} is an unsupported script event hook for project migration")
|
||||
.Throw();
|
||||
}
|
||||
|
||||
var target = csproj.CreateTargetElement(targetName);
|
||||
csproj.InsertBeforeChild(target, csproj.LastChild);
|
||||
|
|
|
@ -154,5 +154,19 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
var target = scriptMigrationRule.MigrateScriptSet(mockProj, mockProj.AddPropertyGroup(), commands, "prepublish");
|
||||
target.Condition.Should().Be(" '$(IsCrossTargetingBuild)' != 'true' ");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Migrating_scripts_throws_on_invalid_ScriptSet()
|
||||
{
|
||||
var scriptMigrationRule = new MigrateScriptsRule();
|
||||
ProjectRootElement mockProj = ProjectRootElement.Create();
|
||||
|
||||
var commands = new string[] { "fakecommand" };
|
||||
|
||||
Action action = () => scriptMigrationRule.MigrateScriptSet(mockProj, mockProj.AddPropertyGroup(), commands, "invalidScriptSet");
|
||||
|
||||
action.ShouldThrow<MigrationException>()
|
||||
.WithMessage("MIGRATE1019::Unsupported Script Event Hook: invalidScriptSet is an unsupported script event hook for project migration");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue