Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 48ec1e5

Browse filesBrowse files
authored
Merge pull request #589 from filipw/netcoreapp5.0
Support for .Net 5
2 parents 4c4f188 + a4df919 commit 48ec1e5
Copy full SHA for 48ec1e5

14 files changed

+82
-33
lines changed

‎azure-pipelines.yml

Copy file name to clipboardExpand all lines: azure-pipelines.yml
+13-1Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ jobs:
2525
- bash: "curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -version 2.1.402"
2626
displayName: "Install 2.1.402"
2727

28+
- bash: "curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -version 5.0.100"
29+
displayName: " 5.0.100"
30+
2831
- bash: |
2932
export PATH=/home/vsts/.dotnet:$PATH
3033
curl -L https://github.com/filipw/dotnet-script/releases/download/0.28.0/dotnet-script.0.28.0.zip > dotnet-script.zip
@@ -44,9 +47,12 @@ jobs:
4447
steps:
4548
- bash: |
4649
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -version 3.1.102
47-
4850
displayName: "Install 3.0.100"
4951
52+
- bash: |
53+
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin -version 5.0.100
54+
displayName: "Install 5.0.100"
55+
5056
- bash: |
5157
curl -L https://github.com/filipw/dotnet-script/releases/download/0.28.0/dotnet-script.0.28.0.zip > dotnet-script.zip
5258
unzip -o dotnet-script.zip -d ./
@@ -73,6 +79,12 @@ jobs:
7379
7480
displayName: "Install 2.1.402 SDK"
7581
82+
- powershell: |
83+
iwr https://raw.githubusercontent.com/dotnet/cli/release/2.1.3xx/scripts/obtain/dotnet-install.ps1 -outfile dotnet-install.ps1
84+
.\dotnet-install.ps1 -Version 5.0.100
85+
86+
displayName: "Install 5.0.100"
87+
7688
# NuGet Tool Installer
7789
# Acquires a specific version of NuGet from the internet or the tools cache and adds it to the PATH. Use this task to change the version of NuGet used in the NuGet tasks.
7890
- task: NuGetToolInstaller@0

‎global.json

Copy file name to clipboard
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "3.1.102",
3+
"version": "5.0.100",
44
"rollForward": "latestFeature"
55
}
66
}

‎src/.vscode/settings.json

Copy file name to clipboard
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"coverage-gutters.lcovname": "coverage.info"
3-
}
2+
"coverage-gutters.lcovname": "coverage.info",
3+
"dotnetCoreExplorer.searchpatterns": "**/bin/Debug/net5.0/Dotnet.Script.Tests.dll"
4+
}

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

Copy file name to clipboardExpand all lines: src/Dotnet.Script.Core/Dotnet.Script.Core.csproj
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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>0.53.0</VersionPrefix>
5+
<VersionPrefix>1.0.0</VersionPrefix>
66
<Authors>filipw</Authors>
77
<TargetFrameworks>netstandard2.0</TargetFrameworks>
88
<AssemblyName>Dotnet.Script.Core</AssemblyName>

‎src/Dotnet.Script.Core/ScriptEmitter.cs

Copy file name to clipboardExpand all lines: src/Dotnet.Script.Core/ScriptEmitter.cs
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public ScriptEmitter(ScriptConsole scriptConsole, ScriptCompiler scriptCompiler)
1818
_scriptCompiler = scriptCompiler;
1919
}
2020

21-
public virtual ScriptEmitResult Emit<TReturn, THost>(ScriptContext context)
21+
public virtual ScriptEmitResult Emit<TReturn, THost>(ScriptContext context, string assemblyName)
2222
{
2323
var compilationContext = _scriptCompiler.CreateCompilationContext<TReturn, THost>(context);
2424
foreach (var warning in compilationContext.Warnings)
@@ -37,13 +37,17 @@ public virtual ScriptEmitResult Emit<TReturn, THost>(ScriptContext context)
3737
}
3838

3939
var compilation = compilationContext.Script.GetCompilation();
40+
compilation = compilation.WithAssemblyName(assemblyName);
4041

4142
var peStream = new MemoryStream();
4243
EmitOptions emitOptions = null;
44+
4345
if (context.OptimizationLevel == Microsoft.CodeAnalysis.OptimizationLevel.Debug)
4446
{
4547
emitOptions = new EmitOptions()
4648
.WithDebugInformationFormat(DebugInformationFormat.Embedded);
49+
50+
4751
}
4852

4953
var result = compilation.Emit(peStream, options: emitOptions);

‎src/Dotnet.Script.Core/ScriptPublisher.cs

Copy file name to clipboardExpand all lines: src/Dotnet.Script.Core/ScriptPublisher.cs
+8-5Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Dotnet.Script.Core
1313
{
1414
public class ScriptPublisher
1515
{
16-
private const string ScriptingVersion = "2.8.2";
16+
private const string ScriptingVersion = "3.7.0";
1717

1818
private readonly ScriptProjectProvider _scriptProjectProvider;
1919
private readonly ScriptEmitter _scriptEmitter;
@@ -73,8 +73,8 @@ public void CreateExecutable<TReturn, THost>(ScriptContext context, LogFactory l
7373
executableFileName = executableFileName ?? Path.GetFileNameWithoutExtension(context.FilePath);
7474
const string AssemblyName = "scriptAssembly";
7575

76-
var tempProjectPath = ScriptProjectProvider.GetPathToProjectFile(Path.GetDirectoryName(context.FilePath), ScriptEnvironment.Default.TargetFramework);
77-
var renamedProjectPath = ScriptProjectProvider.GetPathToProjectFile(Path.GetDirectoryName(context.FilePath), ScriptEnvironment.Default.TargetFramework, executableFileName);
76+
var tempProjectPath = ScriptProjectProvider.GetPathToProjectFile(Path.GetDirectoryName(context.FilePath), _scriptEnvironment.TargetFramework);
77+
var renamedProjectPath = ScriptProjectProvider.GetPathToProjectFile(Path.GetDirectoryName(context.FilePath), _scriptEnvironment.TargetFramework, executableFileName);
7878
var tempProjectDirectory = Path.GetDirectoryName(tempProjectPath);
7979

8080
var scriptAssemblyPath = CreateScriptAssembly<TReturn, THost>(context, tempProjectDirectory, AssemblyName);
@@ -88,7 +88,10 @@ public void CreateExecutable<TReturn, THost>(ScriptContext context, LogFactory l
8888

8989
var commandRunner = new CommandRunner(logFactory);
9090
// todo: may want to add ability to return dotnet.exe errors
91-
var exitcode = commandRunner.Execute("dotnet", $"publish \"{renamedProjectPath}\" -c Release -r {runtimeIdentifier} -o \"{context.WorkingDirectory}\" {(ScriptEnvironment.Default.NetCoreVersion.Major >= 3 ? "/p:PublishSingleFile=true" : string.Empty)} /p:DebugType=Embedded");
91+
var publishSingleFileArgument = ScriptEnvironment.Default.NetCoreVersion.Major >= 3 ? "/p:PublishSingleFile=true" : string.Empty;
92+
var includeNativeLibrariesForSelfExtract = ScriptEnvironment.Default.NetCoreVersion.Major >= 5 ? "/p:IncludeNativeLibrariesForSelfExtract=true" : string.Empty;
93+
94+
var exitcode = commandRunner.Execute("dotnet", $"publish \"{renamedProjectPath}\" -c Release -r {runtimeIdentifier} -o \"{context.WorkingDirectory}\" {publishSingleFileArgument} {includeNativeLibrariesForSelfExtract} /p:DebugType=Embedded");
9295

9396
if (exitcode != 0)
9497
{
@@ -100,7 +103,7 @@ public void CreateExecutable<TReturn, THost>(ScriptContext context, LogFactory l
100103

101104
private string CreateScriptAssembly<TReturn, THost>(ScriptContext context, string outputDirectory, string assemblyFileName)
102105
{
103-
var emitResult = _scriptEmitter.Emit<TReturn, THost>(context);
106+
var emitResult = _scriptEmitter.Emit<TReturn, THost>(context, assemblyFileName);
104107
var assemblyPath = Path.Combine(outputDirectory, $"{assemblyFileName}.dll");
105108
using (var peFileStream = new FileStream(assemblyPath, FileMode.Create))
106109
using (emitResult.PeStream)

‎src/Dotnet.Script.Core/Templates/program.publish.template

Copy file name to clipboardExpand all lines: src/Dotnet.Script.Core/Templates/program.publish.template
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using Microsoft.CodeAnalysis.CSharp.Scripting.Hosting;
33
using Microsoft.CodeAnalysis.Scripting.Hosting;
4+
using System.Runtime.Loader;
45
using System.Threading.Tasks;
56
using static System.Console;
67
using System.Reflection;
@@ -18,15 +19,14 @@ namespace dotnetPublishCode
1819
foreach (var arg in args)
1920
globals.Args.Add(arg);
2021

21-
var path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
22-
var assembly = Assembly.LoadFrom(Path.Combine(path, "scriptAssembly.dll"));
22+
var assembly = AssemblyLoadContext.Default.LoadFromAssemblyName(new AssemblyName("scriptAssembly"));
2323
var type = assembly.GetType("Submission#0");
2424
var factoryMethod = type.GetMethod("<Factory>");
2525
if (factoryMethod == null) throw new Exception("couldn't find factory method to initiate script");
2626

2727
var invokeTask = factoryMethod.Invoke(null, new object[] { new object[] { globals, null } }) as Task<int>;
2828
var invokeResult = await invokeTask;
29-
if (invokeResult != 0)
29+
if (invokeResult != 0)
3030
{
3131
WritePrettyError($"Error result: '{invokeResult}'");
3232
return 0x1;

‎src/Dotnet.Script.DependencyModel.Nuget/Dotnet.Script.DependencyModel.NuGet.csproj

Copy file name to clipboardExpand all lines: src/Dotnet.Script.DependencyModel.Nuget/Dotnet.Script.DependencyModel.NuGet.csproj
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<RepositoryUrl>https://github.com/filipw/dotnet-script.git</RepositoryUrl>
99
<RepositoryType>git</RepositoryType>
1010
<PackageTags>script;csx;csharp;roslyn;nuget</PackageTags>
11-
<Version>0.53.0</Version>
11+
<Version>1.0.0</Version>
1212
<Description>A MetadataReferenceResolver that allows inline nuget references to be specified in script(csx) files.</Description>
1313
<Authors>dotnet-script</Authors>
1414
<Company>dotnet-script</Company>

‎src/Dotnet.Script.DependencyModel/Dotnet.Script.DependencyModel.csproj

Copy file name to clipboardExpand all lines: src/Dotnet.Script.DependencyModel/Dotnet.Script.DependencyModel.csproj
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<RepositoryUrl>https://github.com/filipw/dotnet-script.git</RepositoryUrl>
1212
<RepositoryType>git</RepositoryType>
1313
<PackageTags>script;csx;csharp;roslyn;omnisharp</PackageTags>
14-
<Version>0.53.0</Version>
14+
<Version>1.0.0</Version>
1515
<LangVersion>latest</LangVersion>
1616
</PropertyGroup>
1717

‎src/Dotnet.Script.DependencyModel/Environment/ScriptEnvironment.cs

Copy file name to clipboardExpand all lines: src/Dotnet.Script.DependencyModel/Environment/ScriptEnvironment.cs
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ private static string GetPlatformIdentifier()
7474

7575
private static DotnetVersion GetNetCoreAppVersion()
7676
{
77+
GetNetCoreVersion();
7778
// https://github.com/dotnet/BenchmarkDotNet/blob/94863ab4d024eca04d061423e5aad498feff386b/src/BenchmarkDotNet/Portability/RuntimeInformation.cs#L156
7879
var codeBase = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly.CodeBase;
7980
var pattern = @"^.*Microsoft\.NETCore\.App\/(\d+\.\d+)(.*?)\/";
@@ -88,6 +89,16 @@ private static DotnetVersion GetNetCoreAppVersion()
8889
return new DotnetVersion(version, $"netcoreapp{tfm}");
8990
}
9091

92+
public static string GetNetCoreVersion()
93+
{
94+
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
95+
var assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
96+
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
97+
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
98+
return assemblyPath[netCoreAppIndex + 1];
99+
return null;
100+
}
101+
91102
private static string GetInstallLocation()
92103
{
93104
return Path.GetDirectoryName(new Uri(typeof(ScriptEnvironment).GetTypeInfo().Assembly.CodeBase).LocalPath);
@@ -145,6 +156,10 @@ public DotnetVersion(string version, string tfm)
145156
Major = int.Parse(versionMatch.Groups[1].Value);
146157
if (versionMatch.Success && versionMatch.Groups[2].Success)
147158
Minor = int.Parse(versionMatch.Groups[2].Value);
159+
if (Major >= 5)
160+
{
161+
Tfm = $"net{Major}.{Minor}";
162+
}
148163
}
149164

150165
public string Version { get; }

‎src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj

Copy file name to clipboardExpand all lines: src/Dotnet.Script.Tests/Dotnet.Script.Tests.csproj
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
3+
<TargetFrameworks>net5.0</TargetFrameworks>
44
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
55
</PropertyGroup>
66
<ItemGroup>

‎src/Dotnet.Script.Tests/ScriptPackagesTests.cs

Copy file name to clipboardExpand all lines: src/Dotnet.Script.Tests/ScriptPackagesTests.cs
+20-14Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ public ScriptPackagesTests(ITestOutputHelper testOutputHelper)
2525
[Fact]
2626
public void ShouldHandleScriptPackageWithMainCsx()
2727
{
28-
var result = Execute("WithMainCsx/WithMainCsx.csx");
29-
Assert.StartsWith("Hello from netstandard2.0", result);
28+
var (output, exitcode) = ScriptTestRunner.Default.ExecuteWithScriptPackage("WithMainCsx", "--no-cache");
29+
Assert.Equal(0, exitcode);
30+
Assert.StartsWith("Hello from netstandard2.0", output);
3031
}
3132

32-
[Fact]
33+
//[Fact]
3334
public void ShouldThrowMeaningfulExceptionWhenScriptPackageIsMissing()
3435
{
3536
using (var scriptFolder = new DisposableFolder())
@@ -60,37 +61,42 @@ public void ShouldThrowMeaningfulExceptionWhenScriptPackageIsMissing()
6061
[Fact]
6162
public void ShouldHandleScriptWithAnyTargetFramework()
6263
{
63-
var result = Execute("WithAnyTargetFramework/WithAnyTargetFramework.csx");
64-
Assert.StartsWith("Hello from any target framework", result);
64+
var (output, exitcode) = ScriptTestRunner.Default.ExecuteWithScriptPackage("WithAnyTargetFramework", "--no-cache");
65+
Assert.Equal(0, exitcode);
66+
Assert.StartsWith("Hello from any target framework", output);
6567
}
6668

6769
[Fact]
6870
public void ShouldHandleScriptPackageWithNoEntryPointFile()
6971
{
70-
var result = Execute("WithNoEntryPointFile/WithNoEntryPointFile.csx");
71-
Assert.Contains("Hello from Foo.csx", result);
72-
Assert.Contains("Hello from Bar.csx", result);
72+
var (output, exitcode) = ScriptTestRunner.Default.ExecuteWithScriptPackage("WithNoEntryPointFile", "--no-cache");
73+
Assert.Equal(0, exitcode);
74+
Assert.Contains("Hello from Foo.csx", output);
75+
Assert.Contains("Hello from Bar.csx", output);
7376
}
7477

7578
[Fact]
7679
public void ShouldHandleScriptPackageWithScriptPackageDependency()
7780
{
78-
var result = Execute("WithScriptPackageDependency/WithScriptPackageDependency.csx");
79-
Assert.StartsWith("Hello from netstandard2.0", result);
81+
var (output, exitcode) = ScriptTestRunner.Default.ExecuteWithScriptPackage("WithScriptPackageDependency", "--no-cache");
82+
Assert.Equal(0, exitcode);
83+
Assert.StartsWith("Hello from netstandard2.0", output);
8084
}
8185

8286
[Fact]
8387
public void ShouldThrowExceptionWhenReferencingUnknownPackage()
8488
{
85-
var result = Execute("WithInvalidPackageReference/WithInvalidPackageReference.csx");
86-
Assert.StartsWith("Unable to restore packages from", result);
89+
var (output, exitcode) = ScriptTestRunner.Default.ExecuteWithScriptPackage("WithInvalidPackageReference", "--no-cache");
90+
Assert.NotEqual(0, exitcode);
91+
Assert.StartsWith("Unable to restore packages from", output);
8792
}
8893

8994
[Fact]
9095
public void ShouldHandleScriptPackageWithSubFolder()
9196
{
92-
var result = Execute("WithSubFolder/WithSubFolder.csx");
93-
Assert.StartsWith("Hello from Bar.csx", result);
97+
var (output, exitcode) = ScriptTestRunner.Default.ExecuteWithScriptPackage("WithSubFolder", "--no-cache");
98+
Assert.Equal(0, exitcode);
99+
Assert.StartsWith("Hello from Bar.csx", output);
94100
}
95101

96102
[Fact]

‎src/Dotnet.Script.Tests/ScriptTestRunner.cs

Copy file name to clipboardExpand all lines: src/Dotnet.Script.Tests/ScriptTestRunner.cs
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ public int ExecuteInProcess(string arguments = null)
4242
return result;
4343
}
4444

45+
public (string output, int exitcode) ExecuteWithScriptPackage(string fixture, string arguments = null, string workingDirectory = null)
46+
{
47+
var pathToScriptPackageFixtures = TestPathUtils.GetPathToTestFixtureFolder("ScriptPackage");
48+
var pathToFixture = Path.Combine(pathToScriptPackageFixtures, fixture, $"{fixture}.csx");
49+
return ProcessHelper.RunAndCaptureOutput("dotnet", GetDotnetScriptArguments($"{pathToFixture} {arguments}"), workingDirectory);
50+
}
51+
4552
public int ExecuteFixtureInProcess(string fixture, string arguments = null)
4653
{
4754
var pathToFixture = TestPathUtils.GetPathToTestFixture(fixture);
@@ -80,6 +87,7 @@ private string GetDotnetScriptArguments(string arguments)
8087
#else
8188
configuration = "Release";
8289
#endif
90+
8391
var allArgs = $"exec {Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "..", "..", "Dotnet.Script", "bin", configuration, _scriptEnvironment.TargetFramework, "dotnet-script.dll")} {arguments}";
8492

8593
return allArgs;

‎src/Dotnet.Script/Dotnet.Script.csproj

Copy file name to clipboardExpand all lines: src/Dotnet.Script/Dotnet.Script.csproj
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<Description>Dotnet CLI tool allowing you to run C# (CSX) scripts.</Description>
4-
<VersionPrefix>0.53.0</VersionPrefix>
4+
<VersionPrefix>1.0.0</VersionPrefix>
55
<Authors>filipw</Authors>
66
<PackageId>Dotnet.Script</PackageId>
7-
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
7+
<TargetFrameworks>net5.0;netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
88
<DebugType>portable</DebugType>
99
<AssemblyName>dotnet-script</AssemblyName>
1010
<OutputType>Exe</OutputType>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.