From 000734d1ef05583277aee63ee2381045d71e77a5 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Fri, 20 Jan 2017 15:59:21 -0800 Subject: [PATCH] Ignore explicit glob **/*.cs --- .../TestAppWithExplicitIncludeGlob/Program.cs | 9 +++++++ .../project.json | 24 +++++++++++++++++++ .../Rules/MigrateBuildOptionsRule.cs | 5 ++++ .../transforms/IncludeContextTransform.cs | 22 +++++++++++++++-- .../GivenThatIWantToMigrateTestApps.cs | 15 ++++++++++++ 5 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 TestAssets/TestProjects/TestAppWithExplicitIncludeGlob/Program.cs create mode 100644 TestAssets/TestProjects/TestAppWithExplicitIncludeGlob/project.json diff --git a/TestAssets/TestProjects/TestAppWithExplicitIncludeGlob/Program.cs b/TestAssets/TestProjects/TestAppWithExplicitIncludeGlob/Program.cs new file mode 100644 index 000000000..5f9be2467 --- /dev/null +++ b/TestAssets/TestProjects/TestAppWithExplicitIncludeGlob/Program.cs @@ -0,0 +1,9 @@ +using System; + +class Program +{ + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } +} \ No newline at end of file diff --git a/TestAssets/TestProjects/TestAppWithExplicitIncludeGlob/project.json b/TestAssets/TestProjects/TestAppWithExplicitIncludeGlob/project.json new file mode 100644 index 000000000..67a885251 --- /dev/null +++ b/TestAssets/TestProjects/TestAppWithExplicitIncludeGlob/project.json @@ -0,0 +1,24 @@ +{ + "version": "1.0.0-*", + "buildOptions": { + "debugType": "portable", + "emitEntryPoint": true, + "compile": { + "include": [ + "**/*.cs" + ] + } + }, + "dependencies": {}, + "frameworks": { + "netcoreapp1.0": { + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.1" + } + }, + "imports": "dnxcore50" + } + } +} diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs index c0e3b0201..7b15bdf9e 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigrateBuildOptionsRule.cs @@ -110,10 +110,15 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules compilerOptions => projectFolderName, compilerOptions => compilerOptions.OutputName != null); + private string[] _compilePatternsBlackList = new string[] { + "**/*.cs" + }; + private IncludeContextTransform CompileFilesTransform => new IncludeContextTransform( "Compile", transformMappings: false, + patternsBlackList: _compilePatternsBlackList, condition: ic => ic != null, emitBuiltInIncludes: false); diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/transforms/IncludeContextTransform.cs b/src/Microsoft.DotNet.ProjectJsonMigration/transforms/IncludeContextTransform.cs index 65630c2da..06a82260d 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/transforms/IncludeContextTransform.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/transforms/IncludeContextTransform.cs @@ -25,6 +25,16 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms && includeContext.IncludeFiles != null && includeContext.IncludeFiles.Count > 0); + private bool IsPatternBlackListed(string pattern) + { + if (_patternsBlackList == null) + { + return false; + } + + return _patternsBlackList.Contains(pattern.Replace('\\', '/')); + } + protected virtual Func> IncludeExcludeTransformGetter => (itemName) => new AddItemTransform( itemName, @@ -36,6 +46,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms fullIncludeSet = fullIncludeSet.Union(includeContext.BuiltInsInclude.OrEmptyIfNull()); } + if (_patternsBlackList != null) + { + fullIncludeSet = fullIncludeSet.Where((pattern) => !IsPatternBlackListed(pattern)); + } + return FormatGlobPatternsForMsbuild(fullIncludeSet, includeContext.SourceBasePath); }, includeContext => @@ -50,7 +65,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms { return includeContext != null && ( - (includeContext.IncludePatterns != null && includeContext.IncludePatterns.Count > 0) + (includeContext.IncludePatterns != null && includeContext.IncludePatterns.Where((pattern) => !IsPatternBlackListed(pattern)).Count() > 0) || (_emitBuiltInIncludes && includeContext.BuiltInsInclude != null && @@ -68,6 +83,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms private readonly string _itemName; private bool _transformMappings; + private string[] _patternsBlackList; private bool _emitBuiltInIncludes; private readonly List> _metadata = new List>(); @@ -75,11 +91,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms string itemName, bool transformMappings = true, Func condition = null, - bool emitBuiltInIncludes = true) : base(condition) + bool emitBuiltInIncludes = true, + string[] patternsBlackList = null) : base(condition) { _itemName = itemName; _transformMappings = transformMappings; _emitBuiltInIncludes = emitBuiltInIncludes; + _patternsBlackList = patternsBlackList; _mappingsToTransfrom = (addItemTransform, targetPath) => { diff --git a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs index c569c6cc6..98e1f2169 100644 --- a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs +++ b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs @@ -640,6 +640,21 @@ namespace Microsoft.DotNet.Migration.Tests Restore(projectDirectory, projectName); BuildMSBuild(projectDirectory, projectName); } + + [Fact] + public void ItMigratesAndBuildsAppWithExplicitIncludeGlob() + { + const string projectName = "TestAppWithExplicitIncludeGlob"; + var projectDirectory = TestAssets.Get(projectName) + .CreateInstance() + .WithSourceFiles() + .Root + .FullName; + + MigrateProject(projectDirectory); + Restore(projectDirectory, projectName); + BuildMSBuild(projectDirectory, projectName); + } private void VerifyAutoInjectedDesktopReferences(DirectoryInfo projectDirectory, string projectName, bool shouldBePresent) {