diff --git a/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedCompileExcludeOptions/ExcludeThis.cs b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedCompileExcludeOptions/ExcludeThis1.cs similarity index 100% rename from TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedCompileExcludeOptions/ExcludeThis.cs rename to TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedCompileExcludeOptions/ExcludeThis1.cs diff --git a/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedCompileExcludeOptions/ExcludeThis2.cs b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedCompileExcludeOptions/ExcludeThis2.cs new file mode 100644 index 000000000..c8ee6c75e --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedCompileExcludeOptions/ExcludeThis2.cs @@ -0,0 +1 @@ +This does not compile but is used to test compile exclusion. diff --git a/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedCompileExcludeOptions/project.json b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedCompileExcludeOptions/project.json index 5c81a68c2..3b457a6dc 100644 --- a/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedCompileExcludeOptions/project.json +++ b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedCompileExcludeOptions/project.json @@ -1,6 +1,7 @@ { "version": "1.0.0-*", - "compileExclude": "ExcludeThis.cs", + "compileExclude": "ExcludeThis1.cs", + "exclude": [ "ExcludeThis2.cs" ], "buildOptions": { "debugType": "portable", "emitEntryPoint": true diff --git a/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceBuiltInOptions/Strings1.resx b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceBuiltInOptions/Strings1.resx new file mode 100644 index 000000000..1f24a372f --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceBuiltInOptions/Strings1.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Hello World! + + \ No newline at end of file diff --git a/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceBuiltInOptions/Strings2.resx b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceBuiltInOptions/Strings2.resx new file mode 100644 index 000000000..1f24a372f --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceBuiltInOptions/Strings2.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Hello World! + + \ No newline at end of file diff --git a/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceBuiltInOptions/project/Program.cs b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceBuiltInOptions/project/Program.cs new file mode 100644 index 000000000..d0134277c --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceBuiltInOptions/project/Program.cs @@ -0,0 +1,19 @@ +using System; +using System.Linq; +using System.Reflection; + +namespace ConsoleApplication +{ + public class Program + { + public static void Main(string[] args) + { + var thisAssembly = typeof(Program).GetTypeInfo().Assembly; + var resources = from resourceName in thisAssembly.GetManifestResourceNames() + select resourceName; + + var resourceNames = string.Join(",", resources); + Console.WriteLine($"{resources.Count()} Resources Found: {resourceNames}"); + } + } +} diff --git a/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceBuiltInOptions/project/Resources/Strings.resx b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceBuiltInOptions/project/Resources/Strings.resx new file mode 100644 index 000000000..1f24a372f --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceBuiltInOptions/project/Resources/Strings.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Hello World! + + \ No newline at end of file diff --git a/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceBuiltInOptions/project/project.json b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceBuiltInOptions/project/project.json new file mode 100644 index 000000000..d4f8ee07f --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceBuiltInOptions/project/project.json @@ -0,0 +1,20 @@ +{ + "version": "1.0.0-*", + "resourceBuiltIn": [ "../Strings1.resx", "../Strings2.resx" ], + "buildOptions": { + "debugType": "portable", + "emitEntryPoint": true + }, + "dependencies": {}, + "frameworks": { + "netcoreapp1.0": { + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.0" + } + }, + "imports": "dnxcore50" + } + } +} diff --git a/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceExcludeOptions/Exclude1.resx b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceExcludeOptions/Exclude1.resx new file mode 100644 index 000000000..a82c91ddd --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceExcludeOptions/Exclude1.resx @@ -0,0 +1 @@ +This is not a resource file but is used to test resource exclusion. diff --git a/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceExcludeOptions/Exclude2.resx b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceExcludeOptions/Exclude2.resx new file mode 100644 index 000000000..a82c91ddd --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceExcludeOptions/Exclude2.resx @@ -0,0 +1 @@ +This is not a resource file but is used to test resource exclusion. diff --git a/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceExcludeOptions/Program.cs b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceExcludeOptions/Program.cs new file mode 100644 index 000000000..d0134277c --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceExcludeOptions/Program.cs @@ -0,0 +1,19 @@ +using System; +using System.Linq; +using System.Reflection; + +namespace ConsoleApplication +{ + public class Program + { + public static void Main(string[] args) + { + var thisAssembly = typeof(Program).GetTypeInfo().Assembly; + var resources = from resourceName in thisAssembly.GetManifestResourceNames() + select resourceName; + + var resourceNames = string.Join(",", resources); + Console.WriteLine($"{resources.Count()} Resources Found: {resourceNames}"); + } + } +} diff --git a/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceExcludeOptions/project.json b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceExcludeOptions/project.json new file mode 100644 index 000000000..01c3c9e23 --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceExcludeOptions/project.json @@ -0,0 +1,21 @@ +{ + "version": "1.0.0-*", + "exclude": "Exclude1.resx", + "resourceExclude": [ "Exclude2.resx" ], + "buildOptions": { + "debugType": "portable", + "emitEntryPoint": true + }, + "dependencies": {}, + "frameworks": { + "netcoreapp1.0": { + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.0" + } + }, + "imports": "dnxcore50" + } + } +} diff --git a/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceOptions/Strings1.resx b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceOptions/Strings1.resx new file mode 100644 index 000000000..1f24a372f --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceOptions/Strings1.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Hello World! + + \ No newline at end of file diff --git a/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceOptions/Strings2.resx b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceOptions/Strings2.resx new file mode 100644 index 000000000..1f24a372f --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceOptions/Strings2.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Hello World! + + \ No newline at end of file diff --git a/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceOptions/project/Program.cs b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceOptions/project/Program.cs new file mode 100644 index 000000000..d0134277c --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceOptions/project/Program.cs @@ -0,0 +1,19 @@ +using System; +using System.Linq; +using System.Reflection; + +namespace ConsoleApplication +{ + public class Program + { + public static void Main(string[] args) + { + var thisAssembly = typeof(Program).GetTypeInfo().Assembly; + var resources = from resourceName in thisAssembly.GetManifestResourceNames() + select resourceName; + + var resourceNames = string.Join(",", resources); + Console.WriteLine($"{resources.Count()} Resources Found: {resourceNames}"); + } + } +} diff --git a/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceOptions/project/Resources/Strings.resx b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceOptions/project/Resources/Strings.resx new file mode 100644 index 000000000..1f24a372f --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceOptions/project/Resources/Strings.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Hello World! + + \ No newline at end of file diff --git a/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceOptions/project/project.json b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceOptions/project/project.json new file mode 100644 index 000000000..369f7325d --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/PJAppWithDeprecatedResourceOptions/project/project.json @@ -0,0 +1,21 @@ +{ + "version": "1.0.0-*", + "resource": "../Strings1.resx", + "resourceFiles": [ "../Strings2.resx" ], + "buildOptions": { + "debugType": "portable", + "emitEntryPoint": true + }, + "dependencies": {}, + "frameworks": { + "netcoreapp1.0": { + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.0" + } + }, + "imports": "dnxcore50" + } + } +} diff --git a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateDeprecatedProjects.cs b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateDeprecatedProjects.cs index e5839c949..d5dcad063 100644 --- a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateDeprecatedProjects.cs +++ b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateDeprecatedProjects.cs @@ -384,5 +384,163 @@ namespace Microsoft.DotNet.Migration.Tests // .Execute("build") // .Should().Pass(); } + + [Fact] + public void WhenMigratingAProjectWithDeprecatedResourceOptionsWarningsArePrinted() + { + var projectDirectory = TestAssets + .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedResourceOptions") + .CreateInstance() + .WithSourceFiles() + .Root + .GetDirectory("project"); + + var cmd = new DotnetCommand() + .WithWorkingDirectory(projectDirectory) + .ExecuteWithCapturedOutput("migrate"); + + cmd.Should().Pass(); + + cmd.StdOut.Should().Contain( + "The 'resource' option is deprecated. Use 'embed' in 'buildOptions' instead."); + cmd.StdOut.Should().Contain( + "The 'resourceFiles' option is deprecated. Use 'embed' in 'buildOptions' instead."); + } + + [Fact] + public void WhenMigratingAProjectWithDeprecatedResourceOptionsItSucceeds() + { + var projectDirectory = TestAssets + .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedResourceOptions") + .CreateInstance() + .WithSourceFiles() + .Root + .GetDirectory("project"); + + new DotnetCommand() + .WithWorkingDirectory(projectDirectory) + .Execute("migrate") + .Should().Pass(); + + new DotnetCommand() + .WithWorkingDirectory(projectDirectory) + .Execute("restore") + .Should().Pass(); + + new DotnetCommand() + .WithWorkingDirectory(projectDirectory) + .Execute("build") + .Should().Pass(); + + var cmd = new DotnetCommand() + .WithWorkingDirectory(projectDirectory) + .ExecuteWithCapturedOutput("run"); + cmd.Should().Pass(); + cmd.StdOut.Should().Contain("3 Resources Found:"); + } + + [Fact] + public void WhenMigratingAProjectWithDeprecatedResourceBuiltInOptionsWarningsArePrinted() + { + var projectDirectory = TestAssets + .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedResourceBuiltInOptions") + .CreateInstance() + .WithSourceFiles() + .Root + .GetDirectory("project"); + + var cmd = new DotnetCommand() + .WithWorkingDirectory(projectDirectory) + .ExecuteWithCapturedOutput("migrate"); + + cmd.Should().Pass(); + + cmd.StdOut.Should().Contain( + "The 'resourceBuiltIn' option is deprecated. Use 'embed' in 'buildOptions' instead."); + } + + [Fact] + public void WhenMigratingAProjectWithDeprecatedResourceBuiltInOptionsItSucceeds() + { + var projectDirectory = TestAssets + .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedResourceBuiltInOptions") + .CreateInstance() + .WithSourceFiles() + .Root + .GetDirectory("project"); + + new DotnetCommand() + .WithWorkingDirectory(projectDirectory) + .Execute("migrate") + .Should().Pass(); + + new DotnetCommand() + .WithWorkingDirectory(projectDirectory) + .Execute("restore") + .Should().Pass(); + + new DotnetCommand() + .WithWorkingDirectory(projectDirectory) + .Execute("build") + .Should().Pass(); + + var cmd = new DotnetCommand() + .WithWorkingDirectory(projectDirectory) + .ExecuteWithCapturedOutput("run"); + cmd.Should().Pass(); + // Issue: https://github.com/dotnet/cli/issues/5467 + //cmd.StdOut.Should().Contain("2 Resources Found:"); + } + + [Fact] + public void WhenMigratingAProjectWithDeprecatedResourceExcludeOptionsWarningsArePrinted() + { + var projectDirectory = TestAssets + .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedResourceExcludeOptions") + .CreateInstance() + .WithSourceFiles() + .Root; + + var cmd = new DotnetCommand() + .WithWorkingDirectory(projectDirectory) + .ExecuteWithCapturedOutput("migrate"); + + cmd.Should().Pass(); + + cmd.StdOut.Should().Contain( + "The 'resourceExclude' option is deprecated. Use 'embed' in 'buildOptions' instead."); + } + + [Fact] + public void WhenMigratingAProjectWithDeprecatedResourceExcludeOptionsItSucceeds() + { + var projectDirectory = TestAssets + .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedResourceExcludeOptions") + .CreateInstance() + .WithSourceFiles() + .Root; + + new DotnetCommand() + .WithWorkingDirectory(projectDirectory) + .Execute("migrate") + .Should().Pass(); + + new DotnetCommand() + .WithWorkingDirectory(projectDirectory) + .Execute("restore") + .Should().Pass(); + + // Issue: https://github.com/dotnet/cli/issues/5461 + //new DotnetCommand() + // .WithWorkingDirectory(projectDirectory) + // .Execute("build") + // .Should().Pass(); + + //var cmd = new DotnetCommand() + // .WithWorkingDirectory(projectDirectory) + // .ExecuteWithCapturedOutput("run"); + //cmd.Should().Pass(); + //cmd.StdOut.Should().Contain("0 Resources Found:"); + } } }