From a8c804cba7539b753e132a54429468cf29bbd4b5 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Mon, 12 Sep 2016 14:47:29 -0500 Subject: [PATCH 1/3] Update the CLI to the new Run static properties from the SDK. See https://github.com/dotnet/sdk/issues/98 --- .../commands/dotnet-run3/Run3Command.cs | 63 ++++++------------- 1 file changed, 19 insertions(+), 44 deletions(-) diff --git a/src/dotnet/commands/dotnet-run3/Run3Command.cs b/src/dotnet/commands/dotnet-run3/Run3Command.cs index 04b180d1c..b72081672 100644 --- a/src/dotnet/commands/dotnet-run3/Run3Command.cs +++ b/src/dotnet/commands/dotnet-run3/Run3Command.cs @@ -6,48 +6,36 @@ using System.Collections.Generic; 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; namespace Microsoft.DotNet.Tools.Run { public partial class Run3Command { - private const string GetRunInformationTaskName = "GetRunInformation"; - + private const string RunCommandPropName = "RunCommand"; + private const string RunArgumentsPropName = "RunArguments"; + private const string RunWorkingDirectoryPropName = "RunWorkingDirectory"; + public string Configuration { get; set; } public string Project { get; set; } public IReadOnlyList Args { get; set; } - private readonly ICommandFactory _commandFactory; private List _args; public Run3Command() - : this(new RunCommandFactory()) { } - public Run3Command(ICommandFactory commandFactory) - { - _commandFactory = commandFactory; - } - public int Start() { Initialize(); EnsureProjectIsBuilt(); - ITaskItem runInfoItem = GetRunInformation(); + ICommand runCommand = GetRunCommand(); - string commandName = runInfoItem.GetMetadata("CommandName"); - string[] args = runInfoItem.GetMetadata("Args").Split(';'); - - ICommand command = _commandFactory.Create(commandName, Enumerable.Concat(args, _args)); - - return command + return runCommand .Execute() .ExitCode; } @@ -73,7 +61,7 @@ namespace Microsoft.DotNet.Tools.Run } } - private ITaskItem GetRunInformation() + private ICommand GetRunCommand() { Dictionary globalProperties = new Dictionary() { @@ -87,30 +75,25 @@ namespace Microsoft.DotNet.Tools.Run ProjectInstance projectInstance = new ProjectInstance(Project, globalProperties, null); - BuildRequestData buildRequestData = new BuildRequestData(projectInstance, new string[] { GetRunInformationTaskName }); - BuildParameters buildParameters = new BuildParameters(); - - BuildResult result = BuildManager.DefaultBuildManager.Build(buildParameters, buildRequestData); - - TargetResult runInfoResult; - if (!result.ResultsByTarget.TryGetValue(GetRunInformationTaskName, out runInfoResult)) + string runProgram = projectInstance.GetPropertyValue(RunCommandPropName); + if (string.IsNullOrEmpty(runProgram)) { - throw new InvalidOperationException($"Could not find a target named '{GetRunInformationTaskName}' in your project. Please ensure 'dotnet run' supports this project."); + throw new InvalidOperationException($"The property named '{RunCommandPropName}' does not have a value in your project. Please ensure 'dotnet run' supports this project."); } - if (runInfoResult.ResultCode != TargetResultCode.Success) + string runArguments = projectInstance.GetPropertyValue(RunArgumentsPropName); + string runWorkingDirectory = projectInstance.GetPropertyValue(RunWorkingDirectoryPropName); + + string fullArguments = runArguments; + if (_args.Any()) { - throw new InvalidOperationException($"Could not get the run information for project {Project}. An internal MSBuild error has occured" + Environment.NewLine + - runInfoResult.Exception?.ToString()); + fullArguments += " " + ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(_args); } - ITaskItem runInfoItem = runInfoResult.Items.FirstOrDefault(i => i.ItemSpec == projectInstance.FullPath); - if (runInfoItem == null) - { - throw new InvalidOperationException($"'{GetRunInformationTaskName}' did not return an ITaskItem with the project's FullPath as the ItemSpec."); - } + CommandSpec commandSpec = new CommandSpec(runProgram, fullArguments, CommandResolutionStrategy.None); - return runInfoItem; + return Command.Create(commandSpec) + .WorkingDirectory(runWorkingDirectory); } private void Initialize() @@ -144,13 +127,5 @@ namespace Microsoft.DotNet.Tools.Run _args = new List(Args); } } - - private class RunCommandFactory : ICommandFactory - { - public ICommand Create(string commandName, IEnumerable args, NuGetFramework framework = null, string configuration = Constants.DefaultConfiguration) - { - return Command.Create(commandName, args, framework, configuration); - } - } } } From f9953c1e683f9e037deb86e67da1788cb82f9e43 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Wed, 14 Sep 2016 14:55:17 -0500 Subject: [PATCH 2/3] Update Microsoft.NETCore.Sdk to 1.0.0-alpha-20160914-1. --- TestAssets/TestProjects/MSBuildTestApp/project.json | 2 +- .../commands/dotnet-new/CSharp_MSBuild/project.json.template | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TestAssets/TestProjects/MSBuildTestApp/project.json b/TestAssets/TestProjects/MSBuildTestApp/project.json index 88c388d06..3087945e1 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-20160913-1", + "Microsoft.NETCore.Sdk": "1.0.0-alpha-20160914-1", "Microsoft.NETCore.App": { "version": "1.0.1", "type": "platform" 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 e32ce4428..897ee0fae 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-20160913-1", + "Microsoft.NETCore.Sdk": "1.0.0-alpha-20160914-1", "Microsoft.NETCore.App": { "type": "platform", "version": "1.0.1" From 3026eb9d35695e16e01b192e68d0db90bc1e1628 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Wed, 14 Sep 2016 16:27:52 -0500 Subject: [PATCH 3/3] Add a better error message for 'dotnet run3' when it is unable to find a RunCommand property. --- src/dotnet/commands/dotnet-run3/Run3Command.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/dotnet/commands/dotnet-run3/Run3Command.cs b/src/dotnet/commands/dotnet-run3/Run3Command.cs index b72081672..222853395 100644 --- a/src/dotnet/commands/dotnet-run3/Run3Command.cs +++ b/src/dotnet/commands/dotnet-run3/Run3Command.cs @@ -13,10 +13,6 @@ namespace Microsoft.DotNet.Tools.Run { public partial class Run3Command { - private const string RunCommandPropName = "RunCommand"; - private const string RunArgumentsPropName = "RunArguments"; - private const string RunWorkingDirectoryPropName = "RunWorkingDirectory"; - public string Configuration { get; set; } public string Project { get; set; } public IReadOnlyList Args { get; set; } @@ -75,14 +71,19 @@ namespace Microsoft.DotNet.Tools.Run ProjectInstance projectInstance = new ProjectInstance(Project, globalProperties, null); - string runProgram = projectInstance.GetPropertyValue(RunCommandPropName); + string runProgram = projectInstance.GetPropertyValue("RunCommand"); if (string.IsNullOrEmpty(runProgram)) { - throw new InvalidOperationException($"The property named '{RunCommandPropName}' does not have a value in your project. Please ensure 'dotnet run' supports this project."); + string outputType = projectInstance.GetPropertyValue("OutputType"); + + throw new GracefulException(string.Join(Environment.NewLine, + "Unable to run your project.", + "Please ensure you have a runnable project type and ensure 'dotnet run' supports this project.", + $"The current OutputType is '{outputType}'.")); } - string runArguments = projectInstance.GetPropertyValue(RunArgumentsPropName); - string runWorkingDirectory = projectInstance.GetPropertyValue(RunWorkingDirectoryPropName); + string runArguments = projectInstance.GetPropertyValue("RunArguments"); + string runWorkingDirectory = projectInstance.GetPropertyValue("RunWorkingDirectory"); string fullArguments = runArguments; if (_args.Any())