Add Microsoft.DotNet.Tools.Interactive
This commit is contained in:
parent
54847cf032
commit
e2cdf17e2e
14 changed files with 278 additions and 37 deletions
|
@ -44,7 +44,7 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
|
||||
public static Command Create(string executable, IEnumerable<string> args)
|
||||
{
|
||||
return Create(executable, args.Any() ? string.Join(" ", args) : string.Empty);
|
||||
return Create(executable, string.Join(" ", args));
|
||||
}
|
||||
|
||||
public static Command Create(string executable, string args)
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
"dependencies": {
|
||||
"System.CommandLine": "0.1.0-*",
|
||||
"System.Linq": "4.0.1-beta-23502",
|
||||
"System.Runtime": "4.0.21-beta-23502",
|
||||
"System.Linq": "4.0.1-beta-23504",
|
||||
"System.Runtime": "4.0.21-beta-23504",
|
||||
"Microsoft.DotNet.ProjectModel": "1.0.0-*"
|
||||
},
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ namespace Microsoft.Extensions.ProjectModel
|
|||
{
|
||||
try
|
||||
{
|
||||
var buildVersion = Environment.GetEnvironmentVariable("DOETNET_BUILD_VERSION");
|
||||
var buildVersion = Environment.GetEnvironmentVariable("DOTNET_BUILD_VERSION");
|
||||
project.Version = SpecifySnapshot(version, buildVersion);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
@ -46,33 +46,23 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
|
||||
var buildProjectReferences = !noProjectDependencies.HasValue();
|
||||
var isNative = native.HasValue();
|
||||
var configValue = configuration.Value() ?? Constants.DefaultConfiguration;
|
||||
var outputValue = output.Value();
|
||||
|
||||
// Load project contexts for each framework and compile them
|
||||
bool success = true;
|
||||
if (framework.HasValue())
|
||||
var contexts = framework.HasValue() ?
|
||||
framework.Values.Select(f => ProjectContext.Create(path, NuGetFramework.Parse(f))) :
|
||||
ProjectContext.CreateContextForEachFramework(path);
|
||||
foreach (var context in contexts)
|
||||
{
|
||||
foreach (var context in framework.Values.Select(f => ProjectContext.Create(path, NuGetFramework.Parse(f))))
|
||||
success &= Compile(context, configValue, outputValue, intermediateOutput.Value(), buildProjectReferences);
|
||||
if (isNative)
|
||||
{
|
||||
success &= Compile(context, configuration.Value() ?? Constants.DefaultConfiguration, output.Value(), intermediateOutput.Value(), buildProjectReferences);
|
||||
|
||||
if (isNative)
|
||||
{
|
||||
success &= CompileNative(context, configuration.Value() ?? Constants.DefaultConfiguration, output.Value(), buildProjectReferences);
|
||||
}
|
||||
success &= CompileNative(context, configValue, outputValue, buildProjectReferences);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var context in ProjectContext.CreateContextForEachFramework(path))
|
||||
{
|
||||
success &= Compile(context, configuration.Value() ?? Constants.DefaultConfiguration, output.Value(), intermediateOutput.Value(), buildProjectReferences);
|
||||
|
||||
if (isNative)
|
||||
{
|
||||
success &= CompileNative(context, configuration.Value() ?? Constants.DefaultConfiguration, output.Value(), buildProjectReferences);
|
||||
}
|
||||
}
|
||||
}
|
||||
return success ? 0 : 1;
|
||||
});
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
"System.Linq": "4.0.1-beta-23504",
|
||||
"System.Diagnostics.Process": "4.1.0-beta-23504",
|
||||
"System.IO.FileSystem": "4.0.1-beta-23504",
|
||||
"System.AppContext": "4.0.1-beta-23504",
|
||||
|
||||
"Microsoft.DotNet.ProjectModel": "1.0.0-*",
|
||||
"Microsoft.DotNet.Compiler.Common": "1.0.0-*",
|
||||
|
@ -22,8 +23,7 @@
|
|||
"Microsoft.Extensions.CommandLineUtils.Sources": {
|
||||
"type": "build",
|
||||
"version": "1.0.0-*"
|
||||
},
|
||||
"Microsoft.Net.Compilers.netcore": "1.1.0-*"
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"dnxcore50": { }
|
||||
|
|
|
@ -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>717a4ed9-8897-492f-bd0c-230fcaea9237</ProjectGuid>
|
||||
<RootNamespace>Microsoft.DotNet.Tools.Interactive.Csi</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>
|
38
src/Microsoft.DotNet.Tools.Interactive.Csi/Program.cs
Normal file
38
src/Microsoft.DotNet.Tools.Interactive.Csi/Program.cs
Normal file
|
@ -0,0 +1,38 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.Dnx.Runtime.Common.CommandLine;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Interactive.Csi
|
||||
{
|
||||
public sealed class Program
|
||||
{
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
DebugHelper.HandleDebugSwitch(ref args);
|
||||
|
||||
var app = new CommandLineApplication();
|
||||
app.Name = "dotnet interactive csi";
|
||||
app.FullName = "CSharp Interactive";
|
||||
app.Description = "CSharp Interactive for the .NET platform";
|
||||
app.HelpOption("-h|--help");
|
||||
var script = app.Argument("<SCRIPT>", "The .csx file to run. Defaults to interactive mode.");
|
||||
|
||||
app.OnExecute(() => Run(script.Value));
|
||||
return app.Execute(args);
|
||||
}
|
||||
|
||||
private static int Run(string scriptOpt)
|
||||
{
|
||||
var corerun = Path.Combine(AppContext.BaseDirectory, Constants.HostExecutableName);
|
||||
var csiExe = Path.Combine(AppContext.BaseDirectory, "csi.exe");
|
||||
var csiArgs = string.IsNullOrEmpty(scriptOpt) ? "-i" : scriptOpt;
|
||||
var command = File.Exists(corerun) && File.Exists(csiExe) ?
|
||||
Command.Create(corerun, $@"""{csiExe}"" {csiArgs}") :
|
||||
Command.Create(csiExe, csiArgs);
|
||||
command = command.ForwardStdOut().ForwardStdErr();
|
||||
var result = command.Execute();
|
||||
return result.ExitCode;
|
||||
}
|
||||
}
|
||||
}
|
29
src/Microsoft.DotNet.Tools.Interactive.Csi/project.json
Normal file
29
src/Microsoft.DotNet.Tools.Interactive.Csi/project.json
Normal file
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"name": "dotnet-interactive-csi",
|
||||
"version": "1.0.0-*",
|
||||
"compilationOptions": {
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.Runtime": "1.0.1-beta-23504",
|
||||
|
||||
"System.Console": "4.0.0-beta-23504",
|
||||
"System.Collections": "4.0.11-beta-23504",
|
||||
"System.Linq": "4.0.1-beta-23504",
|
||||
"System.Diagnostics.Process": "4.1.0-beta-23504",
|
||||
"System.IO.FileSystem": "4.0.1-beta-23504",
|
||||
"System.AppContext": "4.0.1-beta-23504",
|
||||
|
||||
"Microsoft.DotNet.Cli.Utils": {
|
||||
"type": "build",
|
||||
"version": "1.0.0-*"
|
||||
},
|
||||
"Microsoft.Extensions.CommandLineUtils.Sources": {
|
||||
"type": "build",
|
||||
"version": "1.0.0-*"
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"dnxcore50": { }
|
||||
}
|
||||
}
|
|
@ -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>b317356c-99de-499e-8b4d-d6bec5da57d5</ProjectGuid>
|
||||
<RootNamespace>Microsoft.DotNet.Tools.Interactive</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>
|
43
src/Microsoft.DotNet.Tools.Interactive/Program.cs
Normal file
43
src/Microsoft.DotNet.Tools.Interactive/Program.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
using System;
|
||||
using Microsoft.Dnx.Runtime.Common.CommandLine;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Interactive
|
||||
{
|
||||
public sealed class Program
|
||||
{
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
DebugHelper.HandleDebugSwitch(ref args);
|
||||
|
||||
var app = new CommandLineApplication();
|
||||
app.Name = "dotnet interactive";
|
||||
app.FullName = ".NET interactive";
|
||||
app.Description = "Interactive for the .NET platform";
|
||||
app.HelpOption("-h|--help");
|
||||
var language = app.Argument("<LANGUAGE>", "The interactive programming language, defaults to csharp");
|
||||
|
||||
app.OnExecute(() => Run(language.Value));
|
||||
return app.Execute(args);
|
||||
}
|
||||
|
||||
private static int Run(string languageOpt)
|
||||
{
|
||||
string interactiveName;
|
||||
if ((languageOpt == null) || (languageOpt == "csharp"))
|
||||
{
|
||||
interactiveName = "csi";
|
||||
}
|
||||
else
|
||||
{
|
||||
Reporter.Error.WriteLine($"Unrecognized language: {languageOpt}".Red());
|
||||
return -1;
|
||||
}
|
||||
var command = Command.Create($"dotnet-interactive-{interactiveName}", string.Empty)
|
||||
.ForwardStdOut()
|
||||
.ForwardStdErr();
|
||||
var result = command.Execute();
|
||||
return result.ExitCode;
|
||||
}
|
||||
}
|
||||
}
|
29
src/Microsoft.DotNet.Tools.Interactive/project.json
Normal file
29
src/Microsoft.DotNet.Tools.Interactive/project.json
Normal file
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"name": "dotnet-interactive",
|
||||
"version": "1.0.0-*",
|
||||
"compilationOptions": {
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.Runtime": "1.0.1-beta-23504",
|
||||
|
||||
"System.Console": "4.0.0-beta-23504",
|
||||
"System.Collections": "4.0.11-beta-23504",
|
||||
"System.Linq": "4.0.1-beta-23504",
|
||||
"System.Diagnostics.Process": "4.1.0-beta-23504",
|
||||
"System.IO.FileSystem": "4.0.1-beta-23504",
|
||||
|
||||
"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-*"
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"dnxcore50": { }
|
||||
}
|
||||
}
|
|
@ -25,27 +25,36 @@ namespace Microsoft.DotNet.Tools.Run
|
|||
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("-t|--preserve-temporary", "Keep the output's temporary directory around", CommandOptionType.NoValue);
|
||||
var project = app.Option("-p|--project <PROJECT_PATH>", "The path to the project to run (defaults to the current directory)", CommandOptionType.SingleValue);
|
||||
var project = app.Argument("<PROJECT>", "The project to run, 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 = Directory.GetCurrentDirectory();
|
||||
if(project.HasValue())
|
||||
var path = project.Value;
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
path = project.Value();
|
||||
}
|
||||
|
||||
var contexts = ProjectContext.CreateContextForEachFramework(path);
|
||||
if (!framework.HasValue())
|
||||
{
|
||||
return Run(contexts.First(), configuration.Value() ?? Constants.DefaultConfiguration, app.RemainingArguments, preserveTemporaryOutput.HasValue());
|
||||
if (File.Exists(path) && (Path.GetExtension(path) == ".csx"))
|
||||
{
|
||||
return RunInteractive(path);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var context = contexts.FirstOrDefault(c => c.TargetFramework.Equals(NuGetFramework.Parse(framework.Value())));
|
||||
return Run(context, configuration.Value() ?? Constants.DefaultConfiguration, app.RemainingArguments, preserveTemporaryOutput.HasValue());
|
||||
path = Directory.GetCurrentDirectory();
|
||||
}
|
||||
|
||||
var contexts = ProjectContext.CreateContextForEachFramework(path);
|
||||
ProjectContext context;
|
||||
if (!framework.HasValue())
|
||||
{
|
||||
context = contexts.First();
|
||||
}
|
||||
else
|
||||
{
|
||||
var fx = NuGetFramework.Parse(framework.Value());
|
||||
context = contexts.FirstOrDefault(c => c.TargetFramework.Equals(fx));
|
||||
}
|
||||
return Run(context, configuration.Value() ?? Constants.DefaultConfiguration, app.RemainingArguments, preserveTemporaryOutput.HasValue());
|
||||
});
|
||||
|
||||
try
|
||||
|
@ -113,5 +122,14 @@ namespace Microsoft.DotNet.Tools.Run
|
|||
|
||||
return result.ExitCode;
|
||||
}
|
||||
|
||||
private static int RunInteractive(string scriptName)
|
||||
{
|
||||
var command = Command.Create($"dotnet-interactive-csi", scriptName)
|
||||
.ForwardStdOut()
|
||||
.ForwardStdErr();
|
||||
var result = command.Execute();
|
||||
return result.ExitCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue