Implement 'run3' command which will execute the MSBuild project.
Also create a 'dotnet new -t msbuild' template.
This commit is contained in:
parent
bccff16c18
commit
b068687413
15 changed files with 331 additions and 37 deletions
|
@ -147,10 +147,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{FF498306-2
|
|||
build\test\TestPackageProjects.props = build\test\TestPackageProjects.props
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.Core.Sdk", "src\Microsoft.DotNet.Core.MSBuild\Microsoft.DotNet.Core.Sdk.xproj", "{556554CA-6EC9-4007-A2C3-AB03DCF8F741}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.Core.Build.Tasks", "src\Microsoft.DotNet.Core.Build.Tasks\Microsoft.DotNet.Core.Build.Tasks.xproj", "{E8E7D24B-4830-4662-80A8-255D6FE3B0BE}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.Core.Sdk", "src\Microsoft.DotNet.Core.Sdk\Microsoft.DotNet.Core.Sdk.xproj", "{556554CA-6EC9-4007-A2C3-AB03DCF8F741}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -899,22 +899,6 @@ Global
|
|||
{49D7318E-D198-4E2B-BBEA-3A24D805F88D}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
|
||||
{49D7318E-D198-4E2B-BBEA-3A24D805F88D}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
|
||||
{49D7318E-D198-4E2B-BBEA-3A24D805F88D}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.MinSizeRel|x64.Build.0 = Debug|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.Release|x64.Build.0 = Release|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
|
||||
{E8E7D24B-4830-4662-80A8-255D6FE3B0BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E8E7D24B-4830-4662-80A8-255D6FE3B0BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E8E7D24B-4830-4662-80A8-255D6FE3B0BE}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
|
@ -931,6 +915,22 @@ Global
|
|||
{E8E7D24B-4830-4662-80A8-255D6FE3B0BE}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
|
||||
{E8E7D24B-4830-4662-80A8-255D6FE3B0BE}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
|
||||
{E8E7D24B-4830-4662-80A8-255D6FE3B0BE}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.MinSizeRel|x64.Build.0 = Debug|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.Release|x64.Build.0 = Release|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -990,7 +990,7 @@ Global
|
|||
{FD7D515A-D10F-4F49-B8AE-21CF7ED071AE} = {89905EC4-BC0F-443B-8ADF-691321F10108}
|
||||
{8E3354BD-827F-41B7-9EE6-6BE1F1EDD8E9} = {89905EC4-BC0F-443B-8ADF-691321F10108}
|
||||
{FF498306-2DE2-47F6-8C35-3CF0589CF2B8} = {89905EC4-BC0F-443B-8ADF-691321F10108}
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F}
|
||||
{E8E7D24B-4830-4662-80A8-255D6FE3B0BE} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F}
|
||||
{556554CA-6EC9-4007-A2C3-AB03DCF8F741} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
"Microsoft.NETCore.App": {
|
||||
"version": "1.0.0",
|
||||
"type": "platform"
|
||||
},
|
||||
"Microsoft.DotNet.Core.MSBuild": "1.0.0-preview3"
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>e8e7d24b-4830-4662-80a8-255d6fe3b0be</ProjectGuid>
|
||||
<RootNamespace>Microsoft.DotNet.Core.MSBuild</RootNamespace>
|
||||
<RootNamespace>Microsoft.DotNet.Core.Build.Tasks</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>556554ca-6ec9-4007-a2c3-ab03dcf8f741</ProjectGuid>
|
||||
<RootNamespace>Microsoft.DotNet.Core.MSBuild</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
|
||||
<RootNamespace>Microsoft.DotNet.Core.Sdk</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
|
@ -4,7 +4,9 @@
|
|||
<MicrosoftDotNetCoreBuildTasksTFM Condition=" '$(MSBuildRuntimeType)' == 'Core'">netstandard1.6</MicrosoftDotNetCoreBuildTasksTFM>
|
||||
<MicrosoftDotNetCoreBuildTasksTFM Condition=" '$(MicrosoftDotNetCoreBuildTasksTFM)' == ''">net451</MicrosoftDotNetCoreBuildTasksTFM>
|
||||
<MicrosoftDotNetCoreBuildTasksDirectory>$(MicrosoftDotNetCoreBuildTasksDirectoryRoot)$(MicrosoftDotNetCoreBuildTasksTFM)/</MicrosoftDotNetCoreBuildTasksDirectory>
|
||||
|
||||
|
||||
<!-- If the build task directory doesn't exist (since we aren't in a NuGet package), load the task assembly in the tools path -->
|
||||
<MicrosoftDotNetCoreBuildTasksDirectory Condition=" !Exists('$(MicrosoftDotNetCoreBuildTasksDirectory)') ">$(MSBuildToolsPath)/</MicrosoftDotNetCoreBuildTasksDirectory>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
@ -16,7 +18,7 @@
|
|||
<_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory)</_FullFrameworkReferenceAssemblyPaths>
|
||||
</PropertyGroup>
|
||||
|
||||
<UsingTask TaskName="MakeNetCoreRunnable" AssemblyFile="$(MicrosoftDotNetCoreBuildTasksDirectory)/Microsoft.DotNet.Core.Build.Tasks.dll" />
|
||||
<UsingTask TaskName="MakeNetCoreRunnable" AssemblyFile="$(MicrosoftDotNetCoreBuildTasksDirectory)Microsoft.DotNet.Core.Build.Tasks.dll" />
|
||||
|
||||
<PropertyGroup>
|
||||
<CoreBuildDependsOn>
|
||||
|
@ -49,6 +51,28 @@
|
|||
<!-- Putting this here to show the structure that we should use in production -->
|
||||
</Target>
|
||||
|
||||
<!--
|
||||
============================================================
|
||||
GetRunInformation
|
||||
|
||||
Returns the ProcessStart information that can be used to run this project.
|
||||
============================================================
|
||||
-->
|
||||
|
||||
<Target Name="GetRunInformation"
|
||||
DependsOnTargets="GenerateRunInformation"
|
||||
Outputs="@(RunInformation)" />
|
||||
|
||||
<Target Name="GenerateRunInformation">
|
||||
<ItemGroup>
|
||||
<RunInformation Include="$(MSBuildProjectFullPath)">
|
||||
<!-- TODO: Need to get the Muxer path from MSBuild -->
|
||||
<CommandName>dotnet</CommandName>
|
||||
<Args>exec;$(TargetDir)/$(AssemblyName).dll</Args>
|
||||
</RunInformation>
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
<!--
|
||||
============================================================
|
||||
Publish
|
|
@ -36,7 +36,8 @@ namespace Microsoft.DotNet.Cli
|
|||
["restore"] = RestoreCommand.Run,
|
||||
["run"] = RunCommand.Run,
|
||||
["test"] = TestCommand.Run,
|
||||
["build3"] = Build3Command.Run
|
||||
["build3"] = Build3Command.Run,
|
||||
["run3"] = Run3Command.Run
|
||||
};
|
||||
|
||||
public static int Main(string[] args)
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier>
|
||||
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="**\*.cs" Exclude="$(GlobalExclude)" />
|
||||
<EmbeddedResource Include="**\*.resx" Exclude="$(GlobalExclude)" />
|
||||
<None Include="project.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
12
src/dotnet/commands/dotnet-new/CSharp_MSBuild/Program.cs
Normal file
12
src/dotnet/commands/dotnet-new/CSharp_MSBuild/Program.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello World!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"runtimes": {
|
||||
"$currentruntime$": {}
|
||||
}
|
||||
}
|
|
@ -1,14 +1,15 @@
|
|||
// 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.Cli.CommandLine;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.IO.Compression;
|
||||
using Microsoft.DotNet.Cli.CommandLine;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.InternalAbstractions;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.New
|
||||
{
|
||||
|
@ -64,11 +65,37 @@ namespace Microsoft.DotNet.Tools.New
|
|||
}
|
||||
}
|
||||
|
||||
archive.ExtractToDirectory(Directory.GetCurrentDirectory());
|
||||
string projectDirectory = Directory.GetCurrentDirectory();
|
||||
|
||||
archive.ExtractToDirectory(projectDirectory);
|
||||
|
||||
string projectJsonFile = Path.Combine(projectDirectory, "project.json");
|
||||
|
||||
File.Move(
|
||||
Path.Combine(Directory.GetCurrentDirectory(), "project.json.template"),
|
||||
Path.Combine(Directory.GetCurrentDirectory(), "project.json"));
|
||||
Path.Combine(projectDirectory, "project.json.template"),
|
||||
projectJsonFile);
|
||||
|
||||
string originalProjectJsonText = File.ReadAllText(projectJsonFile);
|
||||
string replacedProjectJsonText = originalProjectJsonText
|
||||
.Replace("$currentruntime$", RuntimeEnvironment.GetRuntimeIdentifier());
|
||||
|
||||
if (replacedProjectJsonText != originalProjectJsonText)
|
||||
{
|
||||
File.WriteAllText(projectJsonFile, replacedProjectJsonText);
|
||||
}
|
||||
|
||||
string projectName = new DirectoryInfo(projectDirectory).Name;
|
||||
foreach (string file in Directory.GetFiles(projectDirectory, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
if (Path.GetFileNameWithoutExtension(file) == "$projectName$")
|
||||
{
|
||||
string extension = Path.GetExtension(file);
|
||||
|
||||
File.Move(
|
||||
file,
|
||||
Path.Combine(Path.GetDirectoryName(file), $"{projectName}{extension}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
|
@ -99,7 +126,7 @@ namespace Microsoft.DotNet.Tools.New
|
|||
app.Description = "Initializes empty project for .NET Platform";
|
||||
app.HelpOption("-h|--help");
|
||||
|
||||
var csharp = new { Name = "C#", Alias = new[] { "c#", "cs", "csharp" }, TemplatePrefix = "CSharp", Templates = new[] { "Console", "Web", "Lib", "xunittest" } };
|
||||
var csharp = new { Name = "C#", Alias = new[] { "c#", "cs", "csharp" }, TemplatePrefix = "CSharp", Templates = new[] { "Console", "Web", "Lib", "xunittest", "MSBuild" } };
|
||||
var fsharp = new { Name = "F#", Alias = new[] { "f#", "fs", "fsharp" }, TemplatePrefix = "FSharp", Templates = new[] { "Console", "Lib" } };
|
||||
|
||||
var languages = new[] { csharp, fsharp };
|
||||
|
|
60
src/dotnet/commands/dotnet-run3/Program.cs
Normal file
60
src/dotnet/commands/dotnet-run3/Program.cs
Normal file
|
@ -0,0 +1,60 @@
|
|||
// 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 System;
|
||||
using Microsoft.DotNet.Cli.CommandLine;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Run
|
||||
{
|
||||
public partial class Run3Command
|
||||
{
|
||||
public static int Run(string[] args)
|
||||
{
|
||||
DebugHelper.HandleDebugSwitch(ref args);
|
||||
|
||||
CommandLineApplication app = new CommandLineApplication(throwOnUnexpectedArg: false);
|
||||
app.Name = "dotnet run3";
|
||||
app.FullName = ".NET Run3 Command";
|
||||
app.Description = "Command used to run .NET apps";
|
||||
app.HandleResponseFiles = true;
|
||||
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);
|
||||
|
||||
app.OnExecute(() =>
|
||||
{
|
||||
Run3Command runCmd = new Run3Command();
|
||||
|
||||
runCmd.Configuration = configuration.Value();
|
||||
runCmd.Project = project.Value();
|
||||
runCmd.Args = app.RemainingArguments;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
132
src/dotnet/commands/dotnet-run3/Run3Command.cs
Normal file
132
src/dotnet/commands/dotnet-run3/Run3Command.cs
Normal file
|
@ -0,0 +1,132 @@
|
|||
// 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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.Build.Execution;
|
||||
using Microsoft.Build.Framework;
|
||||
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<string> Args { get; set; }
|
||||
|
||||
private readonly ICommandFactory _commandFactory;
|
||||
private List<string> _args;
|
||||
|
||||
public Run3Command()
|
||||
: this(new RunCommandFactory())
|
||||
{
|
||||
}
|
||||
|
||||
public Run3Command(ICommandFactory commandFactory)
|
||||
{
|
||||
_commandFactory = commandFactory;
|
||||
}
|
||||
|
||||
public int Start()
|
||||
{
|
||||
Initialize();
|
||||
|
||||
ITaskItem runInfoItem = GetRunInformation();
|
||||
|
||||
string commandName = runInfoItem.GetMetadata("CommandName");
|
||||
string[] args = runInfoItem.GetMetadata("Args").Split(';');
|
||||
|
||||
ICommand command = _commandFactory.Create(commandName, Enumerable.Concat(args, _args));
|
||||
|
||||
return command
|
||||
.Execute()
|
||||
.ExitCode;
|
||||
}
|
||||
|
||||
private ITaskItem GetRunInformation()
|
||||
{
|
||||
Dictionary<string, string> globalProperties = new Dictionary<string, string>()
|
||||
{
|
||||
{ "MSBuildExtensionsPath", AppContext.BaseDirectory }
|
||||
};
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Configuration))
|
||||
{
|
||||
globalProperties.Add("Configuration", Configuration);
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
throw new InvalidOperationException($"Could not find a target named '{GetRunInformationTaskName}' in your project. Please ensure 'dotnet run' supports this project.");
|
||||
}
|
||||
|
||||
if (runInfoResult.ResultCode != TargetResultCode.Success)
|
||||
{
|
||||
throw new InvalidOperationException($"Could not get the run information for project {Project}. An internal MSBuild error has occured" + Environment.NewLine +
|
||||
runInfoResult.Exception?.ToString());
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
return runInfoItem;
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Project))
|
||||
{
|
||||
string directory = Directory.GetCurrentDirectory();
|
||||
string[] projectFiles = Directory.GetFiles(directory, "*.*proj");
|
||||
|
||||
if (projectFiles.Length == 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Couldn't find a project to run. Ensure a project exists in {directory}." + Environment.NewLine +
|
||||
"Or pass the path to the project using --project");
|
||||
}
|
||||
else if (projectFiles.Length > 1)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Specify which project file to use because this '{directory}' contains more than one project file.");
|
||||
}
|
||||
|
||||
Project = projectFiles[0];
|
||||
}
|
||||
|
||||
if (Args == null)
|
||||
{
|
||||
_args = new List<string>();
|
||||
}
|
||||
else
|
||||
{
|
||||
_args = new List<string>(Args);
|
||||
}
|
||||
}
|
||||
|
||||
private class RunCommandFactory : ICommandFactory
|
||||
{
|
||||
public ICommand Create(string commandName, IEnumerable<string> args, NuGetFramework framework = null, string configuration = Constants.DefaultConfiguration)
|
||||
{
|
||||
return Command.Create(commandName, args, framework, configuration);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@
|
|||
"include": [
|
||||
"commands/dotnet-new/CSharp_Console.zip",
|
||||
"commands/dotnet-new/CSharp_Lib.zip",
|
||||
"commands/dotnet-new/CSharp_MSBuild.zip",
|
||||
"commands/dotnet-new/CSharp_xunittest.zip",
|
||||
"commands/dotnet-new/CSharp_Web.zip",
|
||||
"commands/dotnet-new/FSharp_Console.zip",
|
||||
|
@ -18,6 +19,7 @@
|
|||
"commands/dotnet-new/FSharp_Console/**",
|
||||
"commands/dotnet-new/CSharp_Web/**",
|
||||
"commands/dotnet-new/CSharp_Lib/**",
|
||||
"commands/dotnet-new/CSharp_MSBuild/**",
|
||||
"commands/dotnet-new/FSharp_Lib/**",
|
||||
"commands/dotnet-new/CSharp_xunittest/**"
|
||||
]
|
||||
|
@ -28,7 +30,7 @@
|
|||
"14.1/**"
|
||||
],
|
||||
"mappings": {
|
||||
"NETCore/": "../Microsoft.DotNet.Core.MSBuild/build/netstandard1.0/*"
|
||||
"NETCore/": "../Microsoft.DotNet.Core.Sdk/build/netstandard1.0/*"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
|
@ -80,7 +82,11 @@
|
|||
"Microsoft.Net.Compilers.Targets.NetCore": "0.1.5-dev",
|
||||
"Microsoft.Cci": "4.0.0-rc3-24128-00",
|
||||
"Microsoft.Composition": "1.0.30",
|
||||
"Microsoft.NuGet.Build.Tasks": "1.0.0-alpha-000001"
|
||||
"Microsoft.NuGet.Build.Tasks": "1.0.0-alpha-000001",
|
||||
|
||||
"Microsoft.DotNet.Core.Build.Tasks": {
|
||||
"target": "project"
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
|
|
Loading…
Reference in a new issue