Skip to content

Commit

Permalink
Upgrade to .NET 8
Browse files Browse the repository at this point in the history
  • Loading branch information
Windows10CE committed Nov 26, 2023
1 parent d67d0b7 commit f1deb82
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 18 deletions.
12 changes: 6 additions & 6 deletions CSharpRepl.Tests/CSharpRepl.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
<PropertyGroup>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
<LangVersion>preview</LangVersion>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>CSDiscordService.Tests</RootNamespace>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.reporters" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.2" />
<PackageReference Include="xunit.runner.reporters" Version="2.6.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
18 changes: 14 additions & 4 deletions CSharpRepl.Tests/EvalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,33 @@ public EvalTests(ITestOutputHelper outputHelper)
[InlineData(@"var a = ""thing""; return a;", "thing", "string")]
[InlineData("Math.Pow(1,2)", 1D, "double")]
[InlineData(@"Enumerable.Range(0,1).Select(a=>""@"");", null, null)]
[InlineData("typeof(int)", "System.Int32, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e", "RuntimeType")]
[InlineData("typeof(int)", "System.Int32, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e", "RuntimeType")]
[InlineData("Assembly.GetExecutingAssembly()", true, "RuntimeAssembly")]
[InlineData("TimeSpan.FromSeconds(2310293892)", "26739.12:18:12", "TimeSpan")]
[InlineData("float.PositiveInfinity", "Infinity", "float")]
[InlineData("List<int> l = [1, 2, 3]; l", "[1,2,3]", "List<int>")]
public async Task Eval_WellFormattedCodeExecutes(string expr, object expected, string type)
{
var (result, statusCode) = await Execute(expr);
var res = result.ReturnValue as JsonElement?;
object convertedValue;
if (expected is string || expected is null)
if (res.Value.ValueKind == JsonValueKind.Array)
{
convertedValue = res.Value.GetRawText();
}
else if (expected is string || expected is null)
{
convertedValue = res?.GetString();
}
else if (res.Value.ValueKind == JsonValueKind.Object)
{
convertedValue = res.HasValue;
}
else if (result.ReturnTypeName == "RuntimeAssembly")
{
// nothing to do here, value is random for this test
convertedValue = expected;
}
else
{
var value = res.Value.GetRawText();
Expand Down Expand Up @@ -186,8 +196,8 @@ public async Task Eval_ConsoleOutputIsCaptured(string expr, string consoleOut, o
[Fact]
public async Task Eval_LoadDLLThatExposesTypeOfADependency()
{
var expr = "#nuget CK.ActivityMonitor\nvar m = new ActivityMonitor();";
var (_, statusCode) = await Execute(expr);
var expr = "#nuget CK.ActivityMonitor\nvar m = new CK.Core.ActivityMonitor();";
var (result, statusCode) = await Execute(expr);

Assert.Equal(HttpStatusCode.OK, statusCode);
}
Expand Down
8 changes: 4 additions & 4 deletions CSharpRepl/CSharpRepl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<EnablePreviewFeatures>true</EnablePreviewFeatures>
<LangVersion>preview</LangVersion>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
<UserSecretsId>03629088-8bb9-4faf-8162-debf93066bc4</UserSecretsId>
</PropertyGroup>
Expand All @@ -14,10 +14,10 @@

<ItemGroup>
<PackageReference Include="AngouriMath" Version="1.3.0" />
<PackageReference Include="ICSharpCode.Decompiler" Version="8.0.0.7313-preview4" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.5.0" />
<PackageReference Include="ICSharpCode.Decompiler" Version="8.2.0.7535" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.8.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NuGet.Resolver" Version="6.5.0" />
<PackageReference Include="NuGet.Resolver" Version="6.8.0" />
<PackageReference Include="Seq.Extensions.Logging" Version="6.1.0" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion CSharpRepl/Eval/NugetDirectiveProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task PreProcess(string directive, ScriptExecutionContext context, A
{
var actionLogger = new NugetLogger(logger);
var nugetDirective = NugetPreProcessorDirective.Parse(directive);
string frameworkName = Assembly.GetEntryAssembly()!.GetCustomAttributes(true)
string frameworkName = typeof(NugetDirectiveProcessor).Assembly.GetCustomAttributes(true)
.OfType<System.Runtime.Versioning.TargetFrameworkAttribute>()
.Select(x => x.FrameworkName)
.FirstOrDefault()!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializer

public class AssemblyJsonConverterFactory : JsonConverterFactory
{
public override bool CanConvert(Type typeToConvert) => typeToConvert == Type.GetType("System.RuntimeAssembly");
public override bool CanConvert(Type typeToConvert) => typeToConvert == Type.GetType("System.Reflection.RuntimeAssembly");
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options)
{
return new RuntimeAssemblyJsonConverter();
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:7.0 as dotnet-build
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 as dotnet-build
ARG TARGETPLATFORM
ARG BUILDPLATFORM
WORKDIR /src
Expand All @@ -10,7 +10,7 @@ RUN dotnet build --configuration Release --no-restore
#RUN dotnet test --configuration Release CSharpRepl.Tests/CSharpRepl.Tests.csproj --no-build --no-restore
RUN dotnet publish --configuration Release CSharpRepl/CSharpRepl.csproj --no-build --no-restore -o /app

FROM --platform=$TARGETPLATFORM mcr.microsoft.com/dotnet/aspnet:7.0
FROM --platform=$TARGETPLATFORM mcr.microsoft.com/dotnet/aspnet:8.0
ARG TARGETPLATFORM
ARG BUILDPLATFORM
WORKDIR /app
Expand Down

0 comments on commit f1deb82

Please sign in to comment.