commit
c62433a3e6
7 changed files with 143 additions and 12 deletions
|
@ -174,6 +174,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-test3.Tests", "test\
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dotnet-cli-build", "build_projects\dotnet-cli-build\dotnet-cli-build.csproj", "{8A2FA2D8-0DA1-4814-B5C1-2ECEAA613EB1}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-run3.Tests", "test\dotnet-run3.Tests\dotnet-run3.Tests.xproj", "{9229D2A5-E2D1-4BEE-BC89-EFE65042842F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -1018,6 +1020,22 @@ Global
|
|||
{8A2FA2D8-0DA1-4814-B5C1-2ECEAA613EB1}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
|
||||
{8A2FA2D8-0DA1-4814-B5C1-2ECEAA613EB1}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
|
||||
{8A2FA2D8-0DA1-4814-B5C1-2ECEAA613EB1}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
|
||||
{9229D2A5-E2D1-4BEE-BC89-EFE65042842F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9229D2A5-E2D1-4BEE-BC89-EFE65042842F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9229D2A5-E2D1-4BEE-BC89-EFE65042842F}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{9229D2A5-E2D1-4BEE-BC89-EFE65042842F}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{9229D2A5-E2D1-4BEE-BC89-EFE65042842F}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9229D2A5-E2D1-4BEE-BC89-EFE65042842F}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9229D2A5-E2D1-4BEE-BC89-EFE65042842F}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
|
||||
{9229D2A5-E2D1-4BEE-BC89-EFE65042842F}.MinSizeRel|x64.Build.0 = Debug|Any CPU
|
||||
{9229D2A5-E2D1-4BEE-BC89-EFE65042842F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9229D2A5-E2D1-4BEE-BC89-EFE65042842F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9229D2A5-E2D1-4BEE-BC89-EFE65042842F}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{9229D2A5-E2D1-4BEE-BC89-EFE65042842F}.Release|x64.Build.0 = Release|Any CPU
|
||||
{9229D2A5-E2D1-4BEE-BC89-EFE65042842F}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9229D2A5-E2D1-4BEE-BC89-EFE65042842F}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
|
||||
{9229D2A5-E2D1-4BEE-BC89-EFE65042842F}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
|
||||
{9229D2A5-E2D1-4BEE-BC89-EFE65042842F}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -1083,5 +1101,6 @@ Global
|
|||
{FBE4F1D6-BA4C-46D9-8286-4EE4B032D01E} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
|
||||
{90236A80-4B84-41D3-A161-AA20709776B1} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
|
||||
{8A2FA2D8-0DA1-4814-B5C1-2ECEAA613EB1} = {88278B81-7649-45DC-8A6A-D3A645C5AFC3}
|
||||
{9229D2A5-E2D1-4BEE-BC89-EFE65042842F} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFrameworks>net451;netcoreapp1.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Sdk">
|
||||
<Version>1.0.0-alpha-20161010-1</Version>
|
||||
<PrivateAssets>All</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
|
||||
<PackageReference Include="Microsoft.NETCore.App">
|
||||
<Version>1.0.1</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="**\*.cs" />
|
||||
<EmbeddedResource Include="**\*.resx" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
Console.WriteLine("Hello World!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,6 +28,9 @@ namespace Microsoft.DotNet.Tools.Run
|
|||
CommandOption framework = app.Option(
|
||||
"-f|--framework <FRAMEWORK>", "Compile a specific framework",
|
||||
CommandOptionType.SingleValue);
|
||||
CommandOption noBuild = app.Option(
|
||||
"--no-build", "Do not build the project before running.",
|
||||
CommandOptionType.BoolValue);
|
||||
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);
|
||||
|
@ -38,6 +41,7 @@ namespace Microsoft.DotNet.Tools.Run
|
|||
|
||||
runCmd.Configuration = configuration.Value();
|
||||
runCmd.Framework = framework.Value();
|
||||
runCmd.NoBuild = noBuild.BoolValue ?? false;
|
||||
runCmd.Project = project.Value();
|
||||
runCmd.Args = app.RemainingArguments;
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.Build.Execution;
|
||||
using Microsoft.Build.Evaluation;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Tools.MSBuild;
|
||||
|
||||
|
@ -15,10 +15,12 @@ namespace Microsoft.DotNet.Tools.Run
|
|||
{
|
||||
public string Configuration { get; set; }
|
||||
public string Framework { get; set; }
|
||||
public bool NoBuild { get; set; }
|
||||
public string Project { get; set; }
|
||||
public IReadOnlyList<string> Args { get; set; }
|
||||
|
||||
private List<string> _args;
|
||||
private bool ShouldBuild => !NoBuild;
|
||||
|
||||
public Run3Command()
|
||||
{
|
||||
|
@ -28,7 +30,10 @@ namespace Microsoft.DotNet.Tools.Run
|
|||
{
|
||||
Initialize();
|
||||
|
||||
EnsureProjectIsBuilt();
|
||||
if (ShouldBuild)
|
||||
{
|
||||
EnsureProjectIsBuilt();
|
||||
}
|
||||
|
||||
ICommand runCommand = GetRunCommand();
|
||||
|
||||
|
@ -80,21 +85,16 @@ namespace Microsoft.DotNet.Tools.Run
|
|||
globalProperties.Add("TargetFramework", Framework);
|
||||
}
|
||||
|
||||
ProjectInstance projectInstance = new ProjectInstance(Project, globalProperties, null);
|
||||
Project project = new Project(Project, globalProperties, null);
|
||||
|
||||
string runProgram = projectInstance.GetPropertyValue("RunCommand");
|
||||
string runProgram = project.GetPropertyValue("RunCommand");
|
||||
if (string.IsNullOrEmpty(runProgram))
|
||||
{
|
||||
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}'."));
|
||||
ThrowUnableToRunError(project);
|
||||
}
|
||||
|
||||
string runArguments = projectInstance.GetPropertyValue("RunArguments");
|
||||
string runWorkingDirectory = projectInstance.GetPropertyValue("RunWorkingDirectory");
|
||||
string runArguments = project.GetPropertyValue("RunArguments");
|
||||
string runWorkingDirectory = project.GetPropertyValue("RunWorkingDirectory");
|
||||
|
||||
string fullArguments = runArguments;
|
||||
if (_args.Any())
|
||||
|
@ -108,6 +108,30 @@ namespace Microsoft.DotNet.Tools.Run
|
|||
.WorkingDirectory(runWorkingDirectory);
|
||||
}
|
||||
|
||||
private void ThrowUnableToRunError(Project project)
|
||||
{
|
||||
string unableToRunYourProjectMessage = "Unable to run your project.";
|
||||
|
||||
string targetFrameworks = project.GetPropertyValue("TargetFrameworks");
|
||||
if (!string.IsNullOrEmpty(targetFrameworks))
|
||||
{
|
||||
string targetFramework = project.GetPropertyValue("TargetFramework");
|
||||
if (string.IsNullOrEmpty(targetFramework))
|
||||
{
|
||||
throw new GracefulException(string.Join(Environment.NewLine,
|
||||
unableToRunYourProjectMessage,
|
||||
"Your project targets multiple frameworks. Please specify which framework to run using '--framework'."));
|
||||
}
|
||||
}
|
||||
|
||||
string outputType = project.GetPropertyValue("OutputType");
|
||||
|
||||
throw new GracefulException(string.Join(Environment.NewLine,
|
||||
unableToRunYourProjectMessage,
|
||||
"Please ensure you have a runnable project type and ensure 'dotnet run' supports this project.",
|
||||
$"The current OutputType is '{outputType}'."));
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Project))
|
||||
|
|
|
@ -87,5 +87,31 @@ namespace Microsoft.DotNet.Cli.Run3.Tests
|
|||
.And
|
||||
.HaveStdOutContaining("Hello World!");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ItReportsAGoodErrorWhenProjectHasMultipleFrameworks()
|
||||
{
|
||||
var testAppName = "MSBuildAppWithMultipleFrameworks";
|
||||
var testInstance = TestAssetsManager
|
||||
.CreateTestInstance(testAppName);
|
||||
|
||||
var testProjectDirectory = testInstance.TestRoot;
|
||||
|
||||
new Restore3Command()
|
||||
.WithWorkingDirectory(testProjectDirectory)
|
||||
.Execute("/p:SkipInvalidConfigurations=true")
|
||||
.Should()
|
||||
.Pass();
|
||||
|
||||
// use --no-build so this test can run on all platforms.
|
||||
// the test app targets net451, which can't be built on non-Windows
|
||||
new Run3Command()
|
||||
.WithWorkingDirectory(testProjectDirectory)
|
||||
.ExecuteWithCapturedOutput("--no-build")
|
||||
.Should()
|
||||
.Fail()
|
||||
.And
|
||||
.HaveStdErrContaining("--framework");
|
||||
}
|
||||
}
|
||||
}
|
18
test/dotnet-run3.Tests/dotnet-run3.Tests.xproj
Normal file
18
test/dotnet-run3.Tests/dotnet-run3.Tests.xproj
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0.24720" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.24720</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>9229D2A5-E2D1-4BEE-BC89-EFE65042842F</ProjectGuid>
|
||||
<RootNamespace>Microsoft.DotNet.Cli.Run3.Tests</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
Loading…
Reference in a new issue