From 3a3ab7e0b0dd0bc7e47dad26ecb479f709ad034e Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Wed, 23 Nov 2016 23:54:44 -0800 Subject: [PATCH] MSBuildSDKsPath (#4824) * Tests in place * Implementation --- .../MSBuildIntegration/build.proj | 17 ++++++++++--- .../MSBuildIntegration/build.props | 6 +++++ build/Microsoft.DotNet.Cli.BundledSdks.props | 6 +++++ build/Microsoft.DotNet.Cli.Compile.targets | 17 ++++++++++++- build/Microsoft.DotNet.Cli.Prepare.targets | 1 + .../dotnet-msbuild/MSBuildForwardingApp.cs | 16 ++++++++++--- .../GivenDotnetInvokesMSBuild.cs | 24 +++++++++++-------- 7 files changed, 70 insertions(+), 17 deletions(-) create mode 100644 TestAssets/TestProjects/MSBuildIntegration/build.props create mode 100644 build/Microsoft.DotNet.Cli.BundledSdks.props diff --git a/TestAssets/TestProjects/MSBuildIntegration/build.proj b/TestAssets/TestProjects/MSBuildIntegration/build.proj index f8323acf9..795a611c5 100644 --- a/TestAssets/TestProjects/MSBuildIntegration/build.proj +++ b/TestAssets/TestProjects/MSBuildIntegration/build.proj @@ -2,6 +2,8 @@ + + @@ -22,13 +24,22 @@ + Text="Expected MSBuildNodeCount to be greater than 1, but found $(MSBuildNodeCount). Is this a single proc machine?" /> + Text="Expected MSBuildExtensionsPath to be set, but it is not." /> + Text="Expected CscToolExe to be set, but it is not." /> + + + + + + diff --git a/TestAssets/TestProjects/MSBuildIntegration/build.props b/TestAssets/TestProjects/MSBuildIntegration/build.props new file mode 100644 index 000000000..1cd8b6830 --- /dev/null +++ b/TestAssets/TestProjects/MSBuildIntegration/build.props @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/build/Microsoft.DotNet.Cli.BundledSdks.props b/build/Microsoft.DotNet.Cli.BundledSdks.props new file mode 100644 index 000000000..03d6e8894 --- /dev/null +++ b/build/Microsoft.DotNet.Cli.BundledSdks.props @@ -0,0 +1,6 @@ + + + + + + diff --git a/build/Microsoft.DotNet.Cli.Compile.targets b/build/Microsoft.DotNet.Cli.Compile.targets index ca95e66f4..db8078539 100644 --- a/build/Microsoft.DotNet.Cli.Compile.targets +++ b/build/Microsoft.DotNet.Cli.Compile.targets @@ -18,8 +18,9 @@ + GetNuGetPackagesArchive;" /> @@ -242,4 +243,18 @@ + + + + + + + + + + \ No newline at end of file diff --git a/build/Microsoft.DotNet.Cli.Prepare.targets b/build/Microsoft.DotNet.Cli.Prepare.targets index ff70ae72a..c9c5a04c7 100644 --- a/build/Microsoft.DotNet.Cli.Prepare.targets +++ b/build/Microsoft.DotNet.Cli.Prepare.targets @@ -2,6 +2,7 @@ + diff --git a/src/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs b/src/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs index 5b2b16ff0..2a147a5be 100644 --- a/src/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs +++ b/src/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs @@ -16,7 +16,9 @@ namespace Microsoft.DotNet.Tools.MSBuild { internal const string TelemetrySessionIdEnvironmentVariableName = "DOTNET_CLI_TELEMETRY_SESSIONID"; - private const string s_msbuildExeName = "MSBuild.dll"; + private const string MSBuildExeName = "MSBuild.dll"; + + private const string ExtensionsDirectoryName = "Extensions"; private readonly ForwardingApp _forwardingApp; @@ -24,7 +26,8 @@ namespace Microsoft.DotNet.Tools.MSBuild new Dictionary { { "MSBuildExtensionsPath", AppContext.BaseDirectory }, - { "CscToolExe", GetRunCscPath() } + { "CscToolExe", GetRunCscPath() }, + { "MSBuildSDKsPath", GetMSBuildSDKsPath() } }; private readonly IEnumerable _msbuildRequiredParameters = @@ -78,7 +81,14 @@ namespace Microsoft.DotNet.Tools.MSBuild { return Path.Combine( AppContext.BaseDirectory, - s_msbuildExeName); + MSBuildExeName); + } + + private static string GetMSBuildSDKsPath() + { + return Path.Combine( + AppContext.BaseDirectory, + ExtensionsDirectoryName); } private static string GetRunCscPath() diff --git a/test/msbuild.IntegrationTests/GivenDotnetInvokesMSBuild.cs b/test/msbuild.IntegrationTests/GivenDotnetInvokesMSBuild.cs index e6dbc380b..971ced657 100644 --- a/test/msbuild.IntegrationTests/GivenDotnetInvokesMSBuild.cs +++ b/test/msbuild.IntegrationTests/GivenDotnetInvokesMSBuild.cs @@ -35,6 +35,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.IntegrationTests [Theory] [InlineData("build")] [InlineData("clean")] + [InlineData("msbuild")] [InlineData("pack")] [InlineData("publish")] public void When_dotnet_command_invokes_msbuild_with_no_args_verbosity_is_set_to_minimum(string command) @@ -46,10 +47,12 @@ namespace Microsoft.DotNet.Cli.MSBuild.IntegrationTests var cmd = new DotnetCommand() .WithWorkingDirectory(testInstance.Root) .ExecuteWithCapturedOutput(command); + cmd.Should().Pass(); - cmd.StdOut.Should().NotContain("Message with normal importance"); - // sanity check - cmd.StdOut.Should().Contain("Message with high importance"); + + cmd.StdOut + .Should().NotContain("Message with normal importance", "Because verbosity is set to minimum") + .And.Contain("Message with high importance", "Because high importance messages are shown on minimum verbosity"); } [Theory] @@ -57,7 +60,6 @@ namespace Microsoft.DotNet.Cli.MSBuild.IntegrationTests [InlineData("clean")] [InlineData("pack")] [InlineData("publish")] - [InlineData("test")] public void When_dotnet_command_invokes_msbuild_with_diag_verbosity_Then_arg_is_passed(string command) { var testInstance = TestAssets.Get("MSBuildIntegration") @@ -67,21 +69,23 @@ namespace Microsoft.DotNet.Cli.MSBuild.IntegrationTests var cmd = new DotnetCommand() .WithWorkingDirectory(testInstance.Root) .ExecuteWithCapturedOutput($"{command} -v diag"); + cmd.Should().Pass(); + cmd.StdOut.Should().Contain("Message with low importance"); } [Fact] public void When_dotnet_test_invokes_msbuild_with_no_args_verbosity_is_set_to_quiet() { - string command = "test"; var testInstance = TestAssets.Get("MSBuildIntegration") - .CreateInstance(identifier: command) + .CreateInstance() .WithSourceFiles(); var cmd = new DotnetCommand() .WithWorkingDirectory(testInstance.Root) - .ExecuteWithCapturedOutput(command); + .ExecuteWithCapturedOutput("test"); + cmd.Should().Pass(); cmd.StdOut.Should().NotContain("Message with high importance"); } @@ -89,14 +93,14 @@ namespace Microsoft.DotNet.Cli.MSBuild.IntegrationTests [Fact] public void When_dotnet_msbuild_command_is_invoked_with_non_msbuild_switch_Then_it_fails() { - string command = "msbuild"; var testInstance = TestAssets.Get("MSBuildIntegration") - .CreateInstance(identifier: command) + .CreateInstance() .WithSourceFiles(); var cmd = new DotnetCommand() .WithWorkingDirectory(testInstance.Root) - .ExecuteWithCapturedOutput($"{command} -v diag"); + .ExecuteWithCapturedOutput($"msbuild -v diag"); + cmd.ExitCode.Should().NotBe(0); } }