Browse Source

Update Nancy to latest Mono and .NET Core (#5516)

* Update container versions

* Update to latest Nancy

* Allow synchronous IO

* Update to 3.1

* Remove .NET Core only warning

* Update .NET Framework packages

* Update Dapper and MySqlConnector refs

* Simplify project file
Rich Lander 5 years ago
parent
commit
657b22c5fb

+ 5 - 6
frameworks/CSharp/nancy/nancy-netcore.dockerfile

@@ -1,12 +1,11 @@
-FROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS build
-WORKDIR /app
+FROM mcr.microsoft.com/dotnet/core/sdk:3.1.101 AS build
+WORKDIR /source
 COPY src .
-RUN dotnet publish -c Release -f netcoreapp2.1 -o out
+RUN dotnet publish -c Release -f netcoreapp3.1 -o /app
 
-FROM mcr.microsoft.com/dotnet/core/aspnet:2.1 AS runtime
+FROM mcr.microsoft.com/dotnet/core/aspnet:3.1.2 AS runtime
 ENV ASPNETCORE_URLS http://+:8080
-ENV COMPlus_ReadyToRun 0
 WORKDIR /app
-COPY --from=build /app/out ./
+COPY --from=build /app .
 
 ENTRYPOINT ["dotnet", "NancyBenchmark.dll"]

+ 5 - 5
frameworks/CSharp/nancy/nancy.dockerfile

@@ -1,11 +1,11 @@
-FROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS build
-WORKDIR /app
+FROM mcr.microsoft.com/dotnet/core/sdk:3.1.101 AS build
+WORKDIR /source
 COPY src .
-RUN dotnet publish -c Release -f net471 -o out
+RUN dotnet publish -c Release -f net471 -o /app
 
-FROM mono:5.12.0.226 AS runtime
+FROM mono:6.8 AS runtime
 WORKDIR /app
-COPY --from=build /app/out ./
+COPY --from=build /app .
 ENV ASPNETCORE_URLS http://+:8080
 
 ENTRYPOINT ["mono", "--server", "--gc=sgen", "--gc-params=mode=throughput", "NancyBenchmark.exe"]

+ 8 - 21
frameworks/CSharp/nancy/src/NancyBenchmark.csproj

@@ -1,14 +1,11 @@
 <Project Sdk="Microsoft.NET.Sdk.Web">
   <PropertyGroup>
-    <TargetFrameworks>netcoreapp2.1;net471</TargetFrameworks>
+    <TargetFrameworks>netcoreapp3.1;net471</TargetFrameworks>
     <OutputType>Exe</OutputType>
-    <LangVersion>7.3</LangVersion>
-    <RootNamespace>Nancy.Benchmark</RootNamespace>
   </PropertyGroup>
   
   <PropertyGroup Condition=" '$(TargetFramework)' == 'net471' ">
     <RuntimeIdentifiers>linux-x64</RuntimeIdentifiers>
-    <!-- Add the myget feed, without altering any other configurations. -->
   </PropertyGroup>
   
   <ItemGroup>
@@ -17,28 +14,18 @@
   </ItemGroup>
 
   <ItemGroup>
-    <PackageReference Include="Nancy" Version="2.0.0-pre1909" />
-    <PackageReference Include="MySqlConnector" Version="0.44.1" />
-    <PackageReference Include="Dapper" Version="1.50.4" />
+    <PackageReference Include="Nancy" Version="2.0.0" />
+    <PackageReference Include="MySqlConnector" Version="0.61.0" />
+    <PackageReference Include="Dapper" Version="2.0.30" />
   </ItemGroup>
 
-  <ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1' ">
-    <PackageReference Include="Microsoft.AspNetCore.App" />
+  <ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
+    <PackageReference Include="Microsoft.AspNetCore.Owin" Version="3.1.2" />
   </ItemGroup>
   
   <ItemGroup Condition=" '$(TargetFramework)' == 'net471' ">
-    <PackageReference Include="Microsoft.AspNetCore" Version="2.1.0" />
-    <PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.1.0" />
-    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.0" />
-    <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.1.0" />
-    <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets" Version="2.1.0" />
-    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.1.0" />
-    <PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.0" />
-    <PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="2.1.0" />
-    <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.1.0" />
-    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.0" />
-    <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.1.0" />
-    <PackageReference Include="Microsoft.AspNetCore.Owin" Version="2.1.0" />
+    <PackageReference Include="Microsoft.AspNetCore" Version="2.1.7" />
+    <PackageReference Include="Microsoft.AspNetCore.Owin" Version="2.1.1" />
     <PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0"/>
   </ItemGroup>
 

+ 0 - 8
frameworks/CSharp/nancy/src/NuGet.config

@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<configuration>
-  <packageSources>
-    <clear />
-    <add key="NuGet" value="https://api.nuget.org/v3/index.json" />
-    <add key="Nancy" value="https://www.myget.org/F/nancyfx/api/v3/index.json" />
-  </packageSources>
-</configuration>

+ 4 - 1
frameworks/CSharp/nancy/src/Program.cs

@@ -18,7 +18,10 @@
                 .UseContentRoot(Directory.GetCurrentDirectory())
                 .UseConfiguration(config)
                 .UseStartup<Startup>()
-                .UseKestrel()
+                .UseKestrel(o =>
+                {
+                    o.AllowSynchronousIO = true;
+                })
                 .Build();
 
             webHost.Run();

+ 8 - 5
frameworks/CSharp/nancy/src/Startup.cs

@@ -8,22 +8,25 @@
 
     public class Startup
     {
-        private readonly IConfiguration config;
+        public IConfiguration Configuration { get; }
+
+#if NETFRAMEWORK
         public Startup(IHostingEnvironment env)
+#elif NETCOREAPP
+        public Startup(IWebHostEnvironment env)
+#endif
         {
             var builder = new ConfigurationBuilder()
                               .AddJsonFile("appsettings.json")
                               .SetBasePath(env.ContentRootPath);
 
-            config = builder.Build();
+            Configuration = builder.Build();
         }
 
-        public void ConfigureServices(IServiceCollection services) { }
-
         public void Configure(IApplicationBuilder app)
         {
             var appConfig = new AppConfiguration();
-            ConfigurationBinder.Bind(config, appConfig);
+            ConfigurationBinder.Bind(Configuration, appConfig);
 
             app.UseOwin(x => x.UseNancy(opt => opt.Bootstrapper = new Bootstrapper(appConfig)));
         }