Add support for migrating Microsoft.AspNetCore.Mvc.ViewCompilation

This commit is contained in:
Pranav K 2017-01-11 16:51:45 -08:00 committed by Livar Cunha
parent c9216f93ef
commit 80c435e6a1
4 changed files with 79 additions and 0 deletions

View file

@ -23,6 +23,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
{
var csproj = migrationRuleInputs.OutputMSBuildProject;
var commonPropertyGroup = migrationRuleInputs.CommonPropertyGroup;
var projectContext = migrationRuleInputs.DefaultProjectContext;
var scripts = projectContext.ProjectFile.Scripts;
@ -30,6 +31,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
{
MigrateScriptSet(
csproj,
commonPropertyGroup,
scriptSet.Value,
scriptSet.Key,
migrationRuleInputs.IsMultiTFM);
@ -38,6 +40,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
public ProjectTargetElement MigrateScriptSet(
ProjectRootElement csproj,
ProjectPropertyGroupElement commonPropertyGroup,
IEnumerable<string> scriptCommands,
string scriptSetName,
bool isMultiTFM)
@ -49,6 +52,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
{
continue;
}
else if (IsRazorPrecompilationCommand(scriptCommand))
{
EnableRazorCompilationOnPublish(commonPropertyGroup);
continue;
}
AddExec(target, FormatScriptCommand(scriptCommand));
}
@ -94,6 +102,16 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
return command.Contains("dotnet publish-iis");
}
private static bool IsRazorPrecompilationCommand(string command)
{
return command.Contains("dotnet razor-precompile");
}
private static void EnableRazorCompilationOnPublish(ProjectPropertyGroupElement commonPropertyGroup)
{
commonPropertyGroup.AddProperty("MvcRazorCompileOnPublish", "true");
}
private bool IsPathRootedForAnyOS(string path)
{
return path.StartsWith("/") || path.Substring(1).StartsWith(":\\");

View file

@ -51,6 +51,14 @@ namespace Microsoft.DotNet.ProjectJsonMigration
},
null
},
{
new PackageDependencyInfo
{
Name = "Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Tools",
Version = "[1.0.0-*,)"
},
null
},
{
new PackageDependencyInfo
{
@ -159,6 +167,17 @@ namespace Microsoft.DotNet.ProjectJsonMigration
Version = ConstantPackageVersions.AspNetToolsVersion
}
},
{
new PackageDependencyInfo
{
Name = "Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Design",
Version = "[1.0.0-*,)"
},
new PackageDependencyInfo {
Name = "Microsoft.AspNetCore.Mvc.Razor.ViewCompilation",
Version = ConstantPackageVersions.AspNet110ToolsVersion
}
},
{
new PackageDependencyInfo
{

View file

@ -63,10 +63,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{
var scriptMigrationRule = new MigrateScriptsRule();
ProjectRootElement mockProj = ProjectRootElement.Create();
ProjectPropertyGroupElement commonPropertyGroup = mockProj.AddPropertyGroup();
var commands = new string[] { "fakecommand" };
var target = scriptMigrationRule.MigrateScriptSet(
mockProj,
commonPropertyGroup,
commands,
scriptName,
IsMultiTFM);
@ -83,10 +86,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{
var scriptMigrationRule = new MigrateScriptsRule();
ProjectRootElement mockProj = ProjectRootElement.Create();
ProjectPropertyGroupElement commonPropertyGroup = mockProj.AddPropertyGroup();
var commands = new[] { "fakecommand" };
var target = scriptMigrationRule.MigrateScriptSet(
mockProj,
commonPropertyGroup,
commands,
scriptName,
IsMultiTFM);
@ -103,12 +108,14 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{
var scriptMigrationRule = new MigrateScriptsRule();
ProjectRootElement mockProj = ProjectRootElement.Create();
ProjectPropertyGroupElement commonPropertyGroup = mockProj.AddPropertyGroup();
var commands = new[] { "fakecommand1", "fakecommand2", "mockcommand3" };
var commandsInTask = commands.ToDictionary(c => c, c => false);
var target = scriptMigrationRule.MigrateScriptSet(
mockProj,
commonPropertyGroup,
commands,
scriptName,
IsMultiTFM);
@ -140,11 +147,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{
var scriptMigrationRule = new MigrateScriptsRule();
ProjectRootElement mockProj = ProjectRootElement.Create();
ProjectPropertyGroupElement commonPropertyGroup = mockProj.AddPropertyGroup();
var commands = new[] { "%compile:FullTargetFramework%", "%compile:Configuration%"};
var target = scriptMigrationRule.MigrateScriptSet(
mockProj,
commonPropertyGroup,
commands,
scriptName,
IsMultiTFM);
@ -167,6 +176,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{
var scriptMigrationRule = new MigrateScriptsRule();
ProjectRootElement mockProj = ProjectRootElement.Create();
ProjectPropertyGroupElement commonPropertyGroup = mockProj.AddPropertyGroup();
var commands = new[]
{
@ -175,12 +185,36 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var target = scriptMigrationRule.MigrateScriptSet(
mockProj,
commonPropertyGroup,
commands,
"postpublish",
IsMultiTFM);
target.Tasks.Should().BeEmpty();
}
[Fact]
public void MigratingScriptsReplacesRazorPrecompileWithProperty()
{
var scriptMigrationRule = new MigrateScriptsRule();
ProjectRootElement mockProj = ProjectRootElement.Create();
ProjectPropertyGroupElement commonPropertyGroup = mockProj.AddPropertyGroup();
var commands = new string[] { "dotnet razor-precompile --configuration %publish:Configuration% --framework %publish:TargetFramework% --output-path %publish:OutputPath% %publish:ProjectPath%" };
var target = scriptMigrationRule.MigrateScriptSet(
mockProj,
commonPropertyGroup,
commands,
"postpublish",
IsMultiTFM);
target.Tasks.Should().BeEmpty();
commonPropertyGroup.Properties.Count().Should().Be(1);
var propertyElement = commonPropertyGroup.Properties.First();
propertyElement.Name.Should().Be("MvcRazorCompileOnPublish");
propertyElement.Value.Should().Be("true");
}
[Fact]
public void FormattingScriptCommandsReplacesUnknownVariablesWithMSBuildPropertyForEnvironmentVariableSupport()
{
@ -193,11 +227,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{
var scriptMigrationRule = new MigrateScriptsRule();
ProjectRootElement mockProj = ProjectRootElement.Create();
ProjectPropertyGroupElement commonPropertyGroup = mockProj.AddPropertyGroup();
var commands = new[] { "compile:FullTargetFramework", "compile:Configuration"};
var target = scriptMigrationRule.MigrateScriptSet(
mockProj,
commonPropertyGroup,
commands,
"prepublish",
IsMultiTFM);
@ -209,11 +245,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{
var scriptMigrationRule = new MigrateScriptsRule();
ProjectRootElement mockProj = ProjectRootElement.Create();
ProjectPropertyGroupElement commonPropertyGroup = mockProj.AddPropertyGroup();
var commands = new[] { "compile:FullTargetFramework", "compile:Configuration"};
var target = scriptMigrationRule.MigrateScriptSet(
mockProj,
commonPropertyGroup,
commands,
"prepublish",
false);
@ -225,11 +263,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{
var scriptMigrationRule = new MigrateScriptsRule();
ProjectRootElement mockProj = ProjectRootElement.Create();
ProjectPropertyGroupElement commonPropertyGroup = mockProj.AddPropertyGroup();
var commands = new string[] { "fakecommand" };
Action action = () => scriptMigrationRule.MigrateScriptSet(
mockProj,
commonPropertyGroup,
commands,
"invalidScriptSet",
IsMultiTFM);

View file

@ -18,6 +18,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
[InlineData("Microsoft.VisualStudio.Web.CodeGenerators.Mvc", "1.0.1", "Microsoft.VisualStudio.Web.CodeGeneration.Design", ConstantPackageVersions.AspNetToolsVersion)]
[InlineData("Microsoft.VisualStudio.Web.CodeGenerators.Mvc", "1.0.0-preview3-final", "Microsoft.VisualStudio.Web.CodeGeneration.Design", ConstantPackageVersions.AspNetToolsVersion)]
[InlineData("Microsoft.VisualStudio.Web.CodeGenerators.Mvc", "1.1.0-preview4-final", "Microsoft.VisualStudio.Web.CodeGeneration.Design", ConstantPackageVersions.AspNet110ToolsVersion)]
[InlineData("Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Design", "1.1.0-preview4-final", "Microsoft.AspNetCore.Mvc.Razor.ViewCompilation", ConstantPackageVersions.AspNet110ToolsVersion)]
public void ItMigratesProjectDependenciesToANewNameAndVersion(
string sourceToolName,
string sourceVersion,
@ -77,6 +78,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
[Theory]
[InlineData("Microsoft.AspNetCore.Razor.Tools")]
[InlineData("Microsoft.AspNetCore.Server.IISIntegration.Tools")]
[InlineData("Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Tools")]
public void ItDoesNotMigrateAspProjectTool(string toolName)
{
var mockProj = RunPackageDependenciesRuleOnPj(@"