Merge pull request #133 from dotnet/anurse/dotnet-run
dotnet-run command
This commit is contained in:
commit
a65303dd76
11 changed files with 167 additions and 15 deletions
|
@ -70,6 +70,10 @@ echo Building stage1 dotnet-publish.exe ...
|
||||||
dotnet publish --framework "%TFM%" --runtime "%RID%" --output "%STAGE1_DIR%" --configuration "%CONFIGURATION%" "%REPOROOT%\src\Microsoft.DotNet.Tools.Resgen"
|
dotnet publish --framework "%TFM%" --runtime "%RID%" --output "%STAGE1_DIR%" --configuration "%CONFIGURATION%" "%REPOROOT%\src\Microsoft.DotNet.Tools.Resgen"
|
||||||
if errorlevel 1 goto fail
|
if errorlevel 1 goto fail
|
||||||
|
|
||||||
|
echo Building stage1 dotnet-run.exe ...
|
||||||
|
dotnet publish --framework "%TFM%" --runtime "%RID%" --output "%STAGE1_DIR%" --configuration "%CONFIGURATION%" "%REPOROOT%\src\Microsoft.DotNet.Tools.Run"
|
||||||
|
if errorlevel 1 goto fail
|
||||||
|
|
||||||
REM deploy corehost.exe to the output
|
REM deploy corehost.exe to the output
|
||||||
copy "%HOST_DIR%\corehost.exe" "%STAGE1_DIR%"
|
copy "%HOST_DIR%\corehost.exe" "%STAGE1_DIR%"
|
||||||
if errorlevel 1 goto fail
|
if errorlevel 1 goto fail
|
||||||
|
@ -103,6 +107,10 @@ echo Building stage2 dotnet-publish.exe ...
|
||||||
dotnet publish --framework "%TFM%" --runtime "%RID%" --output "%STAGE2_DIR%" --configuration "%CONFIGURATION%" "%REPOROOT%\src\Microsoft.DotNet.Tools.Resgen"
|
dotnet publish --framework "%TFM%" --runtime "%RID%" --output "%STAGE2_DIR%" --configuration "%CONFIGURATION%" "%REPOROOT%\src\Microsoft.DotNet.Tools.Resgen"
|
||||||
if errorlevel 1 goto fail
|
if errorlevel 1 goto fail
|
||||||
|
|
||||||
|
echo Building stage2 dotnet-run.exe ...
|
||||||
|
dotnet publish --framework "%TFM%" --runtime "%RID%" --output "%STAGE2_DIR%" --configuration "%CONFIGURATION%" "%REPOROOT%\src\Microsoft.DotNet.Tools.Run"
|
||||||
|
if errorlevel 1 goto fail
|
||||||
|
|
||||||
REM deploy corehost.exe to the output
|
REM deploy corehost.exe to the output
|
||||||
copy "%HOST_DIR%\corehost.exe" "%STAGE2_DIR%"
|
copy "%HOST_DIR%\corehost.exe" "%STAGE2_DIR%"
|
||||||
if errorlevel 1 goto fail
|
if errorlevel 1 goto fail
|
||||||
|
|
|
@ -66,6 +66,7 @@ dotnet publish --framework "$TFM" --runtime $RID --output "$STAGE1_DIR" --config
|
||||||
dotnet publish --framework "$TFM" --runtime $RID --output "$STAGE1_DIR" --configuration "$CONFIGURATION" "$REPOROOT/src/Microsoft.DotNet.Tools.Compiler.Csc"
|
dotnet publish --framework "$TFM" --runtime $RID --output "$STAGE1_DIR" --configuration "$CONFIGURATION" "$REPOROOT/src/Microsoft.DotNet.Tools.Compiler.Csc"
|
||||||
dotnet publish --framework "$TFM" --runtime $RID --output "$STAGE1_DIR" --configuration "$CONFIGURATION" "$REPOROOT/src/Microsoft.DotNet.Tools.Publish"
|
dotnet publish --framework "$TFM" --runtime $RID --output "$STAGE1_DIR" --configuration "$CONFIGURATION" "$REPOROOT/src/Microsoft.DotNet.Tools.Publish"
|
||||||
dotnet publish --framework "$TFM" --runtime $RID --output "$STAGE1_DIR" --configuration "$CONFIGURATION" "$REPOROOT/src/Microsoft.DotNet.Tools.Resgen"
|
dotnet publish --framework "$TFM" --runtime $RID --output "$STAGE1_DIR" --configuration "$CONFIGURATION" "$REPOROOT/src/Microsoft.DotNet.Tools.Resgen"
|
||||||
|
dotnet publish --framework "$TFM" --runtime $RID --output "$STAGE1_DIR" --configuration "$CONFIGURATION" "$REPOROOT/src/Microsoft.DotNet.Tools.Run"
|
||||||
|
|
||||||
# Deploy CLR host to the output
|
# Deploy CLR host to the output
|
||||||
cp "$HOST_DIR/corehost" "$STAGE1_DIR"
|
cp "$HOST_DIR/corehost" "$STAGE1_DIR"
|
||||||
|
@ -82,6 +83,7 @@ dotnet publish --framework "$TFM" --runtime $RID --output "$STAGE2_DIR" --config
|
||||||
dotnet publish --framework "$TFM" --runtime $RID --output "$STAGE2_DIR" --configuration "$CONFIGURATION" "$REPOROOT/src/Microsoft.DotNet.Tools.Compiler.Csc"
|
dotnet publish --framework "$TFM" --runtime $RID --output "$STAGE2_DIR" --configuration "$CONFIGURATION" "$REPOROOT/src/Microsoft.DotNet.Tools.Compiler.Csc"
|
||||||
dotnet publish --framework "$TFM" --runtime $RID --output "$STAGE2_DIR" --configuration "$CONFIGURATION" "$REPOROOT/src/Microsoft.DotNet.Tools.Publish"
|
dotnet publish --framework "$TFM" --runtime $RID --output "$STAGE2_DIR" --configuration "$CONFIGURATION" "$REPOROOT/src/Microsoft.DotNet.Tools.Publish"
|
||||||
dotnet publish --framework "$TFM" --runtime $RID --output "$STAGE2_DIR" --configuration "$CONFIGURATION" "$REPOROOT/src/Microsoft.DotNet.Tools.Resgen"
|
dotnet publish --framework "$TFM" --runtime $RID --output "$STAGE2_DIR" --configuration "$CONFIGURATION" "$REPOROOT/src/Microsoft.DotNet.Tools.Resgen"
|
||||||
|
dotnet publish --framework "$TFM" --runtime $RID --output "$STAGE2_DIR" --configuration "$CONFIGURATION" "$REPOROOT/src/Microsoft.DotNet.Tools.Run"
|
||||||
|
|
||||||
# Deploy CLR host to the output
|
# Deploy CLR host to the output
|
||||||
cp "$HOST_DIR/corehost" "$STAGE2_DIR"
|
cp "$HOST_DIR/corehost" "$STAGE2_DIR"
|
||||||
|
|
|
@ -156,6 +156,12 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
_stdErrCapture?.GetStringBuilder()?.ToString());
|
_stdErrCapture?.GetStringBuilder()?.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Command EnvironmentVariable(string name, string value)
|
||||||
|
{
|
||||||
|
_process.StartInfo.Environment.Add(name, value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Command CaptureStdOut()
|
public Command CaptureStdOut()
|
||||||
{
|
{
|
||||||
ThrowIfRunning();
|
ThrowIfRunning();
|
||||||
|
|
|
@ -4,9 +4,6 @@
|
||||||
"compilationOptions": {
|
"compilationOptions": {
|
||||||
"emitEntryPoint": true
|
"emitEntryPoint": true
|
||||||
},
|
},
|
||||||
"commands": {
|
|
||||||
"dotnet": "Microsoft.DotNet.Cli"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.NETCore.Runtime": "1.0.1-beta-23428",
|
"Microsoft.NETCore.Runtime": "1.0.1-beta-23428",
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,6 @@
|
||||||
"compilationOptions": {
|
"compilationOptions": {
|
||||||
"emitEntryPoint": true
|
"emitEntryPoint": true
|
||||||
},
|
},
|
||||||
"commands": {
|
|
||||||
"dotnet-compile-csc": "Microsoft.DotNet.Tools.Compiler.Csc"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.NETCore.Runtime": "1.0.1-beta-23428",
|
"Microsoft.NETCore.Runtime": "1.0.1-beta-23428",
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,6 @@
|
||||||
"compilationOptions": {
|
"compilationOptions": {
|
||||||
"emitEntryPoint": true
|
"emitEntryPoint": true
|
||||||
},
|
},
|
||||||
"commands": {
|
|
||||||
"dotnet-compile": "Microsoft.DotNet.Tools.Compiler"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.NETCore.Runtime": "1.0.1-beta-23428",
|
"Microsoft.NETCore.Runtime": "1.0.1-beta-23428",
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,6 @@
|
||||||
"compilationOptions": {
|
"compilationOptions": {
|
||||||
"emitEntryPoint": true
|
"emitEntryPoint": true
|
||||||
},
|
},
|
||||||
"commands": {
|
|
||||||
"dotnet-publish": "Microsoft.DotNet.Tools.Publish"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.NETCore.Runtime": "1.0.1-beta-23428",
|
"Microsoft.NETCore.Runtime": "1.0.1-beta-23428",
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,6 @@
|
||||||
"compilationOptions": {
|
"compilationOptions": {
|
||||||
"emitEntryPoint": true
|
"emitEntryPoint": true
|
||||||
},
|
},
|
||||||
"commands": {
|
|
||||||
"resgen": "Microsoft.DotNet.Tools.Resgen"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.NETCore.Runtime": "1.0.1-beta-23428",
|
"Microsoft.NETCore.Runtime": "1.0.1-beta-23428",
|
||||||
"System.Console": "4.0.0-beta-23428",
|
"System.Console": "4.0.0-beta-23428",
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||||
|
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<ProjectGuid>0a309227-a9d8-4ddf-88dd-326b57b04378</ProjectGuid>
|
||||||
|
<RootNamespace>Microsoft.DotNet.Tools.Compiler</RootNamespace>
|
||||||
|
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||||
|
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||||
|
</Project>
|
101
src/Microsoft.DotNet.Tools.Run/Program.cs
Normal file
101
src/Microsoft.DotNet.Tools.Run/Program.cs
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using Microsoft.Dnx.Runtime.Common.CommandLine;
|
||||||
|
using Microsoft.DotNet.Cli.Utils;
|
||||||
|
using Microsoft.DotNet.Tools.Common;
|
||||||
|
using Microsoft.Extensions.ProjectModel;
|
||||||
|
using Microsoft.Extensions.ProjectModel.Compilation;
|
||||||
|
using NuGet.Frameworks;
|
||||||
|
|
||||||
|
namespace Microsoft.DotNet.Tools.Compiler
|
||||||
|
{
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
public static int Main(string[] args)
|
||||||
|
{
|
||||||
|
DebugHelper.HandleDebugSwitch(ref args);
|
||||||
|
|
||||||
|
var app = new CommandLineApplication(throwOnUnexpectedArg: false);
|
||||||
|
app.Name = "dotnet run";
|
||||||
|
app.FullName = ".NET Executor";
|
||||||
|
app.Description = "Runner for the .NET Platform";
|
||||||
|
app.HelpOption("-h|--help");
|
||||||
|
|
||||||
|
var framework = app.Option("-f|--framework <FRAMEWORK>", "Compile a specific framework", CommandOptionType.MultipleValue);
|
||||||
|
var configuration = app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", CommandOptionType.SingleValue);
|
||||||
|
var preserveTemporaryOutput = app.Option("-p|--preserve-temporary", "Configuration under which to build", CommandOptionType.NoValue);
|
||||||
|
var project = app.Argument("<PROJECT>", "The project to compile, defaults to the current directory. Can be a path to a project.json or a project directory");
|
||||||
|
|
||||||
|
app.OnExecute(() =>
|
||||||
|
{
|
||||||
|
// Locate the project and get the name and full path
|
||||||
|
var path = project.Value;
|
||||||
|
if (string.IsNullOrEmpty(path))
|
||||||
|
{
|
||||||
|
path = Directory.GetCurrentDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
|
var contexts = ProjectContext.CreateContextForEachFramework(path);
|
||||||
|
if (!framework.HasValue())
|
||||||
|
{
|
||||||
|
return Run(contexts.First(), configuration.Value() ?? Constants.DefaultConfiguration, app.RemainingArguments, preserveTemporaryOutput.HasValue());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var context = contexts.FirstOrDefault(c => c.TargetFramework.Equals(NuGetFramework.Parse(framework.Value())));
|
||||||
|
return Run(context, configuration.Value() ?? Constants.DefaultConfiguration, app.RemainingArguments, preserveTemporaryOutput.HasValue());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return app.Execute(args);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Console.Error.WriteLine(ex);
|
||||||
|
#else
|
||||||
|
Console.Error.WriteLine(ex.Message);
|
||||||
|
#endif
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int Run(ProjectContext context, string configuration, IEnumerable<string> remainingArguments, bool preserveTemporaryOutput)
|
||||||
|
{
|
||||||
|
// Create a temporary directory
|
||||||
|
var tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
|
||||||
|
|
||||||
|
// Compile to that directory
|
||||||
|
var result = Command.Create($"dotnet-compile", $"--output \"{tempDir}\" --framework \"{context.TargetFramework}\" --configuration \"{configuration}\"")
|
||||||
|
.ForwardStdOut()
|
||||||
|
.ForwardStdErr()
|
||||||
|
.Execute();
|
||||||
|
if (result.ExitCode != 0)
|
||||||
|
{
|
||||||
|
Reporter.Error.WriteLine($"Failed to compile {context.RootProject.Identity.Name}".Red().Bold());
|
||||||
|
return result.ExitCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now launch the output and give it the results
|
||||||
|
var outputName = Path.Combine(tempDir, context.ProjectFile.Name + Constants.ExeSuffix);
|
||||||
|
result = Command.Create(outputName, string.Join(" ", remainingArguments))
|
||||||
|
.ForwardStdOut()
|
||||||
|
.ForwardStdErr()
|
||||||
|
.EnvironmentVariable("CLRHOST_CLR_PATH", AppContext.BaseDirectory)
|
||||||
|
.Execute();
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
if (!preserveTemporaryOutput)
|
||||||
|
{
|
||||||
|
Directory.Delete(tempDir, recursive: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.ExitCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
src/Microsoft.DotNet.Tools.Run/project.json
Normal file
30
src/Microsoft.DotNet.Tools.Run/project.json
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
{
|
||||||
|
"name": "dotnet-run",
|
||||||
|
"version": "1.0.0-*",
|
||||||
|
"compilationOptions": {
|
||||||
|
"emitEntryPoint": true
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"Microsoft.NETCore.Runtime": "1.0.1-beta-23428",
|
||||||
|
|
||||||
|
"System.Console": "4.0.0-beta-23428",
|
||||||
|
"System.Collections": "4.0.11-beta-23428",
|
||||||
|
"System.Linq": "4.0.1-beta-23428",
|
||||||
|
"System.Diagnostics.Process": "4.1.0-beta-23428",
|
||||||
|
"System.IO.FileSystem": "4.0.1-beta-23428",
|
||||||
|
|
||||||
|
"Microsoft.DotNet.ProjectModel": "1.0.0-*",
|
||||||
|
"Microsoft.DotNet.Cli.Utils": {
|
||||||
|
"type": "build",
|
||||||
|
"version": "1.0.0-*"
|
||||||
|
},
|
||||||
|
"Microsoft.Extensions.CommandLineUtils.Sources": {
|
||||||
|
"type": "build",
|
||||||
|
"version": "1.0.0-*"
|
||||||
|
},
|
||||||
|
"Microsoft.Net.Compilers.netcore": "1.1.0-*"
|
||||||
|
},
|
||||||
|
"frameworks": {
|
||||||
|
"dnxcore50": { }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue