[netcore] ASP.NET Core sample (mono/mono#14224)
authorEgor Bogatov <egorbo@gmail.com>
Thu, 25 Apr 2019 16:28:56 +0000 (19:28 +0300)
committerMarek Safar <marek.safar@gmail.com>
Thu, 25 Apr 2019 16:28:56 +0000 (18:28 +0200)
* ASP.NET Core sample

* update makefile

* update Home page

* Update Makefile

* remove ASPNET_SHAREDRUNTIME

* replace mvc with web sample

Commit migrated from https://github.com/mono/mono/commit/591d6d0a2139757760aaf169769f4967ee7d70e8

src/mono/netcore/.gitignore
src/mono/netcore/Makefile
src/mono/netcore/sample/AspNetCore/AspNetCore.csproj [new file with mode: 0644]
src/mono/netcore/sample/AspNetCore/Program.cs [new file with mode: 0644]
src/mono/netcore/sample/AspNetCore/Properties/launchSettings.json [new file with mode: 0644]
src/mono/netcore/sample/AspNetCore/Startup.cs [new file with mode: 0644]
src/mono/netcore/sample/AspNetCore/appsettings.Development.json [new file with mode: 0644]
src/mono/netcore/sample/AspNetCore/appsettings.json [new file with mode: 0644]
src/mono/netcore/sample/HelloWorld/Program.cs

index b001f5c..989ddd5 100644 (file)
@@ -4,6 +4,7 @@ tests
 /shared
 sdk
 dotnet*
+aspnetcore-runtime-*
 netcoreapp2.0/
 netcoreapp3.0/
 packs/
index 7e61651..23d0beb 100644 (file)
@@ -10,6 +10,9 @@ NETCORETESTS_VERSION := 4.6.0-preview5.19217.2
 # Extracted MicrosoftNETCoreAppVersion from https://github.com/dotnet/coreclr/blob/master/eng/Versions.props#L14
 NETCOREAPP_VERSION := 3.0.0-preview5-27620-01
 
+# Extracted from https://dotnetcli.blob.core.windows.net/dotnet/aspnetcore/Runtime/master/latest.version
+ASPNETCOREAPP_VERSION := 3.0.0-preview-18614-0151
+
 include roslyn.make
 
 ifeq ($(HOST_PLATFORM),win32)
@@ -31,14 +34,24 @@ XUNIT_FLAGS = -notrait category=nonlinuxtests
 endif
 
 NETCORESDK_FILE := dotnet-runtime-$(NETCOREAPP_VERSION)-$(RID).$(NETCORESDK_EXT)
-URL := https://dotnetcli.blob.core.windows.net/dotnet/Runtime/$(NETCOREAPP_VERSION)/$(NETCORESDK_FILE)
+ASPNETCORESDK_FILE := aspnetcore-runtime-$(ASPNETCOREAPP_VERSION)-$(RID).$(NETCORESDK_EXT)
+NETCORE_URL := https://dotnetcli.blob.core.windows.net/dotnet/Runtime/$(NETCOREAPP_VERSION)/$(NETCORESDK_FILE)
+ASPNETCORE_URL := https://dotnetcli.blob.core.windows.net/dotnet/aspnetcore/Runtime/$(ASPNETCOREAPP_VERSION)/$(ASPNETCORESDK_FILE)
 FEED_BASE_URL := https://dotnetfeed.blob.core.windows.net/dotnet-core
 TEST_ASSETS_URL = $(FEED_BASE_URL)/corefx-tests/$(NETCORETESTS_VERSION)/OSX.x64/netcoreapp/corefx-test-assets.xml
 
 $(NETCORESDK_FILE):
-       curl $(URL) --output $(NETCORESDK_FILE)
+       curl $(NETCORE_URL) --output $(NETCORESDK_FILE)
+       rm -rf shared/Microsoft.NETCore.App
        $(UNZIPCMD) $(NETCORESDK_FILE)
 
+# AspNetCoreApp contains its own .NET Core Runtime but we don't need it so let's remove it 
+# and update version in Microsoft.AspNetCore.App.runtimeconfig.json to NETCOREAPP_VERSION
+$(ASPNETCORESDK_FILE):
+       curl $(ASPNETCORE_URL) --output $(ASPNETCORESDK_FILE)
+       $(UNZIPCMD) $(ASPNETCORESDK_FILE)
+       sed -e 's/.*version.*/\"version\": \"$(NETCOREAPP_VERSION)\"/' < shared/Microsoft.AspNetCore.App/$(ASPNETCOREAPP_VERSION)/Microsoft.AspNetCore.App.runtimeconfig.json > 2 && mv 2 shared/Microsoft.AspNetCore.App/$(ASPNETCOREAPP_VERSION)/Microsoft.AspNetCore.App.runtimeconfig.json
+
 update-corefx: corefx/.stamp-dl-corefx-$(NETCORETESTS_VERSION)
 
 corefx/.stamp-dl-corefx-$(NETCORETESTS_VERSION): corefx-restore.csproj
@@ -55,12 +68,17 @@ corefx/.stamp-dl-corefx-tests-$(NETCORETESTS_VERSION):
        python dl-test-assets.py corefx-test-assets.xml $(FEED_BASE_URL) corefx/tests
        touch $@
 
-build-sample:
-       dotnet build sample/HelloWorld
-
 run-sample:
+       dotnet build sample/HelloWorld
        COMPlus_DebugWriteToStdErr=1 ./dotnet --fx-version "$(NETCOREAPP_VERSION)" sample/HelloWorld/bin/Debug/netcoreapp3.0/HelloWorld.dll
 
+run-aspnet-sample: prepare
+       rm -rf sample/AspNetCore/{bin,obj}
+       dotnet publish sample/AspNetCore -c Debug -r $(RID)
+       cp ../mono/mini/.libs/libmonosgen-2.0$(PLATFORM_AOT_SUFFIX) sample/AspNetCore/bin/Debug/netcoreapp3.0/$(RID)/publish/$(PLATFORM_AOT_PREFIX)coreclr$(PLATFORM_AOT_SUFFIX)
+       cp ../mcs/class/System.Private.CoreLib/bin/$(COREARCH)/System.Private.CoreLib.dll sample/AspNetCore/bin/Debug/netcoreapp3.0/$(RID)/publish/
+       COMPlus_DebugWriteToStdErr=1 ./dotnet --fx-version "$(ASPNETCOREAPP_VERSION)" sample/AspNetCore/bin/Debug/netcoreapp3.0/$(RID)/publish/AspNetCore.dll
+
 # COREHOST_TRACE=1 
 SHAREDRUNTIME := shared/Microsoft.NETCore.App/$(NETCOREAPP_VERSION)
 
@@ -77,13 +95,13 @@ link-mono:
        cp ../mono/mini/.libs/libmonosgen-2.0$(PLATFORM_AOT_SUFFIX) $(SHAREDRUNTIME)/$(PLATFORM_AOT_PREFIX)coreclr$(PLATFORM_AOT_SUFFIX)
        cp ../mcs/class/System.Private.CoreLib/bin/$(COREARCH)/System.Private.CoreLib.{dll,pdb} $(SHAREDRUNTIME)
 
-prepare: $(NETCORESDK_FILE) update-corefx update-roslyn link-mono
+prepare: $(ASPNETCORESDK_FILE) $(NETCORESDK_FILE) update-corefx update-roslyn link-mono
 
 nupkg:
        nuget pack runtime.nuspec -properties VERSION=$(VERSION)\;RID=$(RID)\;PLATFORM_AOT_SUFFIX=$(PLATFORM_AOT_SUFFIX)\;COREARCH=$(COREARCH)
 
 clean:
-       rm -rf sdk shared host dotnet tests obj corefx roslyn LICENSE.txt ThirdPartyNotices.txt $(NETCORESDK_FILE)
+       rm -rf sdk shared host dotnet tests obj corefx roslyn LICENSE.txt ThirdPartyNotices.txt $(NETCORESDK_FILE) $(ASPNETCORESDK_FILE)
 
 #
 # Running tests:
diff --git a/src/mono/netcore/sample/AspNetCore/AspNetCore.csproj b/src/mono/netcore/sample/AspNetCore/AspNetCore.csproj
new file mode 100644 (file)
index 0000000..bb9ffce
--- /dev/null
@@ -0,0 +1,7 @@
+<Project Sdk="Microsoft.NET.Sdk.Web">
+
+  <PropertyGroup>
+    <TargetFramework>netcoreapp3.0</TargetFramework>
+  </PropertyGroup>
+
+</Project>
diff --git a/src/mono/netcore/sample/AspNetCore/Program.cs b/src/mono/netcore/sample/AspNetCore/Program.cs
new file mode 100644 (file)
index 0000000..e5a1c70
--- /dev/null
@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Logging;
+
+namespace AspNetCore
+{
+    public class Program
+    {
+        public static void Main(string[] args)
+        {
+            CreateHostBuilder(args).Build().Run();
+        }
+
+        public static IHostBuilder CreateHostBuilder(string[] args) =>
+            Host.CreateDefaultBuilder(args)
+                .ConfigureWebHostDefaults(webBuilder =>
+                {
+                    webBuilder.UseStartup<Startup>();
+                });
+    }
+}
diff --git a/src/mono/netcore/sample/AspNetCore/Properties/launchSettings.json b/src/mono/netcore/sample/AspNetCore/Properties/launchSettings.json
new file mode 100644 (file)
index 0000000..592c590
--- /dev/null
@@ -0,0 +1,27 @@
+{\r
+  "iisSettings": {\r
+    "windowsAuthentication": false, \r
+    "anonymousAuthentication": true, \r
+    "iisExpress": {\r
+      "applicationUrl": "http://localhost:35206",\r
+      "sslPort": 44375\r
+    }\r
+  },\r
+  "profiles": {\r
+    "IIS Express": {\r
+      "commandName": "IISExpress",\r
+      "launchBrowser": true,\r
+      "environmentVariables": {\r
+        "ASPNETCORE_ENVIRONMENT": "Development"\r
+      }\r
+    },\r
+    "AspNetCore": {\r
+      "commandName": "Project",\r
+      "launchBrowser": true,\r
+      "applicationUrl": "https://localhost:5001;http://localhost:5000",\r
+      "environmentVariables": {\r
+        "ASPNETCORE_ENVIRONMENT": "Development"\r
+      }\r
+    }\r
+  }\r
+}
\ No newline at end of file
diff --git a/src/mono/netcore/sample/AspNetCore/Startup.cs b/src/mono/netcore/sample/AspNetCore/Startup.cs
new file mode 100644 (file)
index 0000000..a2ca498
--- /dev/null
@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+
+namespace AspNetCore
+{
+    public class Startup
+    {
+        // This method gets called by the runtime. Use this method to add services to the container.
+        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
+        public void ConfigureServices(IServiceCollection services)
+        {
+        }
+
+        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
+        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
+        {
+            if (env.IsDevelopment())
+            {
+                app.UseDeveloperExceptionPage();
+            }
+
+            app.UseRouting();
+
+            app.UseEndpoints(endpoints =>
+            {
+                endpoints.MapGet("/", async context =>
+                {
+                    string corlib = typeof(object).Assembly.FullName;
+                    bool isMono = corlib.Contains("0.0.0.0");
+                    await context.Response.WriteAsync("Hello World " + (isMono ? "from mono!\n" : "\n") + corlib);
+                });
+            });
+        }
+    }
+}
diff --git a/src/mono/netcore/sample/AspNetCore/appsettings.Development.json b/src/mono/netcore/sample/AspNetCore/appsettings.Development.json
new file mode 100644 (file)
index 0000000..a2880cb
--- /dev/null
@@ -0,0 +1,9 @@
+{\r
+  "Logging": {\r
+    "LogLevel": {\r
+      "Default": "Debug",\r
+      "System": "Information",\r
+      "Microsoft": "Information"\r
+    }\r
+  }\r
+}\r
diff --git a/src/mono/netcore/sample/AspNetCore/appsettings.json b/src/mono/netcore/sample/AspNetCore/appsettings.json
new file mode 100644 (file)
index 0000000..81ff877
--- /dev/null
@@ -0,0 +1,10 @@
+{\r
+  "Logging": {\r
+    "LogLevel": {\r
+      "Default": "Information",\r
+      "Microsoft": "Warning",\r
+      "Microsoft.Hosting.Lifetime": "Information"\r
+    }\r
+  },\r
+  "AllowedHosts": "*"\r
+}\r
index faed1e1..534b73f 100644 (file)
@@ -10,6 +10,7 @@ namespace HelloWorld
 
             Console.WriteLine(typeof(object).Assembly.FullName);
             Console.WriteLine(System.Reflection.Assembly.GetEntryAssembly ());
+            Console.WriteLine(System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription);
         }
     }
 }