From 1d25d2574d6f8facf0a9c8d0138b59d74eec31a6 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 8 Feb 2016 16:06:13 -0800 Subject: [PATCH] Fix the paths at which CompileContext locates resgen outputs. Fixes #1136 --- .../Program.cs | 20 +++ .../Strings.fr.resx | 123 ++++++++++++++++++ .../Strings.resx | 123 ++++++++++++++++++ ...stProjectWithCultureSpecificResource.xproj | 19 +++ .../project.json | 14 ++ .../TestProjectWithResource/Program.cs | 18 +++ .../TestProjectWithResource/Strings.resx | 123 ++++++++++++++++++ .../TestProjectWithResource.xproj | 20 +++ .../TestProjectWithResource/project.json | 14 ++ .../commands/dotnet-build/CompileContext.cs | 6 +- ...crementalTestsOnCultureSpecificResource.cs | 31 +++++ .../IncrementalTestsOnResources.cs | 30 +++++ test/dotnet-build.Tests/project.json | 2 + test/dotnet-compile.Tests/CompilerTests.cs | 28 +++- test/dotnet-compile.Tests/project.json | 1 + 15 files changed, 568 insertions(+), 4 deletions(-) create mode 100644 TestAssets/TestProjects/TestProjectWithCultureSpecificResource/Program.cs create mode 100644 TestAssets/TestProjects/TestProjectWithCultureSpecificResource/Strings.fr.resx create mode 100644 TestAssets/TestProjects/TestProjectWithCultureSpecificResource/Strings.resx create mode 100644 TestAssets/TestProjects/TestProjectWithCultureSpecificResource/TestProjectWithCultureSpecificResource.xproj create mode 100644 TestAssets/TestProjects/TestProjectWithCultureSpecificResource/project.json create mode 100644 TestAssets/TestProjects/TestProjectWithResource/Program.cs create mode 100644 TestAssets/TestProjects/TestProjectWithResource/Strings.resx create mode 100644 TestAssets/TestProjects/TestProjectWithResource/TestProjectWithResource.xproj create mode 100644 TestAssets/TestProjects/TestProjectWithResource/project.json create mode 100644 test/dotnet-build.Tests/IncrementalTestsOnCultureSpecificResource.cs create mode 100644 test/dotnet-build.Tests/IncrementalTestsOnResources.cs diff --git a/TestAssets/TestProjects/TestProjectWithCultureSpecificResource/Program.cs b/TestAssets/TestProjects/TestProjectWithCultureSpecificResource/Program.cs new file mode 100644 index 000000000..3b5a088e1 --- /dev/null +++ b/TestAssets/TestProjects/TestProjectWithCultureSpecificResource/Program.cs @@ -0,0 +1,20 @@ +using System; +using System.Resources; +using System.Reflection; +using System.Globalization; + +namespace TestProjectWithCultureSpecificResource +{ + public class Program + { + public static void Main(string[] args) + { + var rm = new ResourceManager( + "TestProjectWithCultureSpecificResource.Strings", + typeof(Program).GetTypeInfo().Assembly); + + Console.WriteLine(rm.GetString("hello")); + Console.WriteLine(rm.GetString("hello", new CultureInfo("fr"))); + } + } +} diff --git a/TestAssets/TestProjects/TestProjectWithCultureSpecificResource/Strings.fr.resx b/TestAssets/TestProjects/TestProjectWithCultureSpecificResource/Strings.fr.resx new file mode 100644 index 000000000..f569847fa --- /dev/null +++ b/TestAssets/TestProjects/TestProjectWithCultureSpecificResource/Strings.fr.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 + + + Bonjour! + + \ No newline at end of file diff --git a/TestAssets/TestProjects/TestProjectWithCultureSpecificResource/Strings.resx b/TestAssets/TestProjects/TestProjectWithCultureSpecificResource/Strings.resx new file mode 100644 index 000000000..bd249e209 --- /dev/null +++ b/TestAssets/TestProjects/TestProjectWithCultureSpecificResource/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/TestProjects/TestProjectWithCultureSpecificResource/TestProjectWithCultureSpecificResource.xproj b/TestAssets/TestProjects/TestProjectWithCultureSpecificResource/TestProjectWithCultureSpecificResource.xproj new file mode 100644 index 000000000..d8121765f --- /dev/null +++ b/TestAssets/TestProjects/TestProjectWithCultureSpecificResource/TestProjectWithCultureSpecificResource.xproj @@ -0,0 +1,19 @@ + + + + 14.0.24720 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + fea4ab27-d004-4580-8abe-b171e30b68cc + TestProjectWithCultureSpecificResource + ..\..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\..\artifacts\bin\$(MSBuildProjectName)\ + + + + 2.0 + + + \ No newline at end of file diff --git a/TestAssets/TestProjects/TestProjectWithCultureSpecificResource/project.json b/TestAssets/TestProjects/TestProjectWithCultureSpecificResource/project.json new file mode 100644 index 000000000..c33f13b32 --- /dev/null +++ b/TestAssets/TestProjects/TestProjectWithCultureSpecificResource/project.json @@ -0,0 +1,14 @@ +{ + "version": "1.0.0-*", + "compilationOptions": { + "emitEntryPoint": true + }, + + "dependencies": { + "NETStandard.Library": "1.0.0-rc2-23805" + }, + + "frameworks": { + "dnxcore50": { } + } +} diff --git a/TestAssets/TestProjects/TestProjectWithResource/Program.cs b/TestAssets/TestProjects/TestProjectWithResource/Program.cs new file mode 100644 index 000000000..1e17eeef6 --- /dev/null +++ b/TestAssets/TestProjects/TestProjectWithResource/Program.cs @@ -0,0 +1,18 @@ +using System; +using System.Resources; +using System.Reflection; + +namespace TestProjectWithResource +{ + public class Program + { + public static void Main(string[] args) + { + var rm = new ResourceManager( + "TestProjectWithResource.Strings", + typeof(Program).GetTypeInfo().Assembly); + + Console.WriteLine(rm.GetString("hello")); + } + } +} diff --git a/TestAssets/TestProjects/TestProjectWithResource/Strings.resx b/TestAssets/TestProjects/TestProjectWithResource/Strings.resx new file mode 100644 index 000000000..bd249e209 --- /dev/null +++ b/TestAssets/TestProjects/TestProjectWithResource/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/TestProjects/TestProjectWithResource/TestProjectWithResource.xproj b/TestAssets/TestProjects/TestProjectWithResource/TestProjectWithResource.xproj new file mode 100644 index 000000000..aee14e286 --- /dev/null +++ b/TestAssets/TestProjects/TestProjectWithResource/TestProjectWithResource.xproj @@ -0,0 +1,20 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + 58808bbc-371e-47d6-a3d0-4909876ed864 + TestProjectWithResource + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + + 2.0 + + + diff --git a/TestAssets/TestProjects/TestProjectWithResource/project.json b/TestAssets/TestProjects/TestProjectWithResource/project.json new file mode 100644 index 000000000..c33f13b32 --- /dev/null +++ b/TestAssets/TestProjects/TestProjectWithResource/project.json @@ -0,0 +1,14 @@ +{ + "version": "1.0.0-*", + "compilationOptions": { + "emitEntryPoint": true + }, + + "dependencies": { + "NETStandard.Library": "1.0.0-rc2-23805" + }, + + "frameworks": { + "dnxcore50": { } + } +} diff --git a/src/dotnet/commands/dotnet-build/CompileContext.cs b/src/dotnet/commands/dotnet-build/CompileContext.cs index b12c0627a..1d7c047f1 100644 --- a/src/dotnet/commands/dotnet-build/CompileContext.cs +++ b/src/dotnet/commands/dotnet-build/CompileContext.cs @@ -475,12 +475,12 @@ namespace Microsoft.DotNet.Tools.Build // input compilation options files AddCompilationOptions(project, buildConfiguration, compilerIO); + // input / output: resources with culture + AddNonCultureResources(project, calculator.IntermediateOutputDirectoryPath, compilerIO); + // input / output: resources without culture AddCultureResources(project, binariesOutputPath, compilerIO); - // input / output: resources with culture - AddNonCultureResources(project, binariesOutputPath, compilerIO); - return compilerIO; } diff --git a/test/dotnet-build.Tests/IncrementalTestsOnCultureSpecificResource.cs b/test/dotnet-build.Tests/IncrementalTestsOnCultureSpecificResource.cs new file mode 100644 index 000000000..dbb5bd527 --- /dev/null +++ b/test/dotnet-build.Tests/IncrementalTestsOnCultureSpecificResource.cs @@ -0,0 +1,31 @@ +// 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 System; +using System.IO; +using Microsoft.DotNet.Tools.Test.Utilities; +using Xunit; + +namespace Microsoft.DotNet.Tools.Builder.Tests +{ + public class IncrementalTestsOnCultureSpecificResource : IncrementalTestBase + { + public IncrementalTestsOnCultureSpecificResource() : base( + Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects", "TestProjectWithCultureSpecificResource"), + "TestProjectWithCultureSpecificResource", + "Hello World!" + Environment.NewLine + "Bonjour!" + Environment.NewLine) + { + } + + [Fact] + public void TestRebuildSkipsCompilationOnNonCultureResource() + { + var buildResult = BuildProject(); + buildResult.Should().HaveCompiledProject(MainProject); + + buildResult = BuildProject(); + + buildResult.Should().HaveSkippedProjectCompilation(MainProject); + } + } +} \ No newline at end of file diff --git a/test/dotnet-build.Tests/IncrementalTestsOnResources.cs b/test/dotnet-build.Tests/IncrementalTestsOnResources.cs new file mode 100644 index 000000000..f2ae27b35 --- /dev/null +++ b/test/dotnet-build.Tests/IncrementalTestsOnResources.cs @@ -0,0 +1,30 @@ +// 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 System; +using System.IO; +using Microsoft.DotNet.Tools.Test.Utilities; +using Xunit; + +namespace Microsoft.DotNet.Tools.Builder.Tests +{ + public class IncrementalTestsOnResources : IncrementalTestBase + { + public IncrementalTestsOnResources() : base( + Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects", "TestProjectWithResource"), + "TestProjectWithResource", + "Hello World!" + Environment.NewLine) + { + } + + [Fact] + public void TestRebuildSkipsCompilationOnNonCultureResource() + { + var buildResult = BuildProject(); + buildResult.Should().HaveCompiledProject(MainProject); + + buildResult = BuildProject(); + buildResult.Should().HaveSkippedProjectCompilation(MainProject); + } + } +} \ No newline at end of file diff --git a/test/dotnet-build.Tests/project.json b/test/dotnet-build.Tests/project.json index 7cd804af9..e36da2b8a 100644 --- a/test/dotnet-build.Tests/project.json +++ b/test/dotnet-build.Tests/project.json @@ -25,6 +25,8 @@ "../../TestAssets/TestProjects/TestLibrary/**/*", "../../TestAssets/TestProjects/TestSimpleIncrementalApp/*", "../../TestAssets/TestProjects/TestProjectToProjectDependencies/**/*", + "../../TestAssets/TestProjects/TestProjectWithCultureSpecificResource/**/*", + "../../TestAssets/TestProjects/TestProjectWithResource/**/*", "../../TestAssets/TestProjects/global.json" ], diff --git a/test/dotnet-compile.Tests/CompilerTests.cs b/test/dotnet-compile.Tests/CompilerTests.cs index 73aba0333..2269b40f5 100644 --- a/test/dotnet-compile.Tests/CompilerTests.cs +++ b/test/dotnet-compile.Tests/CompilerTests.cs @@ -42,7 +42,33 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests Assert.True(File.Exists(outputXml)); Assert.Contains("Gets the message from the helper", File.ReadAllText(outputXml)); } - + + [Fact] + public void SatelliteAssemblyIsGeneratedByDotnetBuild() + { + // create unique directories in the 'temp' folder + var root = Temp.CreateDirectory(); + var testLibDir = root.CreateDirectory("TestProjectWithCultureSpecificResource"); + var sourceTestLibDir = Path.Combine(_testProjectsRoot, "TestProjectWithCultureSpecificResource"); + + CopyProjectToTempDir(sourceTestLibDir, testLibDir); + + // run compile on a project with resources + var outputDir = Path.Combine(testLibDir.Path, "bin"); + var testProject = GetProjectPath(testLibDir); + var buildCmd = new BuildCommand(testProject, output: outputDir, framework: DefaultFramework); + var result = buildCmd.ExecuteWithCapturedOutput(); + result.Should().Pass(); + + var generatedSatelliteAssemblyPath = Path.Combine( + outputDir, + "Debug", + DefaultFramework, + "fr", + "TestProjectWithCultureSpecificResource.resources.dll"); + Assert.True(File.Exists(generatedSatelliteAssemblyPath), $"File {generatedSatelliteAssemblyPath} was not found."); + } + [Fact] public void LibraryWithAnalyzer() { diff --git a/test/dotnet-compile.Tests/project.json b/test/dotnet-compile.Tests/project.json index 3acf043a2..6f8c2fca4 100644 --- a/test/dotnet-compile.Tests/project.json +++ b/test/dotnet-compile.Tests/project.json @@ -23,6 +23,7 @@ "content": [ "../../TestAssets/TestProjects/TestLibraryWithAnalyzer/*", "../../TestAssets/TestProjects/TestLibrary/*", + "../../TestAssets/TestProjects/TestProjectWithCultureSpecificResource/*", "../../TestAssets/TestProjects/global.json" ],