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" diff --git a/src/dotnet/commands/dotnet-run3/Run3Command.cs b/src/dotnet/commands/dotnet-run3/Run3Command.cs index 04b180d1c..222853395 100644 --- a/src/dotnet/commands/dotnet-run3/Run3Command.cs +++ b/src/dotnet/commands/dotnet-run3/Run3Command.cs @@ -6,48 +6,32 @@ 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"; - 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 +57,7 @@ namespace Microsoft.DotNet.Tools.Run } } - private ITaskItem GetRunInformation() + private ICommand GetRunCommand() { Dictionary globalProperties = new Dictionary() { @@ -87,30 +71,30 @@ 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("RunCommand"); + if (string.IsNullOrEmpty(runProgram)) { - throw new InvalidOperationException($"Could not find a target named '{GetRunInformationTaskName}' 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}'.")); } - if (runInfoResult.ResultCode != TargetResultCode.Success) + string runArguments = projectInstance.GetPropertyValue("RunArguments"); + string runWorkingDirectory = projectInstance.GetPropertyValue("RunWorkingDirectory"); + + 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 +128,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); - } - } } }