From 0c833f5349046a0048cb2a4e3a70e910892bde05 Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Wed, 2 Nov 2016 10:11:37 -0700 Subject: [PATCH 1/2] Making the default exclude option empty, so that by default, we don't set any excludes for compile or embed during migration. --- .../Rules/MigrateBuildOptionsRule.cs | 6 ++++-- .../Rules/GivenThatIWantToMigrateBuildOptions.cs | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs index b4e3510a1..d0160a223 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs @@ -130,6 +130,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules private Func> CopyToOutputFilesTransformExecute => (compilerOptions, projectDirectory) => CopyToOutputFilesTransform.Transform(GetCopyToOutputIncludeContext(compilerOptions, projectDirectory)); + + private readonly string[] DefaultEmptyExcludeOption = new string[0]; private readonly ProjectPropertyGroupElement _configurationPropertyGroup; private readonly ProjectItemGroupElement _configurationItemGroup; @@ -328,7 +330,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules "compile", new JObject(), ProjectFilesCollection.DefaultCompileBuiltInPatterns, - ProjectFilesCollection.DefaultBuiltInExcludePatterns); + DefaultEmptyExcludeOption); } private IncludeContext GetEmbedIncludeContext(CommonCompilerOptions compilerOptions, string projectDirectory) @@ -340,7 +342,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules "embed", new JObject(), ProjectFilesCollection.DefaultResourcesBuiltInPatterns, - ProjectFilesCollection.DefaultBuiltInExcludePatterns); + DefaultEmptyExcludeOption); } private IncludeContext GetCopyToOutputIncludeContext(CommonCompilerOptions compilerOptions, string projectDirectory) diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateBuildOptions.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateBuildOptions.cs index 122231849..0e9fffe6f 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateBuildOptions.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateBuildOptions.cs @@ -58,9 +58,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests mockProj.Items.Count().Should().Be(2); mockProj.Items.First(i => i.ItemType == "Compile").Include.Should().Be(@"**\*.cs"); - mockProj.Items.First(i => i.ItemType == "Compile").Exclude.Should().Be(@"bin\**;obj\**;**\*.xproj;packages\**"); + mockProj.Items.First(i => i.ItemType == "Compile").Exclude.Should().BeEmpty(); mockProj.Items.First(i => i.ItemType == "EmbeddedResource").Include.Should().Be(@"compiler\resources\**\*;**\*.resx"); - mockProj.Items.First(i => i.ItemType == "EmbeddedResource").Exclude.Should().Be(@"bin\**;obj\**;**\*.xproj;packages\**"); + mockProj.Items.First(i => i.ItemType == "EmbeddedResource").Exclude.Should().BeEmpty(); } [Fact] From 4e1f2f2b2027bfe0f192111a65c374eb0eef90f9 Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Wed, 2 Nov 2016 15:05:45 -0700 Subject: [PATCH 2/2] Removing TFM specific defines for migrated projects, since they are not being set in the SDK itself. --- .../ProjectReader.cs | 34 ------------------- .../GivenThatIWantToMigrateConfigurations.cs | 15 ++++++++ 2 files changed, 15 insertions(+), 34 deletions(-) diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/ProjectReader.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/ProjectReader.cs index c5b67bf17..d3ac59047 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/ProjectReader.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/ProjectReader.cs @@ -504,12 +504,6 @@ namespace Microsoft.DotNet.Internal.ProjectModel // Add the target framework specific define var defines = new HashSet(compilerOptions.Defines ?? Enumerable.Empty()); - var frameworkDefine = MakeDefaultTargetFrameworkDefine(frameworkName); - - if (!string.IsNullOrEmpty(frameworkDefine)) - { - defines.Add(frameworkDefine); - } compilerOptions.Defines = defines; @@ -806,34 +800,6 @@ namespace Microsoft.DotNet.Internal.ProjectModel return null; } - private static string MakeDefaultTargetFrameworkDefine(NuGetFramework targetFramework) - { - var shortName = targetFramework.GetTwoDigitShortFolderName(); - - if (targetFramework.IsPCL) - { - return null; - } - - var candidateName = shortName.ToUpperInvariant(); - - // Replace '-', '.', and '+' in the candidate name with '_' because TFMs with profiles use those (like "net40-client") - // and we want them representable as defines (i.e. "NET40_CLIENT") - candidateName = candidateName.Replace('-', '_').Replace('+', '_').Replace('.', '_'); - - // We require the following from our Target Framework Define names - // Starts with A-Z or _ - // Contains only A-Z, 0-9 and _ - if (!string.IsNullOrEmpty(candidateName) && - (char.IsLetter(candidateName[0]) || candidateName[0] == '_') && - candidateName.All(c => Char.IsLetterOrDigit(c) || c == '_')) - { - return candidateName; - } - - return null; - } - private static bool HasProjectFile(string path) { string projectPath = Path.Combine(path, Project.FileName); diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateConfigurations.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateConfigurations.cs index b5033280c..a287d7961 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateConfigurations.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateConfigurations.cs @@ -62,6 +62,21 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests .Contain("'$(TargetFramework)' == 'netcoreapp1.0'"); } + [Fact] + public void It_does_not_add_a_define_for_the_framework() + { + var mockProj = RunConfigurationsRuleOnPj(@" + { + ""frameworks"": { + ""netcoreapp1.0"": { + } + } + }"); + + mockProj.Properties.Count( + prop => prop.Name == "DefineConstants" && prop.Value.Contains("NETCOREAPP1_0")).Should().Be(0); + } + [Fact] public void Configuration_buildOptions_properties_are_not_written_when_they_overlap_with_buildOptions() {