From 71da7f6a458ba381e767fff51e1babc13a55ec3a Mon Sep 17 00:00:00 2001 From: Justin Goshi Date: Thu, 12 Jan 2017 11:22:41 -0800 Subject: [PATCH] Migration: do not inject built in compile includes that the SDK does --- .../Files/ProjectFilesCollection.cs | 15 +++++---------- .../ProjectReader.cs | 8 ++++---- .../Rules/MigrateBuildOptionsRule.cs | 8 ++++++-- .../transforms/IncludeContextTransform.cs | 16 ++++++++++++---- .../Rules/GivenThatIWantToMigrateBuildOptions.cs | 6 ++---- .../GivenThatIWantToMigratePublishOptions.cs | 4 ++-- 6 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/Files/ProjectFilesCollection.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/Files/ProjectFilesCollection.cs index d86083a27..ae5216faf 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/Files/ProjectFilesCollection.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/Files/ProjectFilesCollection.cs @@ -9,14 +9,9 @@ namespace Microsoft.DotNet.Internal.ProjectModel.Files { internal class ProjectFilesCollection { - public static readonly string[] DefaultCompileBuiltInPatterns = new[] { @"**/*.cs" }; + public static readonly string[] SdkInjectedDefaultCompileBuiltInPatterns = new[] { @"**/*.cs" }; public static readonly string[] DefaultPreprocessPatterns = new[] { @"compiler/preprocess/**/*.cs" }; public static readonly string[] DefaultSharedPatterns = new[] { @"compiler/shared/**/*.cs" }; - public static readonly string[] DefaultResourcesBuiltInPatterns = new[] { @"compiler/resources/**/*", "**/*.resx" }; - - public static readonly string[] DefaultPublishExcludePatterns = new string[0]; - public static readonly string[] DefaultContentsBuiltInPatterns = new string[0]; - public static readonly string[] DefaultBuiltInExcludePatterns = new[] { "bin/**", "obj/**", "**/*.xproj", "packages/**" }; public static readonly string PackIncludePropertyName = "packInclude"; @@ -53,11 +48,11 @@ namespace Microsoft.DotNet.Internal.ProjectModel.Files var excludeBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "excludeBuiltIn", DefaultBuiltInExcludePatterns); var excludePatterns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "exclude") .Concat(excludeBuiltIns); - var contentBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "contentBuiltIn", DefaultContentsBuiltInPatterns); - var compileBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "compileBuiltIn", DefaultCompileBuiltInPatterns); - var resourceBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "resourceBuiltIn", DefaultResourcesBuiltInPatterns); + var contentBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "contentBuiltIn"); + var compileBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "compileBuiltIn", SdkInjectedDefaultCompileBuiltInPatterns); + var resourceBuiltIns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "resourceBuiltIn"); - _publishExcludePatterns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "publishExclude", DefaultPublishExcludePatterns); + _publishExcludePatterns = PatternsCollectionHelper.GetPatternsCollection(_rawProject, _projectDirectory, _projectFilePath, "publishExclude"); _sharedPatternsGroup = PatternGroup.Build(_rawProject, _projectDirectory, _projectFilePath, "shared", fallbackIncluding: DefaultSharedPatterns, additionalExcluding: excludePatterns); 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 d3ac59047..57583883e 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/ProjectReader.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.Internal.ProjectModel/ProjectReader.cs @@ -664,20 +664,20 @@ namespace Microsoft.DotNet.Internal.ProjectModel project, rawOptions, "compile", - defaultBuiltInInclude: ProjectFilesCollection.DefaultCompileBuiltInPatterns, + defaultBuiltInInclude: ProjectFilesCollection.SdkInjectedDefaultCompileBuiltInPatterns, defaultBuiltInExclude: ProjectFilesCollection.DefaultBuiltInExcludePatterns), EmbedInclude = GetIncludeContext( project, rawOptions, "embed", - defaultBuiltInInclude: ProjectFilesCollection.DefaultResourcesBuiltInPatterns, + defaultBuiltInInclude: null, defaultBuiltInExclude: ProjectFilesCollection.DefaultBuiltInExcludePatterns), CopyToOutputInclude = GetIncludeContext( project, rawOptions, "copyToOutput", defaultBuiltInInclude: null, - defaultBuiltInExclude: ProjectFilesCollection.DefaultPublishExcludePatterns) + defaultBuiltInExclude: null) }; } @@ -794,7 +794,7 @@ namespace Microsoft.DotNet.Internal.ProjectModel "publishOptions", rawProject, defaultBuiltInInclude: null, - defaultBuiltInExclude: ProjectFilesCollection.DefaultPublishExcludePatterns); + defaultBuiltInExclude: null); } return null; diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs index bd6e5ad1d..c0e3b0201 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs @@ -111,7 +111,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules compilerOptions => compilerOptions.OutputName != null); private IncludeContextTransform CompileFilesTransform => - new IncludeContextTransform("Compile", transformMappings: false, condition: ic => ic != null); + new IncludeContextTransform( + "Compile", + transformMappings: false, + condition: ic => ic != null, + emitBuiltInIncludes: false); private IncludeContextTransform EmbedFilesTransform => new IncludeContextTransform("EmbeddedResource", transformMappings: false, condition: ic => ic != null); @@ -396,7 +400,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules "copyToOutput", new JObject(), null, - ProjectFilesCollection.DefaultPublishExcludePatterns); + null); } private string FormatLanguageVersion(string langVersion) diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/transforms/IncludeContextTransform.cs b/src/Microsoft.DotNet.ProjectJsonMigration/transforms/IncludeContextTransform.cs index 60db53fc2..65630c2da 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/transforms/IncludeContextTransform.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/transforms/IncludeContextTransform.cs @@ -30,8 +30,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms itemName, includeContext => { - var fullIncludeSet = includeContext.IncludePatterns.OrEmptyIfNull() - .Union(includeContext.BuiltInsInclude.OrEmptyIfNull()); + var fullIncludeSet = includeContext.IncludePatterns.OrEmptyIfNull(); + if (_emitBuiltInIncludes) + { + fullIncludeSet = fullIncludeSet.Union(includeContext.BuiltInsInclude.OrEmptyIfNull()); + } return FormatGlobPatternsForMsbuild(fullIncludeSet, includeContext.SourceBasePath); }, @@ -49,7 +52,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms ( (includeContext.IncludePatterns != null && includeContext.IncludePatterns.Count > 0) || - (includeContext.BuiltInsInclude != null && includeContext.BuiltInsInclude.Count > 0) + (_emitBuiltInIncludes && + includeContext.BuiltInsInclude != null && + includeContext.BuiltInsInclude.Count > 0) ); }); @@ -63,15 +68,18 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms private readonly string _itemName; private bool _transformMappings; + private bool _emitBuiltInIncludes; private readonly List> _metadata = new List>(); public IncludeContextTransform( string itemName, bool transformMappings = true, - Func condition = null) : base(condition) + Func condition = null, + bool emitBuiltInIncludes = true) : base(condition) { _itemName = itemName; _transformMappings = transformMappings; + _emitBuiltInIncludes = emitBuiltInIncludes; _mappingsToTransfrom = (addItemTransform, targetPath) => { diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateBuildOptions.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateBuildOptions.cs index 81d245811..50819632c 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateBuildOptions.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigrateBuildOptions.cs @@ -582,7 +582,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests private static IEnumerable GetDefaultExcludePatterns(string group) { var defaultExcludePatterns = new List(group == "copyToOutput" ? - ProjectFilesCollection.DefaultPublishExcludePatterns : + Enumerable.Empty() : ProjectFilesCollection.DefaultBuiltInExcludePatterns); if (group == "embed") @@ -595,9 +595,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests private static IEnumerable GetDefaultIncludePatterns(string group) { - return group == "compile" ? ProjectFilesCollection.DefaultCompileBuiltInPatterns - : group == "embed" ? ProjectFilesCollection.DefaultResourcesBuiltInPatterns - : Enumerable.Empty(); + return Enumerable.Empty(); } private static void VerifyContentMetadata(ProjectItemElement item) diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePublishOptions.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePublishOptions.cs index a50f785cb..4c70e90c4 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePublishOptions.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePublishOptions.cs @@ -130,7 +130,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests // From ProjectReader #L725 (Both are empty) var defaultIncludePatterns = Enumerable.Empty(); - var defaultExcludePatterns = ProjectFilesCollection.DefaultPublishExcludePatterns; + var defaultExcludePatterns = Enumerable.Empty(); foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals("Content", StringComparison.Ordinal))) { @@ -193,7 +193,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests // From ProjectReader #L725 (Both are empty) var defaultIncludePatterns = Enumerable.Empty(); - var defaultExcludePatterns = ProjectFilesCollection.DefaultPublishExcludePatterns; + var defaultExcludePatterns = Enumerable.Empty(); foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals("Content", StringComparison.Ordinal))) {