From f084032af64baa676fa51570677c750d5c7ddf24 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Fri, 9 Sep 2016 08:49:22 -0500 Subject: [PATCH] Ensure the project is built in `dotnet run3`. --- .../TestProjects/MSBuildTestApp/project.json | 2 +- .../Microsoft.DotNet.Tools.Test.xproj | 9 ++++--- src/dotnet/Program.cs | 16 +++++++++++++ .../CSharp_MSBuild/project.json.template | 2 +- src/dotnet/commands/dotnet-run3/Program.cs | 21 +--------------- .../commands/dotnet-run3/Run3Command.cs | 24 +++++++++++++++++++ .../commands/dotnet-test/dotnet-test.xproj | 17 ------------- 7 files changed, 47 insertions(+), 44 deletions(-) delete mode 100644 src/dotnet/commands/dotnet-test/dotnet-test.xproj diff --git a/TestAssets/TestProjects/MSBuildTestApp/project.json b/TestAssets/TestProjects/MSBuildTestApp/project.json index 3ba1afc97..45fac06b7 100644 --- a/TestAssets/TestProjects/MSBuildTestApp/project.json +++ b/TestAssets/TestProjects/MSBuildTestApp/project.json @@ -2,7 +2,7 @@ "frameworks": { "netcoreapp1.0": { "dependencies": { - "Microsoft.NETCore.Sdk": "1.0.0-alpha-20160907-1", + "Microsoft.NETCore.Sdk": "1.0.0-alpha-20160909-2", "Microsoft.NETCore.App": { "version": "1.0.1", "type": "platform" diff --git a/src/Microsoft.DotNet.Tools.Test/Microsoft.DotNet.Tools.Test.xproj b/src/Microsoft.DotNet.Tools.Test/Microsoft.DotNet.Tools.Test.xproj index 0ead3698f..f429f9bf5 100644 --- a/src/Microsoft.DotNet.Tools.Test/Microsoft.DotNet.Tools.Test.xproj +++ b/src/Microsoft.DotNet.Tools.Test/Microsoft.DotNet.Tools.Test.xproj @@ -5,17 +5,16 @@ $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - + 6D028154-5518-4A56-BAD6-938A90E5BCF6 dotnet_test_console - obj\$(MSBuildProjectName) - bin\$(MSBuildProjectName)\ - v4.5.2 + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin 2.0 - + diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index 26f6c1008..aaa03e890 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -74,6 +74,22 @@ namespace Microsoft.DotNet.Cli return 1; } + catch (Exception ex) + { +#if DEBUG + Reporter.Error.WriteLine(ex.ToString()); +#else + if (Reporter.IsVerbose) + { + Reporter.Error.WriteLine(ex.ToString()); + } + else + { + Reporter.Error.WriteLine(ex.Message); + } +#endif + return 1; + } finally { if (PerfTrace.Enabled) diff --git a/src/dotnet/commands/dotnet-new/CSharp_MSBuild/project.json.template b/src/dotnet/commands/dotnet-new/CSharp_MSBuild/project.json.template index 7e7211fcc..e6475205c 100644 --- a/src/dotnet/commands/dotnet-new/CSharp_MSBuild/project.json.template +++ b/src/dotnet/commands/dotnet-new/CSharp_MSBuild/project.json.template @@ -3,7 +3,7 @@ "frameworks": { "netcoreapp1.0": { "dependencies": { - "Microsoft.NETCore.Sdk": "1.0.0-alpha-20160907-1", + "Microsoft.NETCore.Sdk": "1.0.0-alpha-20160909-2", "Microsoft.NETCore.App": { "type": "platform", "version": "1.0.1" diff --git a/src/dotnet/commands/dotnet-run3/Program.cs b/src/dotnet/commands/dotnet-run3/Program.cs index db81ea32e..90775bd68 100644 --- a/src/dotnet/commands/dotnet-run3/Program.cs +++ b/src/dotnet/commands/dotnet-run3/Program.cs @@ -35,26 +35,7 @@ namespace Microsoft.DotNet.Tools.Run return runCmd.Start(); }); - try - { - return app.Execute(args); - } - catch (Exception ex) - { -#if DEBUG - Reporter.Error.WriteLine(ex.ToString()); -#else - if (Reporter.IsVerbose) - { - Reporter.Error.WriteLine(ex.ToString()); - } - else - { - Reporter.Error.WriteLine(ex.Message); - } -#endif - return 1; - } + return app.Execute(args); } } } diff --git a/src/dotnet/commands/dotnet-run3/Run3Command.cs b/src/dotnet/commands/dotnet-run3/Run3Command.cs index 3effa9915..04b180d1c 100644 --- a/src/dotnet/commands/dotnet-run3/Run3Command.cs +++ b/src/dotnet/commands/dotnet-run3/Run3Command.cs @@ -7,6 +7,7 @@ using System.IO; using System.Linq; using Microsoft.Build.Execution; using Microsoft.Build.Framework; +using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.Utils; using NuGet.Frameworks; @@ -37,6 +38,8 @@ namespace Microsoft.DotNet.Tools.Run { Initialize(); + EnsureProjectIsBuilt(); + ITaskItem runInfoItem = GetRunInformation(); string commandName = runInfoItem.GetMetadata("CommandName"); @@ -49,6 +52,27 @@ namespace Microsoft.DotNet.Tools.Run .ExitCode; } + private void EnsureProjectIsBuilt() + { + List buildArgs = new List(); + + buildArgs.Add("/nologo"); + buildArgs.Add("/verbosity:quiet"); + + if (!string.IsNullOrWhiteSpace(Configuration)) + { + buildArgs.Add($"/p:Configuration={Configuration}"); + } + + var buildResult = new MSBuildForwardingApp(buildArgs).Execute(); + + if (buildResult != 0) + { + Reporter.Error.WriteLine(); + throw new GracefulException("The build failed. Please fix the build errors and run again."); + } + } + private ITaskItem GetRunInformation() { Dictionary globalProperties = new Dictionary() diff --git a/src/dotnet/commands/dotnet-test/dotnet-test.xproj b/src/dotnet/commands/dotnet-test/dotnet-test.xproj deleted file mode 100644 index 7f173a43e..000000000 --- a/src/dotnet/commands/dotnet-test/dotnet-test.xproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - f003f228-2ae2-4e9d-877b-93eb773b5061 - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\$(MSBuildProjectName)\ - - - 2.0 - - - \ No newline at end of file