remove autounify, fix langversion (#4387)

* remove autounify, fix langversion

* PR feedback
This commit is contained in:
Bryan Thornbury 2016-10-12 14:59:36 -07:00 committed by GitHub
parent 3ae14ab618
commit f79d78703b
6 changed files with 28 additions and 57 deletions

View file

@ -76,7 +76,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
private AddPropertyTransform<CommonCompilerOptions> LanguageVersionTransform =>
new AddPropertyTransform<CommonCompilerOptions>("LangVersion",
compilerOptions => compilerOptions.LanguageVersion,
compilerOptions => FormatLanguageVersion(compilerOptions.LanguageVersion),
compilerOptions => !string.IsNullOrEmpty(compilerOptions.LanguageVersion));
private AddPropertyTransform<CommonCompilerOptions> DelaySignTransform =>
@ -355,5 +355,15 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
null,
ProjectFilesCollection.DefaultPublishExcludePatterns);
}
private string FormatLanguageVersion(string langVersion)
{
if (langVersion.StartsWith("csharp", StringComparison.OrdinalIgnoreCase))
{
return langVersion.Substring("csharp".Length);
}
return langVersion;
}
}
}

View file

@ -56,7 +56,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
MigrationRuleInputs migrationRuleInputs)
{
var buildOptions = project.GetRawCompilerOptions(framework);
var configurationCondition = $" '$(TargetFrameworkIdentifier),Version=$(TargetFrameworkVersion)' == '{framework.DotNetFrameworkName}' ";
var configurationCondition = framework.GetMSBuildCondition();
MigrateConfiguration(buildOptions, configurationCondition, migrationSettings, migrationRuleInputs);
}

View file

@ -32,8 +32,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
var migratedXProjDependencyPaths = MigrateXProjProjectDependencies(migrationRuleInputs);
var migratedXProjDependencyNames = new HashSet<string>(migratedXProjDependencyPaths.Select(p => Path.GetFileNameWithoutExtension(
PathUtility.GetPathWithDirectorySeparator(p))));
AddPropertyTransformsToCommonPropertyGroup(migrationRuleInputs.CommonPropertyGroup);
MigrateProjectJsonProjectDependencies(
migrationRuleInputs.ProjectContexts,
migratedXProjDependencyNames,
@ -105,7 +103,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
{
if (targetFramework != null)
{
itemGroup.Condition = $" '$(TargetFrameworkIdentifier),Version=$(TargetFrameworkVersion)' == '{targetFramework.DotNetFrameworkName}' ";
itemGroup.Condition = targetFramework.GetMSBuildCondition();
}
foreach (var projectDependencyTransformResult in projectDependencyTransformResults)
@ -114,30 +112,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
}
}
private void AddPropertyTransformsToCommonPropertyGroup(ProjectPropertyGroupElement commonPropertyGroup)
{
var propertyTransformResults = new[]
{
AutoUnifyTransform.Transform(true),
DesignTimeAutoUnifyTransform.Transform(true)
};
foreach (var propertyTransformResult in propertyTransformResults)
{
_transformApplicator.Execute(propertyTransformResult, commonPropertyGroup);
}
}
private AddPropertyTransform<bool> AutoUnifyTransform => new AddPropertyTransform<bool>(
"AutoUnify",
"true",
b => true);
private AddPropertyTransform<bool> DesignTimeAutoUnifyTransform => new AddPropertyTransform<bool>(
"DesignTimeAutoUnify",
"true",
b => true);
private AddItemTransform<ProjectDependency> ProjectDependencyTransform => new AddItemTransform<ProjectDependency>(
"ProjectReference",
dep =>

View file

@ -239,6 +239,20 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
mockProj.Properties.First(p => p.Name == "LangVersion").Value.Should().Be("5");
}
[Fact]
public void Migrating_languageVersion_removes_csharp_in_LangVersion()
{
var mockProj = RunBuildOptionsRuleOnPj(@"
{
""buildOptions"": {
""languageVersion"": ""csharp5""
}
}");
mockProj.Properties.Count(p => p.Name == "LangVersion").Should().Be(1);
mockProj.Properties.First(p => p.Name == "LangVersion").Value.Should().Be("5");
}
[Fact]
public void Migrating_keyFile_populates_AssemblyOriginatorKeyFile_and_SignAssembly()
{

View file

@ -59,7 +59,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
mockProj.Properties.First(p => p.Name == "OutputType")
.Parent.Condition.Should()
.Contain("'$(TargetFrameworkIdentifier),Version=$(TargetFrameworkVersion)' == '.NETCoreApp,Version=v1.0'");
.Contain("'$(TargetFramework)' == 'netcoreapp1.0'");
}
[Fact]

View file

@ -16,33 +16,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{
public class GivenThatIWantToMigrateProjectDependencies : TestBase
{
// Workaround For P2P dependencies
// ISSUE: https://github.com/dotnet/sdk/issues/73
[Fact]
public void If_a_project_dependency_is_present_DesignTimeAutoUnify_and_AutoUnify_are_present()
{
var solutionDirectory =
TestAssetsManager.CreateTestInstance("TestAppWithLibrary", callingMethod: "p").Path;
var appDirectory = Path.Combine(solutionDirectory, "TestApp");
var libDirectory = Path.Combine(solutionDirectory, "TestLibrary");
var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
var mockProj = ProjectRootElement.Create();
var testSettings = new MigrationSettings(appDirectory, appDirectory, "1.0.0", mockProj);
var testInputs = new MigrationRuleInputs(new[] {projectContext}, mockProj, mockProj.AddItemGroup(),
mockProj.AddPropertyGroup());
new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);
var autoUnify = mockProj.Properties.Where(p => p.Name == "AutoUnify");
autoUnify.Count().Should().Be(1);
autoUnify.First().Value.Should().Be("true");
var designTimeAutoUnify = mockProj.Properties.Where(p => p.Name == "DesignTimeAutoUnify");
designTimeAutoUnify.Count().Should().Be(1);
designTimeAutoUnify.First().Value.Should().Be("true");
}
[Fact]
public void Project_dependencies_are_migrated_to_ProjectReference()
{