8000 Merge branch 'master' into net6 · dotnet-script/dotnet-script@af5c636 · GitHub
[go: up one dir, main page]

Skip to content

Commit af5c636

Browse files
committed
Merge branch 'master' into net6
2 parents e5f35d2 + ef3e18d commit af5c636

35 files changed

+577
-98
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,4 @@ project.json
265265
/build/dotnet-script
266266
/dotnet-script
267267
/.vscode
268+
/src/Dotnet.Script/Properties/launchSettings.json

README.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Run C# scripts from the .NET CLI, define NuGet packages inline and edit/debug th
1010

1111
| Name | Version | Framework(s) |
1212
| ------------------------------------- | ------------------------------------------------------------ | -------------------------------- |
13-
| `dotnet-script` | [![Nuget](http://img.shields.io/nuget/v/dotnet-script.svg?maxAge=10800)](https://www.nuget.org/packages/dotnet-script/) | `netcoreapp2.1`, `netcoreapp3.1` |
14-
| `Dotnet.Script` | [![Nuget](http://img.shields.io/nuget/v/dotnet.script.svg?maxAge=10800)](https://www.nuget.org/packages/dotnet.script/) | `netcoreapp2.1`, `netcoreapp3.1` |
13+
| `dotnet-script` (global tool) | [![Nuget](http://img.shields.io/nuget/v/dotnet-script.svg?maxAge=10800)](https://www.nuget.org/packages/dotnet-script/) | `net5.0`, `netcoreapp3.1` |
14+
| `Dotnet.Script` (CLI as Nuget) | [![Nuget](http://img.shields.io/nuget/v/dotnet.script.svg?maxAge=10800)](https://www.nuget.org/packages/dotnet.script/) | `net5.0`, `netcoreapp3.1` |
1515
| `Dotnet.Script.Core` | [![Nuget](http://img.shields.io/nuget/v/Dotnet.Script.Core.svg?maxAge=10800)](https://www.nuget.org/packages/Dotnet.Script.Core/) | `netstandard2.0` |
1616
| `Dotnet.Script.DependencyModel` | [![Nuget](http://img.shields.io/nuget/v/Dotnet.Script.DependencyModel.svg?maxAge=10800)](https://www.nuget.org/packages/Dotnet.Script.DependencyModel/) | `netstandard2.0` |
1717
| `Dotnet.Script.DependencyModel.Nuget` | [![Nuget](http://img.shields.io/nuget/v/Dotnet.Script.DependencyModel.Nuget.svg?maxAge=10800)](https://www.nuget.org/packages/Dotnet.Script.DependencyModel.Nuget/) | `netstandard2.0` |
@@ -20,11 +20,11 @@ Run C# scripts from the .NET CLI, define NuGet packages inline and edit/debug th
2020

2121
### Prerequisites
2222

23-
The only thing we need to install is [.NET Core 2.1+ SDK](https://www.microsoft.com/net/download/core). In order to use C# 8.0 features, [.NET Core 3.1+ SDK](https://www.microsoft.com/net/download/core) must be installed.
23+
The only thing we need to install is [.NET Core 3.1 or .NET 5.0 SDK](https://www.microsoft.com/net/download/core).
2424

2525
### .NET Core Global Tool
2626

27-
.NET Core 2.1 introduces the concept of global tools meaning that you can install `dotnet-script` using nothing but the .NET CLI.
27+
.NET Core 2.1 introduced the concept of global tools meaning that you can install `dotnet-script` using nothing but the .NET CLI.
2828

2929
```shell
3030
dotnet tool install -g dotnet-script
@@ -34,9 +34,6 @@ Tool 'dotnet-script' (version '0.22.0') was successfully installed.
3434
```
3535

3636
The advantage of this approach is that you can use the same command for installation across all platforms.
37-
38-
> ⚠️ In order to use the global tool you need [.NET Core SDK 2.1.300](https://www.microsoft.com/net/download/dotnet-core/sdk-2.1.300) or higher. The earlier previews and release candidates of .NET Core 2.1 are not supported.
39-
4037
.NET Core SDK also supports viewing a list of installed tools and their uninstallation.
4138

4239
```shell
@@ -316,7 +313,6 @@ To consume a script package all we need to do specify the NuGet package in the `
316313
The following example loads the [simple-targets](https://www.nuget.org/packages/simple-targets-csx) package that contains script files to be included in our script.
317314

318315
```C#
319-
#! "netcoreapp2.1"
320316
#load "nuget:simple-targets-csx, 6.0.0"
321317

322318
using static SimpleTargets;
@@ -466,7 +462,6 @@ The following example shows how we can pipe data in and out of a script.
466462
The `UpperCase.csx` script simply converts the standard input to upper case and writes it back out to standard output.
467463

468464
```csharp
469-
#! "netcoreapp2.1"
470465
using (var streamReader = new StreamReader(Console.OpenStandardInput()))
471466
{
472467
Write(streamReader.ReadToEnd().ToUpper());

build/Build.csx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ await StepRunner.Execute(Args);
3535

3636
private void CreateGitHubReleaseAsset()
3737
{
38-
DotNet.Publish(dotnetScriptProjectFolder, publishArtifactsFolder, "netcoreapp2.1");
38+
DotNet.Publish(dotnetScriptProjectFolder, publishArtifactsFolder, "netcoreapp3.1");
3939
Zip(publishArchiveFolder, pathToGitHubReleaseAsset);
4040
}
4141

build/omnisharp.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"script": {
33
"enableScriptNuGetReferences": true,
4-
"defaultTargetFramework": "netcoreapp2.1"
4+
"defaultTargetFramework": "netcoreapp3.1"
55
}
66
}

src/Dotnet.Script.Core/Commands/ExecuteCodeCommand.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,19 @@ public async Task<TReturn> Execute<TReturn>(ExecuteCodeCommandOptions options)
2222
{
2323
var sourceText = SourceText.From(options.Code);
2424
var context = new ScriptContext(sourceText, options.WorkingDirectory ?? Directory.GetCurrentDirectory(), options.Arguments, null, options.OptimizationLevel, ScriptMode.Eval, options.PackageSources);
25-
var compiler = GetScriptCompiler(!options.NoCache, _logFactory);
26-
var runner = new ScriptRunner(compiler, _logFactory, _scriptConsole);
25+
var compiler = new ScriptCompiler(_logFactory, !options.NoCache)
26+
{
27+
#if NETCOREAPP
28+
AssemblyLoadContext = options.AssemblyLoadContext
29+
#endif
30+
};
31+
var runner = new ScriptRunner(compiler, _logFactory, _scriptConsole)
32+
{
33+
#if NETCOREAPP
34+
AssemblyLoadContext = options.AssemblyLoadContext
35+
#endif
36+
};
2737
return await runner.Execute<TReturn>(context);
2838
}
29-
30-
private static ScriptCompiler GetScriptCompiler(bool useRestoreCache, C35F LogFactory logFactory)
31-
{
32-
var compiler = new ScriptCompiler(logFactory, useRestoreCache);
33-
return compiler;
34-
}
3539
}
3640
}

src/Dotnet.Script.Core/Commands/ExecuteCodeCommandOptions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
using Microsoft.CodeAnalysis;
2+
#if NETCOREAPP
3+
using System.Runtime.Loader;
4+
#endif
25

36
namespace Dotnet.Script.Core.Commands
47
{
@@ -20,5 +23,14 @@ public ExecuteCodeCommandOptions(string code, string workingDirectory, string[]
2023
public OptimizationLevel OptimizationLevel { get; }
2124
public bool NoCache { get; }
2225
public string[] PackageSources { get; }
26+
27+
#if NETCOREAPP
28+
#nullable enable
29+
/// <summary>
30+
/// Gets or sets a custom assembly load context to use for script execution.
31+
/// </summary>
32+
public AssemblyLoadContext? AssemblyLoadContext { get; init; }
33+
#nullable restore
34+
#endif
2335
}
2436
}

src/Dotnet.Script.Core/Commands/ExecuteInteractiveCommand.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ public ExecuteInteractiveCommand(ScriptConsole scriptConsole, LogFactory logFact
1818

1919
public async Task<int> Execute(ExecuteInteractiveCommandOptions options)
2020
{
21-
var compiler = new ScriptCompiler(_logFactory, useRestoreCache: false);
21+
var compiler = new ScriptCompiler(_logFactory, useRestoreCache: false)
22+
{
23+
#if NETCOREAPP
24+ C35F
AssemblyLoadContext = options.AssemblyLoadContext
25+
#endif
26+
};
2227
var runner = new InteractiveRunner(compiler, _logFactory, _scriptConsole, options.PackageSources);
2328

2429
if (options.ScriptFile == null)
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
using Microsoft.CodeAnalysis;
1+
#if NETCOREAPP
2+
using System.Runtime.Loader;
3+
#endif
24

35
namespace Dotnet.Script.Core.Commands
46
{
57
public class ExecuteInteractiveCommandOptions
68
{
7-
public ExecuteInteractiveCommandOptions(ScriptFile scriptFile, string[] arguments ,string[] packageSources)
9+
public ExecuteInteractiveCommandOptions(ScriptFile scriptFile, string[] arguments, string[] packageSources)
810
{
911
ScriptFile = scriptFile;
1012
Arguments = arguments;
@@ -14,5 +16,14 @@ public ExecuteInteractiveCommandOptions(ScriptFile scriptFile, string[] argument
1416
public ScriptFile ScriptFile { get; }
1517
public string[] Arguments { get; }
1618
public string[] PackageSources { get; }
19+
20+
#if NETCOREAPP
21+
#nullable enable
22+
/// <summary>
23+
/// Gets or sets a custom assembly load context to use for script execution.
24+
/// </summary>
25+
public AssemblyLoadContext? AssemblyLoadContext { get; init; }
26+
#nullable restore
27+
#endif
1728
}
1829
}

src/Dotnet.Script.Core/Commands/ExecuteLibraryCommand.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,20 @@ public async Task<TReturn> Execute<TReturn>(ExecuteLibraryCommandOptions options
2525
}
2626

2727
var absoluteFilePath = options.LibraryPath.GetRootedPath();
28-
var compiler = GetScriptCompiler(!options.NoCache, _logFactory);
29-
var runner = new ScriptRunner(compiler, _logFactory, _scriptConsole);
28+
var compiler = new ScriptCompiler(_logFactory, !options.NoCache)
29+
{
30+
#if NETCOREAPP
31+
AssemblyLoadContext = options.AssemblyLoadContext
32+
#endif
33+
};
34+
var runner = new ScriptRunner(compiler, _logFactory, _scriptConsole)
35+
{
36+
#if NETCOREAPP
37+
AssemblyLoadContext = options.AssemblyLoadContext
38+
#endif
39+
};
3040
var result = await runner.Execute<TReturn>(absoluteFilePath, options.Arguments);
3141
return result;
3242
}
33-
34-
private static ScriptCompiler GetScriptCompiler(bool useRestoreCache, LogFactory logFactory)
35-
{
36-
var compiler = new ScriptCompiler(logFactory, useRestoreCache);
37-
return compiler;
38-
}
3943
}
4044
}

src/Dotnet.Script.Core/Commands/ExecuteLibraryCommandOptions.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#if NETCOREAPP
2+
using System.Runtime.Loader;
3+
#endif
4+
15
namespace Dotnet.Script.Core.Commands
26
{
37
public class ExecuteLibraryCommandOptions
@@ -12,5 +16,14 @@ public ExecuteLibraryCommandOptions(string libraryPath, string[] arguments, bool
1216
public string LibraryPath { get; }
1317
public string[] Arguments { get; }
1418
public bool NoCache { get; }
19+
20+
#if NETCOREAPP
21+
#nullable enable
22+
/// <summary>
23+
/// Gets or sets a custom assembly load context to use for script execution.
24+
/// </summary>
25+
public AssemblyLoadContext? AssemblyLoadContext { get; init; }
26+
#nullable restore
27+
#endif
1528
}
1629
}

0 commit comments

Comments
 (0)
0