8000 Merge pull request #589 from filipw/netcoreapp5.0 · dotnet-script/dotnet-script@48ec1e5 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 48ec1e5

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

File tree

14 files changed

+82
-33
lines changed

14 files changed

+82
-33
lines changed

azure-pipelines.yml

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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
179B 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

Lines 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

Lines 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

Lines 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; }

0 commit comments

Comments
 (0)
0