diff --git a/TestAssets/NonRestoredTestProjects/PJDeprecatedContent/ContentFile1.txt b/TestAssets/NonRestoredTestProjects/PJDeprecatedContent/project/ContentFile1.txt1 similarity index 100% rename from TestAssets/NonRestoredTestProjects/PJDeprecatedContent/ContentFile1.txt rename to TestAssets/NonRestoredTestProjects/PJDeprecatedContent/project/ContentFile1.txt1 diff --git a/TestAssets/NonRestoredTestProjects/PJDeprecatedContent/ContentFile2.txt b/TestAssets/NonRestoredTestProjects/PJDeprecatedContent/project/ContentFile2.txt1 similarity index 100% rename from TestAssets/NonRestoredTestProjects/PJDeprecatedContent/ContentFile2.txt rename to TestAssets/NonRestoredTestProjects/PJDeprecatedContent/project/ContentFile2.txt1 diff --git a/TestAssets/NonRestoredTestProjects/PJDeprecatedContent/ContentFileBuiltIn1.txt b/TestAssets/NonRestoredTestProjects/PJDeprecatedContent/project/ContentFileBuiltIn1.txt1 similarity index 100% rename from TestAssets/NonRestoredTestProjects/PJDeprecatedContent/ContentFileBuiltIn1.txt rename to TestAssets/NonRestoredTestProjects/PJDeprecatedContent/project/ContentFileBuiltIn1.txt1 diff --git a/TestAssets/NonRestoredTestProjects/PJDeprecatedContent/ContentFileBuiltIn2.txt b/TestAssets/NonRestoredTestProjects/PJDeprecatedContent/project/ContentFileBuiltIn2.txt1 similarity index 100% rename from TestAssets/NonRestoredTestProjects/PJDeprecatedContent/ContentFileBuiltIn2.txt rename to TestAssets/NonRestoredTestProjects/PJDeprecatedContent/project/ContentFileBuiltIn2.txt1 diff --git a/TestAssets/NonRestoredTestProjects/PJDeprecatedContent/project/project.json b/TestAssets/NonRestoredTestProjects/PJDeprecatedContent/project/project.json index bf61a22e2..5b1681989 100644 --- a/TestAssets/NonRestoredTestProjects/PJDeprecatedContent/project/project.json +++ b/TestAssets/NonRestoredTestProjects/PJDeprecatedContent/project/project.json @@ -2,8 +2,8 @@ "version": "1.0.0-*", "content": "*.txt", "contentExclude": "ExcludeThis1.txt", - "contentFiles": [ "../ContentFile1.txt", "../ContentFile2.txt" ], - "contentBuiltIn": [ "../ContentFileBuiltIn1.txt", "../ContentFileBuiltIn2.txt" ], + "contentFiles": [ "ContentFile1.txt1", "ContentFile2.txt1" ], + "contentBuiltIn": [ "ContentFileBuiltIn1.txt1", "ContentFileBuiltIn2.txt1" ], "publishExclude": "ExcludeThis2.txt", "buildOptions": { "debugType": "portable", diff --git a/TestAssets/TestProjects/ProjectJsonWebTemplate/project.json b/TestAssets/TestProjects/ProjectJsonWebTemplate/project.json index 7da844f6d..35b616f8a 100644 --- a/TestAssets/TestProjects/ProjectJsonWebTemplate/project.json +++ b/TestAssets/TestProjects/ProjectJsonWebTemplate/project.json @@ -97,7 +97,8 @@ "wwwroot", "**/*.cshtml", "appsettings.json", - "web.config" + "web.config", + "README.md" ] }, diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackOptionsRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackOptionsRule.cs index d68186808..08ce03541 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackOptionsRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackOptionsRule.cs @@ -62,8 +62,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules .WithMappingsToTransform(_mappingsToTransfrom); private IncludeContextTransform DoNotPackFilesTransform => - new UpdateContextTransform("None", transformMappings: true) - .WithMetadata("Pack", "false"); + new UpdateContextTransform( + "None", + transformMappings: true, + excludePatternsRule: pattern => ProjectFilesCollection.DefaultBuiltInExcludePatterns.Contains(pattern)) + .WithMetadata("Pack", "false"); private Func, string, AddItemTransform> _mappingsToTransfrom => (addItemTransform, targetPath) => diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePublishOptionsRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePublishOptionsRule.cs index 17f894bc8..fe35c1397 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePublishOptionsRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePublishOptionsRule.cs @@ -36,15 +36,18 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules projectContext.ProjectFile.PublishOptions, migrationRuleInputs); - ExecuteTransformation( - DoNotCopyToPublishDirectoryTransform, - new ExcludeContext( - projectContext.ProjectFile.PublishOptions.SourceBasePath, - projectContext.ProjectFile.PublishOptions.Option, - projectContext.ProjectFile.PublishOptions.RawObject, - projectContext.ProjectFile.PublishOptions.BuiltInsInclude?.ToArray(), - projectContext.ProjectFile.PublishOptions.BuiltInsExclude?.ToArray()), - migrationRuleInputs); + if (projectContext.ProjectFile.PublishOptions != null) + { + ExecuteTransformation( + DoNotCopyToPublishDirectoryTransform, + new ExcludeContext( + projectContext.ProjectFile.PublishOptions.SourceBasePath, + projectContext.ProjectFile.PublishOptions.Option, + projectContext.ProjectFile.PublishOptions.RawObject, + projectContext.ProjectFile.PublishOptions.BuiltInsInclude?.ToArray(), + projectContext.ProjectFile.PublishOptions.BuiltInsExclude?.ToArray()), + migrationRuleInputs); + } } private void ExecuteTransformation( diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackOptions.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackOptions.cs index e4636910d..7c20923e2 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackOptions.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackOptions.cs @@ -220,6 +220,20 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests } }"); + foreach (var item in mockProj.Items.Where(i => i.ItemType.Equals("None", StringComparison.Ordinal))) + { + Console.WriteLine($"Update: {item.Update}, Include: {item.Include}, Remove: {item.Remove}"); + foreach(var meta in item.Metadata) + { + Console.WriteLine($"\tMetadata: Name: {meta.Name}, Value: {meta.Value}"); + } + + foreach(var condition in item.ConditionChain()) + { + Console.WriteLine($"\tCondition: {condition}"); + } + } + var contentItemsToInclude = mockProj.Items .Where(item => item.ItemType.Equals("None", StringComparison.Ordinal)) .Where(item => item.GetMetadataWithName("Pack").Value == "true"); @@ -231,8 +245,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests .Where(item => item.ItemType.Equals("None", StringComparison.Ordinal)) .Where(item => item.GetMetadataWithName("Pack").Value == "false"); - contentItemsToInclude.Count().Should().Be(1); - contentItemsToInclude.First().Update.Should().Be(@"path\to\file\to\exclude.cs"); + contentItemsToExclude.Count().Should().Be(1); + contentItemsToExclude.First().Update.Should().Be(@"path\to\file\to\exclude.cs"); } [Fact] diff --git a/test/dotnet-migrate.Tests/GivenThatIWantMigratedAppsToBinplaceContent.cs b/test/dotnet-migrate.Tests/GivenThatIWantMigratedAppsToBinplaceContent.cs new file mode 100644 index 000000000..00dfbec1d --- /dev/null +++ b/test/dotnet-migrate.Tests/GivenThatIWantMigratedAppsToBinplaceContent.cs @@ -0,0 +1,127 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.Build.Construction; +using Microsoft.DotNet.TestFramework; +using Microsoft.DotNet.Tools.Common; +using Microsoft.DotNet.Tools.Test.Utilities; +using System; +using System.Collections.Generic; +using System.Linq; +using Xunit; +using FluentAssertions; +using System.IO; +using Microsoft.DotNet.Tools.Migrate; +using BuildCommand = Microsoft.DotNet.Tools.Test.Utilities.BuildCommand; +using System.Runtime.Loader; +using Newtonsoft.Json.Linq; + +using MigrateCommand = Microsoft.DotNet.Tools.Migrate.MigrateCommand; + +namespace Microsoft.DotNet.Migration.Tests +{ + public class GivenThatIWantMigratedAppsToBinplaceContent : TestBase + { + [Fact] + public void ItBinplacesContentOnBuildForConsoleApps() + { + var projectDirectory = TestAssets + .GetProjectJson("TestAppWithContents") + .CreateInstance() + .WithSourceFiles() + .WithRestoreFiles() + .WithEmptyGlobalJson() + .Root; + + new TestCommand("dotnet") + .WithForwardingToConsole() + .Execute($"migrate {projectDirectory.FullName}") + .Should() + .Pass(); + + var command = new RestoreCommand() + .WithWorkingDirectory(projectDirectory) + .Execute() + .Should() + .Pass(); + + var result = new BuildCommand() + .WithWorkingDirectory(projectDirectory) + .ExecuteWithCapturedOutput() + .Should() + .Pass(); + + var outputDir = projectDirectory.GetDirectory("bin", "Debug", "netcoreapp1.0"); + outputDir.Should().Exist().And.HaveFile("testcontentfile.txt"); + outputDir.GetDirectory("dir").Should().Exist().And.HaveFile("mappingfile.txt"); + } + + [Fact] + public void ItBinplacesContentOnPublishForConsoleApps() + { + var projectDirectory = TestAssets + .GetProjectJson("TestAppWithContents") + .CreateInstance() + .WithSourceFiles() + .WithRestoreFiles() + .WithEmptyGlobalJson() + .Root; + + new TestCommand("dotnet") + .WithForwardingToConsole() + .Execute($"migrate {projectDirectory.FullName}") + .Should() + .Pass(); + + var command = new RestoreCommand() + .WithWorkingDirectory(projectDirectory) + .Execute() + .Should() + .Pass(); + + var result = new PublishCommand() + .WithWorkingDirectory(projectDirectory) + .ExecuteWithCapturedOutput() + .Should() + .Pass(); + + var publishDir = projectDirectory.GetDirectory("bin", "Debug", "netcoreapp1.0", "publish"); + publishDir.Should().Exist().And.HaveFile("testcontentfile.txt"); + publishDir.GetDirectory("dir").Should().Exist().And.HaveFile("mappingfile.txt"); + } + + [Fact] + public void ItBinplacesContentOnPublishForWebApps() + { + var projectDirectory = TestAssets + .GetProjectJson("ProjectJsonWebTemplate") + .CreateInstance() + .WithSourceFiles() + .WithRestoreFiles() + .WithEmptyGlobalJson() + .Root; + + new TestCommand("dotnet") + .WithForwardingToConsole() + .Execute($"migrate {projectDirectory.FullName}") + .Should() + .Pass(); + + var command = new RestoreCommand() + .WithWorkingDirectory(projectDirectory) + .Execute() + .Should() + .Pass(); + + var result = new PublishCommand() + .WithWorkingDirectory(projectDirectory) + .ExecuteWithCapturedOutput() + .Should() + .Pass(); + + var publishDir = projectDirectory.GetDirectory("bin", "Debug", "netcoreapp1.0", "publish"); + publishDir.Should().Exist().And.HaveFile("README.md"); + publishDir.GetDirectory("wwwroot").Should().Exist(); + } + } +} \ No newline at end of file diff --git a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateDeprecatedProjects.cs b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateDeprecatedProjects.cs index 5c6813bc8..d0270321f 100644 --- a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateDeprecatedProjects.cs +++ b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateDeprecatedProjects.cs @@ -224,10 +224,10 @@ namespace Microsoft.DotNet.Migration.Tests outputDir.Should().Exist() .And.HaveFiles(new[] { - "ContentFile1.txt", - "ContentFile2.txt", - "ContentFileBuiltIn1.txt", - "ContentFileBuiltIn2.txt", + "ContentFile1.txt1", + "ContentFile2.txt1", + "ContentFileBuiltIn1.txt1", + "ContentFileBuiltIn2.txt1", "IncludeThis.txt", }); Directory.Exists(Path.Combine(outputDir.FullName, "ExcludeThis1.txt")).Should().BeFalse(); @@ -237,10 +237,10 @@ namespace Microsoft.DotNet.Migration.Tests publishDir.Should().Exist() .And.HaveFiles(new[] { - "ContentFile1.txt", - "ContentFile2.txt", - "ContentFileBuiltIn1.txt", - "ContentFileBuiltIn2.txt", + "ContentFile1.txt1", + "ContentFile2.txt1", + "ContentFileBuiltIn1.txt1", + "ContentFileBuiltIn2.txt1", "IncludeThis.txt", }); Directory.Exists(Path.Combine(publishDir.FullName, "ExcludeThis1.txt")).Should().BeFalse();