PR Feedback

This commit is contained in:
Bryan Thornbury 2016-09-16 16:37:48 -07:00
parent f295e16732
commit fe20698d81
5 changed files with 42 additions and 16 deletions

View file

@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.IO;
using Microsoft.Build.Construction;
namespace Microsoft.DotNet.ProjectJsonMigration.Rules
{
@ -14,7 +15,22 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
var outputProject = Path.Combine(migrationSettings.OutputDirectory, outputName + ".csproj");
CleanEmptyPropertyAndItemGroups(migrationRuleInputs.OutputMSBuildProject);
migrationRuleInputs.OutputMSBuildProject.Save(outputProject);
}
private void CleanEmptyPropertyAndItemGroups(ProjectRootElement msbuildProject)
{
foreach (var propertyGroup in msbuildProject.PropertyGroups)
{
propertyGroup.RemoveIfEmpty();
}
foreach (var itemGroup in msbuildProject.ItemGroups)
{
itemGroup.RemoveIfEmpty();
}
}
}
}

View file

@ -79,10 +79,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
}",
testDirectory: testDirectory);
Console.WriteLine(string.Join(";", mockProj.Items.Select(i => " ;; " + i.ItemType)));
Console.WriteLine(string.Join(";", mockProj.Items.Select(i => " ;; " + i.Include)));
Console.WriteLine(string.Join(";", mockProj.Items.Select(i => " ;; " + i.Exclude)));
mockProj.Items.Count(i => i.ItemType.Equals("Content", StringComparison.Ordinal)).Should().Be(3);
// From ProjectReader #L725 (Both are empty)

View file

@ -41,7 +41,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var migratedRuntimeOptionsPath = Path.Combine(projectDir, s_runtimeConfigFileName);
File.Exists(migratedRuntimeOptionsPath).Should().BeTrue();
Console.WriteLine(migratedRuntimeOptionsPath);
var migratedRuntimeOptionsContent = JObject.Parse(File.ReadAllText(migratedRuntimeOptionsPath));
JToken.DeepEquals(rawRuntimeOptions, migratedRuntimeOptionsContent).Should().BeTrue();

View file

@ -130,7 +130,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
foreach (var task in target.Tasks)
{
var taskCommand = task.GetParameter("Command");
Console.WriteLine("TASK: " + taskCommand);
var commandIndex = Array.IndexOf(commands, taskCommand);
commandIndex.Should().Be(-1, "Expected command array elements to be replaced by appropriate msbuild properties");

View file

@ -30,9 +30,14 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var projectContext = ProjectContext.Create(testDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
var mockProj = ProjectRootElement.Create();
var testSettings = new MigrationSettings(testDirectory, testDirectory, "1.0.0", mockProj);
var testInputs = new MigrationRuleInputs(new[] { projectContext }, mockProj, mockProj.AddItemGroup(), mockProj.AddPropertyGroup());
new MigrateTFMRule().Apply(testSettings, testInputs);
var migrationSettings = new MigrationSettings(testDirectory, testDirectory, "1.0.0", mockProj);
var migrationInputs = new MigrationRuleInputs(
new[] { projectContext },
mockProj,
mockProj.AddItemGroup(),
mockProj.AddPropertyGroup());
new MigrateTFMRule().Apply(migrationSettings, migrationInputs);
mockProj.Properties.Count(p => p.Name == "TargetFrameworkIdentifier").Should().Be(0);
mockProj.Properties.Count(p => p.Name == "TargetFrameworkVersion").Should().Be(0);
@ -48,12 +53,18 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var projectContext = ProjectContext.Create(testDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
var mockProj = ProjectRootElement.Create();
var testSettings = new MigrationSettings(testDirectory, testDirectory, "1.0.0", mockProj);
var testInputs = new MigrationRuleInputs(new[] { projectContext }, mockProj, mockProj.AddItemGroup(), mockProj.AddPropertyGroup());
new MigrateTFMRule().Apply(testSettings, testInputs);
var migrationSettings = new MigrationSettings(testDirectory, testDirectory, "1.0.0", mockProj);
var migrationInputs = new MigrationRuleInputs(
new[] { projectContext },
mockProj,
mockProj.AddItemGroup(),
mockProj.AddPropertyGroup());
new MigrateTFMRule().Apply(migrationSettings, migrationInputs);
mockProj.Properties.Count(p => p.Name == "TargetFrameworks").Should().Be(1);
mockProj.Properties.First(p => p.Name == "TargetFrameworks").Value.Should().Be("net20;net35;net40;net461;netstandard1.5");
mockProj.Properties.First(p => p.Name == "TargetFrameworks")
.Value.Should().Be("net20;net35;net40;net461;netstandard1.5");
}
public void Migrating_Single_TFM_project_Populates_TargetFrameworks_with_short_tfm()
@ -71,9 +82,14 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var mockProj = ProjectRootElement.Create();
// Run BuildOptionsRule
var testSettings = new MigrationSettings(testDirectory, testDirectory, "1.0.0", mockProj);
var testInputs = new MigrationRuleInputs(new[] { projectContext }, mockProj, mockProj.AddItemGroup(), mockProj.AddPropertyGroup());
new MigrateTFMRule().Apply(testSettings, testInputs);
var migrationSettings = new MigrationSettings(testDirectory, testDirectory, "1.0.0", mockProj);
var migrationInputs = new MigrationRuleInputs(
new[] { projectContext },
mockProj,
mockProj.AddItemGroup(),
mockProj.AddPropertyGroup());
new MigrateTFMRule().Apply(migrationSettings, migrationInputs);
mockProj.Properties.Count(p => p.Name == "TargetFrameworks").Should().Be(1);
mockProj.Properties.First(p => p.Name == "TargetFrameworks").Value.Should().Be("netcoreapp1.0");