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 10000 .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, 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+
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
}

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,14 @@ public async Task<TReturn> Run<TReturn, THost>(ExecuteScriptCommandOptions optio
3232
}
3333

3434
var pathToLibrary = GetLibrary(options);
35-
return await ExecuteLibrary<TReturn>(pathToLibrary, options.Arguments, options.NoCache);
35+
36+
var libraryOptions = new ExecuteLibraryCommandOptions(pathToLibrary, options.Arguments, options.NoCache)
37+
{
38+
#if NETCOREAPP
39+
AssemblyLoadContext = options.AssemblyLoadContext
40+
#endif
41+
};
42+
return await new ExecuteLibraryCommand(_scriptConsole, _logFactory).Execute<TReturn>(libraryOptions);
3643
}
3744

3845
private async Task<TReturn> DownloadAndRunCode<TReturn>(ExecuteScriptCommandOptions executeOptions)
@@ -57,7 +64,12 @@ private string GetLibrary(ExecuteScriptCommandOptions executeOptions)
5764
return pathToLibrary;
5865
}
5966

60-
var options = new PublishCommandOptions(executeOptions.File, executionCacheFolder, "script", PublishType.Library, executeOptions.OptimizationLevel, executeOptions.PackageSources, null, executeOptions.NoCache);
67+
var options = new PublishCommandOptions(executeOptions.File, executionCacheFolder, "script", PublishType.Library, executeOptions.OptimizationLevel, executeOptions.PackageSources, null, executeOptions.NoCache)
68+
{
69+
#if NETCOREAPP
70+
AssemblyLoadContext = executeOptions.AssemblyLoadContext
71+
#endif
72+
};
6173
new PublishCommand(_scriptConsole, _logFactory).Execute(options);
6274
if (hash != null)
6375
{
@@ -124,11 +136,5 @@ public bool TryGetHash(string cacheFolder, out string hash)
124136
hash = File.ReadAllText(pathToHashFile);
125137
return true;
126138
}
127-
128-
private async Task<TReturn> ExecuteLibrary<TReturn>(string pathToLibrary, string[] arguments, bool noCache)
129-
{
130-
var options = new ExecuteLibraryCommandOptions(pathToLibrary, arguments, noCache);
131-
return await new ExecuteLibraryCommand(_scriptConsole, _logFactory).Execute<TReturn>(options);
132-
}
133139
}
134140
}

src/Dotnet.Script.Core/Commands/ExecuteScriptCommandOptions.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.R 741A untime.Loader;
4+
#endif
25

36
namespace Dotnet.Script.Core.Commands
47
{
@@ -20,5 +23,14 @@ public ExecuteScriptCommandOptions(ScriptFile file, string[] arguments, Optimiza
2023
public string[] PackageSources { get; }
2124
public bool IsInteractive { get; }
2225
public bool NoCache { 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/PublishCommand.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ public void Execute(PublishCommandOptions options)
2828
(options.PublishType == PublishType.Library ? Path.Combine(Path.GetDirectoryName(absoluteFilePath), "publish") : Path.Combine(Path.GetDirectoryName(absoluteFilePath), "publish", options.RuntimeIdentifier));
2929

3030
var absolutePublishDirectory = publishDirectory.GetRootedPath();
31-
var compiler = GetScriptCompiler(!options.NoCache, _logFactory);
31+
var compiler = new ScriptCompiler(_logFactory, !options.NoCache)
32+
{
33+
#if NETCOREAPP
34+
AssemblyLoadContext = options.AssemblyLoadContext
35+
#endif
36+
};
3237
var scriptEmitter = new ScriptEmitter(_scriptConsole, compiler);
3338
var publisher = new ScriptPublisher(_logFactory, scriptEmitter);
3439
var code = absoluteFilePath.ToSourceText();
@@ -43,12 +48,5 @@ public void Execute(PublishCommandOptions options)
4348
publisher.CreateExecutable<int, CommandLineScriptGlobals>(context, _logFactory, options.RuntimeIdentifier, options.LibraryName);
4449
}
4550
}
46-
47-
private static ScriptCompiler GetScriptCompiler(bool useRestoreCache, LogFactory logFactory)
48-
{
49-
50-
var compiler = new ScriptCompiler(logFactory, useRestoreCache);
51-
return compiler;
52-
}
5351
}
5452
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using Dotnet.Script.DependencyModel.Environment;
22
using Microsoft.CodeAnalysis;
3+
#if NETCOREAPP
4+
using System.Runtime.Loader;
5+
#endif
36

47
namespace Dotnet.Script.Core.Commands
58
{
@@ -25,6 +28,15 @@ public PublishCommandOptions(ScriptFile file, string outputDirectory, string lib
2528
public string[] PackageSources { get; }
2629
public string RuntimeIdentifier { get; }
2730
public bool NoCache { get; }
31+
32+
#if NETCOREAPP
33+
#nullable enable
34+
/// <summary>
35+
/// Gets or sets a custom assembly load context to use for script isolation.
36+
/// </summary>
37+
public AssemblyLoadContext? AssemblyLoadContext { get; init; }
38+
#nullable restore
39+
#endif
2840
}
2941

3042
public enum PublishType

src/Dotnet.Script.Core/Dotnet.Script.Core.csproj

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
44
<Description>A cross platform library allowing you to run C# (CSX) scripts with support for debugging and inline NuGet packages. Based on Roslyn.</Description>
5-
<VersionPrefix>1.1.0</VersionPrefix>
5+
<VersionPrefix>1.2.1</VersionPrefix>
66
<Authors>filipw</Authors>
7-
<TargetFrameworks>netstandard2.0</TargetFrameworks>
7+
<TargetFrameworks>netstandard2.0;netcoreapp3.1</TargetFrameworks>
88
<AssemblyName>Dotnet.Script.Core</AssemblyName>
99
<PackageId>Dotnet.Script.Core</PackageId>
1010
<PackageTags>script;csx;csharp;roslyn</PackageTags>
@@ -16,24 +16,26 @@
1616
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
1717
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
1818
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
19+
<LangVersion>9.0</LangVersion>
1920
<SignAssembly>true</SignAssembly>
2021
<AssemblyOriginatorKeyFile>../dotnet-script.snk</AssemblyOriginatorKeyFile>
2122
</PropertyGroup>
2223
<ItemGroup>
2324
<EmbeddedResource Include="**/*.template" />
2425
</ItemGroup>
2526
<ItemGroup>
27+
<PackageReference Include="Gapotchenko.FX" Version="2021.1.5" />
28+
<PackageReference Include="Gapotchenko.FX.Reflection.Loader" Version="2021.2.11" />
2629
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="3.9.0" />
2730
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
2831
<PackageReference Include="ReadLine" Version="2.0.1" />
2932
<PackageReference Include="System.Collections.Immutable" Version="5.0.0" />
3033
<PackageReference Include="System.Reflection.Metadata" Version="5.0.0" />
3134
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
32-
<!-- The following references are just quick fixes for issue #166 and issue #268
33-
We need to figure out why we can't load these via the dependency context.
34-
-->
35+
<!-- The following references are just quick fixes for issue #166 and issue #268 -->
3536
<PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
3637
<PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
38+
<!-- End of quick fixes -->
3739
<PackageReference Include="StrongNamer" Version="0.2.5" PrivateAssets="all" />
3840
</ItemGroup>
3941
<ItemGroup>

0 commit comments

Comments
 (0)
0