Skip to content

Commit 4a0f2bf

Browse files
authored
Merge pull request #781 from dotnet-script/roslyn5
Roslyn5
2 parents 1d74a87 + bf04dcf commit 4a0f2bf

File tree

10 files changed

+110
-39
lines changed

10 files changed

+110
-39
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<ItemGroup>
2727
<PackageReference Include="Gapotchenko.FX" Version="2024.1.3" />
2828
<PackageReference Include="Gapotchenko.FX.Reflection.Loader" Version="2024.1.3" />
29-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.11.0" />
29+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="5.0.0-2.final" />
3030
<PackageReference Include="ReadLine" Version="2.0.1" />
3131
<PackageReference Include="StrongNamer" Version="0.2.5" PrivateAssets="all" />
3232
</ItemGroup>

src/Dotnet.Script.Core/ScriptConsole.cs

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
using System;
22
using System.IO;
3+
using System.Runtime.CompilerServices;
34
using Microsoft.CodeAnalysis;
45
using RL = System.ReadLine;
56

67
namespace Dotnet.Script.Core
78
{
89
public class ScriptConsole
910
{
10-
public static readonly ScriptConsole Default = new ScriptConsole(Console.Out, Console.In, Console.Error);
11+
// Lazy to avoid touching anything during type initialization
12+
private static readonly Lazy<ScriptConsole> s_default =
13+
new Lazy<ScriptConsole>(() => new ScriptConsole(Console.Out, Console.In, Console.Error));
14+
15+
public static ScriptConsole Default => s_default.Value;
1116

1217
public virtual TextWriter Error { get; }
1318
public virtual TextWriter Out { get; }
@@ -69,19 +74,59 @@ public virtual void WriteDiagnostics(Diagnostic[] warningDiagnostics, Diagnostic
6974

7075
public virtual string ReadLine()
7176
{
72-
return In == null ? RL.Read() : In.ReadLine();
77+
if (In != null)
78+
return In.ReadLine();
79+
80+
return ReadLineInteractive();
7381
}
7482

7583
public ScriptConsole(TextWriter output, TextReader input, TextWriter error)
7684
{
7785
if (input == null)
7886
{
79-
RL.HistoryEnabled = true;
87+
TryEnableReadLineHistory();
8088
}
8189

8290
Out = output;
8391
Error = error;
8492
In = input;
8593
}
94+
95+
// Isolate the ReadLine reference so JIT does not resolve it unless called.
96+
[MethodImpl(MethodImplOptions.NoInlining)]
97+
private static string ReadLineInteractive()
98+
{
99+
try
100+
{
101+
return RL.Read();
102+
}
103+
catch (System.IO.FileLoadException)
104+
{
105+
// ReadLine is not strongly named or not resolvable on netfx test hosts; fallback to Console.ReadLine.
106+
return Console.ReadLine();
107+
}
108+
catch (TypeInitializationException tie) when (tie.InnerException is System.IO.FileLoadException)
109+
{
110+
return Console.ReadLine();
111+
}
112+
}
113+
114+
// Isolate the ReadLine reference so JIT does not resolve it unless called.
115+
[MethodImpl(MethodImplOptions.NoInlining)]
116+
private static void TryEnableReadLineHistory()
117+
{
118+
try
119+
{
120+
RL.HistoryEnabled = true;
121+
}
122+
catch (System.IO.FileLoadException)
123+
{
124+
// netfx may require a strong-named dependency chain; ignore for tests.
125+
}
126+
catch (TypeInitializationException tie) when (tie.InnerException is System.IO.FileLoadException)
127+
{
128+
// Same case wrapped by a type initializer; ignore.
129+
}
130+
}
86131
}
87132
}

src/Dotnet.Script.Core/ScriptPublisher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Dotnet.Script.Core
1111
{
1212
public class ScriptPublisher
1313
{
14-
private const string ScriptingVersion = "4.11.0";
14+
private const string ScriptingVersion = "5.0.0-2.final";
1515

1616
private readonly ScriptProjectProvider _scriptProjectProvider;
1717
private readonly ScriptEmitter _scriptEmitter;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
<Compile Include="..\Dotnet.Script.DependencyModel\ProjectSystem\ScriptParserInternal.cs" Link="ScriptParserInternal.cs" />
2121
</ItemGroup>
2222
<ItemGroup>
23-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.11.0" />
23+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="5.0.0-2.final" />
2424
</ItemGroup>
2525
</Project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<runtime>
4+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
5+
<dependentAssembly>
6+
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
7+
<bindingRedirect oldVersion="0.0.0.0-9999.0.0.0" newVersion="9.0.0.0" />
8+
<codeBase version="9.0.0.0" href="System.Collections.Immutable.dll" />
9+
</dependentAssembly>
10+
<dependentAssembly>
11+
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
12+
<bindingRedirect oldVersion="0.0.0.0-9999.0.0.0" newVersion="6.0.1.0" />
13+
<codeBase version="6.0.1.0" href="System.Runtime.CompilerServices.Unsafe.dll" />
14+
</dependentAssembly>
15+
</assemblyBinding>
16+
</runtime>
17+
</configuration>
Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project Sdk="Microsoft.NET.Sdk">
3-
<PropertyGroup>
4-
<TargetFramework>net472</TargetFramework>
5-
<SignAssembly>true</SignAssembly>
6-
<AssemblyOriginatorKeyFile>../dotnet-script.snk</AssemblyOriginatorKeyFile>
7-
</PropertyGroup>
8-
<ItemGroup>
9-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
10-
<PackageReference Include="xunit" Version="2.9.2" />
11-
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
12-
<PrivateAssets>all</PrivateAssets>
13-
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
14-
</PackageReference>
15-
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
16-
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="All" />
17-
<PackageReference Include="StrongNamer" Version="0.2.5" PrivateAssets="all" />
18-
</ItemGroup>
19-
<ItemGroup>
20-
<ProjectReference Include="..\Dotnet.Script.Core\Dotnet.Script.Core.csproj" />
21-
<ProjectReference Include="..\Dotnet.Script.DependencyModel\Dotnet.Script.DependencyModel.csproj" />
22-
<ProjectReference Include="..\Dotnet.Script.Shared.Tests\Dotnet.Script.Shared.Tests.csproj" />
23-
</ItemGroup>
24-
<ItemGroup>
25-
<Content Include="xunit.runner.json">
26-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
27-
</Content>
28-
</ItemGroup>
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net472</TargetFramework>
4+
<SignAssembly>true</SignAssembly>
5+
<AssemblyOriginatorKeyFile>../dotnet-script.snk</AssemblyOriginatorKeyFile>
6+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
7+
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
8+
<ImmutablePkgVersion>9.0.0</ImmutablePkgVersion>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
13+
<PackageReference Include="xunit" Version="2.9.2" />
14+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
15+
<PrivateAssets>all</PrivateAssets>
16+
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
17+
</PackageReference>
18+
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
19+
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="All" />
20+
<PackageReference Include="System.Collections.Immutable" Version="$(ImmutablePkgVersion)" />
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<ProjectReference Include="..\Dotnet.Script.Core\Dotnet.Script.Core.csproj" />
25+
<ProjectReference Include="..\Dotnet.Script.DependencyModel\Dotnet.Script.DependencyModel.csproj" />
26+
<ProjectReference Include="..\Dotnet.Script.Shared.Tests\Dotnet.Script.Shared.Tests.csproj" />
27+
</ItemGroup>
28+
29+
<!-- overwrite output for Immutable to ensure netstandard2.0 asset! -->
30+
<Target Name="ForceNetStandardAssets" AfterTargets="Build">
31+
<Copy SourceFiles="$(NuGetPackageRoot)system.collections.immutable\$(ImmutablePkgVersion)\lib\netstandard2.0\System.Collections.Immutable.dll"
32+
DestinationFolder="$(OutDir)" OverWriteReadOnlyFiles="true" />
33+
</Target>
2934
</Project>

src/Dotnet.Script.Extras/Dotnet.Script.Extras.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
1212
</PropertyGroup>
1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.11.0" />
15-
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
14+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="5.0.0-2.final" />
15+
<PackageReference Include="System.Collections.Immutable" Version="9.0.0" />
1616
</ItemGroup>
1717
</Project>

src/Dotnet.Script.Tests/ScriptExecutionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void ShouldWriteCompilerWarningsToStandardError()
9191
{
9292
var result = ScriptTestRunner.Default.ExecuteFixture(fixture: "CompilationWarning", "--no-cache");
9393
Assert.True(string.IsNullOrWhiteSpace(result.StandardOut));
94-
Assert.Contains("CS1998", result.StandardError, StringComparison.OrdinalIgnoreCase);
94+
Assert.Contains("CS0162", result.StandardError, StringComparison.OrdinalIgnoreCase);
9595
}
9696

9797
[Fact]
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
public async Task Foo()
1+
using System;
2+
3+
public void Foo()
24
{
5+
return;
6+
Console.WriteLine("This is unreachable code.");
37
}

src/Dotnet.Script/Dotnet.Script.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<AssemblyOriginatorKeyFile>../dotnet-script.snk</AssemblyOriginatorKeyFile>
2626
</PropertyGroup>
2727
<ItemGroup>
28-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
28+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.0.0-2.final" />
2929
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.1.1" />
3030
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="10.0.0" Condition="'$(TargetFramework)' == 'net10.0'" />
3131
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0" Condition="'$(TargetFramework)' == 'net9.0'" />

0 commit comments

Comments
 (0)