Merge pull request #4240 from livarcocc/more_run_params

More run params
This commit is contained in:
Livar 2016-09-23 16:09:36 -07:00 committed by GitHub
commit ee7400bd41
4 changed files with 119 additions and 2 deletions

View file

@ -21,14 +21,22 @@ namespace Microsoft.DotNet.Tools.Run
app.AllowArgumentSeparator = true;
app.HelpOption("-h|--help");
CommandOption configuration = app.Option("-c|--configuration", "Configuration under which to build", CommandOptionType.SingleValue);
CommandOption project = app.Option("-p|--project", "The path to the project file to run (defaults to the current directory if there is only one project).", CommandOptionType.SingleValue);
CommandOption configuration = app.Option(
"-c|--configuration", "Configuration under which to build",
CommandOptionType.SingleValue);
CommandOption framework = app.Option(
"-f|--framework <FRAMEWORK>", "Compile a specific framework",
CommandOptionType.SingleValue);
CommandOption project = app.Option(
"-p|--project", "The path to the project file to run (defaults to the current directory if there is only one project).",
CommandOptionType.SingleValue);
app.OnExecute(() =>
{
Run3Command runCmd = new Run3Command();
runCmd.Configuration = configuration.Value();
runCmd.Framework = framework.Value();
runCmd.Project = project.Value();
runCmd.Args = app.RemainingArguments;

View file

@ -14,6 +14,7 @@ namespace Microsoft.DotNet.Tools.Run
public partial class Run3Command
{
public string Configuration { get; set; }
public string Framework { get; set; }
public string Project { get; set; }
public IReadOnlyList<string> Args { get; set; }
@ -48,6 +49,11 @@ namespace Microsoft.DotNet.Tools.Run
buildArgs.Add($"/p:Configuration={Configuration}");
}
if (!string.IsNullOrWhiteSpace(Framework))
{
buildArgs.Add($"/p:TargetFramework={Framework}");
}
var buildResult = new MSBuildForwardingApp(buildArgs).Execute();
if (buildResult != 0)
@ -69,6 +75,11 @@ namespace Microsoft.DotNet.Tools.Run
globalProperties.Add("Configuration", Configuration);
}
if (!string.IsNullOrWhiteSpace(Framework))
{
globalProperties.Add("TargetFramework", Framework);
}
ProjectInstance projectInstance = new ProjectInstance(Project, globalProperties, null);
string runProgram = projectInstance.GetPropertyValue("RunCommand");

View file

@ -0,0 +1,74 @@
// 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 Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Cli.Run3.Tests
{
public class GivenDotnetRun3BuildsCsproj : TestBase
{
[Fact]
public void ItCanRunAMSBuildProject()
{
var testAppName = "MSBuildTestApp";
var testInstance = TestAssetsManager
.CreateTestInstance(testAppName)
.WithLockFiles();
var testProjectDirectory = testInstance.TestRoot;
new Build3Command()
.WithWorkingDirectory(testProjectDirectory)
.Execute()
.Should()
.Pass();
new Run3Command()
.WithWorkingDirectory(testProjectDirectory)
.ExecuteWithCapturedOutput()
.Should()
.Pass()
.And
.HaveStdOutContaining("Hello World!");
}
[Fact]
public void ItBuildsTheProjectBeforeRunning()
{
var testAppName = "MSBuildTestApp";
var testInstance = TestAssetsManager
.CreateTestInstance(testAppName)
.WithLockFiles();
var testProjectDirectory = testInstance.TestRoot;
new Run3Command()
.WithWorkingDirectory(testProjectDirectory)
.ExecuteWithCapturedOutput()
.Should()
.Pass()
.And
.HaveStdOutContaining("Hello World!");
}
[Fact]
public void ItCanRunAMSBuildProjectWhenSpecifyingAFramework()
{
var testAppName = "MSBuildTestApp";
var testInstance = TestAssetsManager
.CreateTestInstance(testAppName)
.WithLockFiles();
var testProjectDirectory = testInstance.TestRoot;
new Run3Command()
.WithWorkingDirectory(testProjectDirectory)
.ExecuteWithCapturedOutput("--framework netcoreapp1.0")
.Should()
.Pass()
.And
.HaveStdOutContaining("Hello World!");
}
}
}

View file

@ -0,0 +1,24 @@
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
},
"System.Runtime.Serialization.Primitives": "4.1.1",
"Microsoft.DotNet.Tools.Tests.Utilities": {
"target": "project"
},
"xunit": "2.2.0-beta3-build3330",
"dotnet-test-xunit": "1.0.0-rc2-350904-49"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.4",
"portable-net451+win8"
]
}
},
"testRunner": "xunit"
}