From e9ca43440512f06e0e7ef1aedad8ee58b1b90afa Mon Sep 17 00:00:00 2001 From: SteveSandersonMS Date: Wed, 27 Jul 2016 12:25:32 +0100 Subject: [PATCH] Update all templates to match latest "yo aspnet" output --- templates/Angular2Spa/Program.cs | 31 ++++++++++++ templates/Angular2Spa/Startup.cs | 49 ++++++++++--------- templates/Angular2Spa/appsettings.json | 2 +- templates/Angular2Spa/project.json | 41 ++-------------- templates/KnockoutSpa/Program.cs | 31 ++++++++++++ templates/KnockoutSpa/Startup.cs | 49 ++++++++++--------- templates/KnockoutSpa/appsettings.json | 2 +- templates/KnockoutSpa/project.json | 41 ++-------------- templates/ReactReduxSpa/Program.cs | 31 ++++++++++++ templates/ReactReduxSpa/Startup.cs | 49 ++++++++++--------- templates/ReactReduxSpa/appsettings.json | 2 +- templates/ReactReduxSpa/project.json | 41 ++-------------- templates/ReactSpa/Program.cs | 31 ++++++++++++ templates/ReactSpa/Startup.cs | 49 ++++++++++--------- templates/ReactSpa/appsettings.json | 2 +- templates/ReactSpa/project.json | 41 ++-------------- templates/WebApplicationBasic/Program.cs | 31 ++++++++++++ templates/WebApplicationBasic/Startup.cs | 44 ++++++++++------- .../WebApplicationBasic/appsettings.json | 2 +- templates/WebApplicationBasic/project.json | 41 ++-------------- 20 files changed, 311 insertions(+), 299 deletions(-) create mode 100644 templates/Angular2Spa/Program.cs create mode 100644 templates/KnockoutSpa/Program.cs create mode 100644 templates/ReactReduxSpa/Program.cs create mode 100644 templates/ReactSpa/Program.cs create mode 100644 templates/WebApplicationBasic/Program.cs diff --git a/templates/Angular2Spa/Program.cs b/templates/Angular2Spa/Program.cs new file mode 100644 index 0000000..b2e5e4b --- /dev/null +++ b/templates/Angular2Spa/Program.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; + +namespace WebApplicationBasic +{ + public class Program + { + public static void Main(string[] args) + { + var config = new ConfigurationBuilder() + .AddCommandLine(args) + .AddEnvironmentVariables(prefix: "ASPNETCORE_") + .Build(); + + var host = new WebHostBuilder() + .UseConfiguration(config) + .UseKestrel() + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseIISIntegration() + .UseStartup() + .Build(); + + host.Run(); + } + } +} diff --git a/templates/Angular2Spa/Startup.cs b/templates/Angular2Spa/Startup.cs index 0c5cc48..e5d73ed 100755 --- a/templates/Angular2Spa/Startup.cs +++ b/templates/Angular2Spa/Startup.cs @@ -1,42 +1,57 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.SpaServices.Webpack; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Newtonsoft.Json.Serialization; namespace WebApplicationBasic { public class Startup { + public Startup(IHostingEnvironment env) + { + var builder = new ConfigurationBuilder() + .SetBasePath(env.ContentRootPath) + .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) + .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) + .AddEnvironmentVariables(); + Configuration = builder.Build(); + } + + public IConfigurationRoot Configuration { get; } + // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddMvc().AddJsonOptions(options => - { - options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); - }); + // Add framework services. + services.AddMvc(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { - app.UseDeveloperExceptionPage(); + loggerFactory.AddConsole(Configuration.GetSection("Logging")); + loggerFactory.AddDebug(); - if (env.IsDevelopment()) { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { HotModuleReplacement = true }); } + else + { + app.UseExceptionHandler("/Home/Error"); + } app.UseStaticFiles(); - loggerFactory.AddConsole(); + app.UseMvc(routes => { routes.MapRoute( @@ -48,17 +63,5 @@ namespace WebApplicationBasic defaults: new { controller = "Home", action = "Index" }); }); } - - public static void Main(string[] args) - { - var host = new WebHostBuilder() - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseIISIntegration() - .UseKestrel() - .UseStartup() - .Build(); - - host.Run(); - } } } diff --git a/templates/Angular2Spa/appsettings.json b/templates/Angular2Spa/appsettings.json index e5472e5..723c096 100755 --- a/templates/Angular2Spa/appsettings.json +++ b/templates/Angular2Spa/appsettings.json @@ -2,7 +2,7 @@ "Logging": { "IncludeScopes": false, "LogLevel": { - "Default": "Verbose", + "Default": "Debug", "System": "Information", "Microsoft": "Information" } diff --git a/templates/Angular2Spa/project.json b/templates/Angular2Spa/project.json index 1ce5f41..845fe68 100755 --- a/templates/Angular2Spa/project.json +++ b/templates/Angular2Spa/project.json @@ -4,7 +4,6 @@ "version": "1.0.0", "type": "platform" }, - "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0", "Microsoft.AspNetCore.AngularServices": "1.0.0-*", "Microsoft.AspNetCore.Diagnostics": "1.0.0", "Microsoft.AspNetCore.Mvc": "1.0.0", @@ -17,46 +16,16 @@ "Microsoft.AspNetCore.StaticFiles": "1.0.0", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", "Microsoft.Extensions.Configuration.Json": "1.0.0", + "Microsoft.Extensions.Configuration.CommandLine": "1.0.0", "Microsoft.Extensions.Logging": "1.0.0", "Microsoft.Extensions.Logging.Console": "1.0.0", "Microsoft.Extensions.Logging.Debug": "1.0.0", - "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { - "version": "1.0.0-preview2-final", - "type": "build" - }, - "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": { - "version": "1.0.0-preview2-final", - "type": "build" - } + "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0" }, "tools": { - "Microsoft.AspNetCore.Razor.Tools": { - "version": "1.0.0-preview2-final", - "imports": "portable-net45+win8+dnxcore50" - }, - "Microsoft.AspNetCore.Server.IISIntegration.Tools": { - "version": "1.0.0-preview2-final", - "imports": "portable-net45+win8+dnxcore50" - }, - "Microsoft.EntityFrameworkCore.Tools": { - "version": "1.0.0-preview2-final", - "imports": [ - "portable-net45+win8+dnxcore50", - "portable-net45+win8" - ] - }, - "Microsoft.Extensions.SecretManager.Tools": { - "version": "1.0.0-preview2-final", - "imports": "portable-net45+win8+dnxcore50" - }, - "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { - "version": "1.0.0-preview2-final", - "imports": [ - "portable-net45+win8+dnxcore50", - "portable-net45+win8" - ] - }, + "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final", + "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final", "Microsoft.DotNet.Watcher.Tools": "1.0.0-preview2-final" }, @@ -64,14 +33,12 @@ "netcoreapp1.0": { "imports": [ "dotnet5.6", - "dnxcore50", "portable-net45+win8" ] } }, "buildOptions": { - "debugType": "portable", "emitEntryPoint": true, "preserveCompilationContext": true }, diff --git a/templates/KnockoutSpa/Program.cs b/templates/KnockoutSpa/Program.cs new file mode 100644 index 0000000..b2e5e4b --- /dev/null +++ b/templates/KnockoutSpa/Program.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; + +namespace WebApplicationBasic +{ + public class Program + { + public static void Main(string[] args) + { + var config = new ConfigurationBuilder() + .AddCommandLine(args) + .AddEnvironmentVariables(prefix: "ASPNETCORE_") + .Build(); + + var host = new WebHostBuilder() + .UseConfiguration(config) + .UseKestrel() + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseIISIntegration() + .UseStartup() + .Build(); + + host.Run(); + } + } +} diff --git a/templates/KnockoutSpa/Startup.cs b/templates/KnockoutSpa/Startup.cs index 0c5cc48..e5d73ed 100755 --- a/templates/KnockoutSpa/Startup.cs +++ b/templates/KnockoutSpa/Startup.cs @@ -1,42 +1,57 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.SpaServices.Webpack; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Newtonsoft.Json.Serialization; namespace WebApplicationBasic { public class Startup { + public Startup(IHostingEnvironment env) + { + var builder = new ConfigurationBuilder() + .SetBasePath(env.ContentRootPath) + .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) + .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) + .AddEnvironmentVariables(); + Configuration = builder.Build(); + } + + public IConfigurationRoot Configuration { get; } + // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddMvc().AddJsonOptions(options => - { - options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); - }); + // Add framework services. + services.AddMvc(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { - app.UseDeveloperExceptionPage(); + loggerFactory.AddConsole(Configuration.GetSection("Logging")); + loggerFactory.AddDebug(); - if (env.IsDevelopment()) { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { HotModuleReplacement = true }); } + else + { + app.UseExceptionHandler("/Home/Error"); + } app.UseStaticFiles(); - loggerFactory.AddConsole(); + app.UseMvc(routes => { routes.MapRoute( @@ -48,17 +63,5 @@ namespace WebApplicationBasic defaults: new { controller = "Home", action = "Index" }); }); } - - public static void Main(string[] args) - { - var host = new WebHostBuilder() - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseIISIntegration() - .UseKestrel() - .UseStartup() - .Build(); - - host.Run(); - } } } diff --git a/templates/KnockoutSpa/appsettings.json b/templates/KnockoutSpa/appsettings.json index e5472e5..723c096 100755 --- a/templates/KnockoutSpa/appsettings.json +++ b/templates/KnockoutSpa/appsettings.json @@ -2,7 +2,7 @@ "Logging": { "IncludeScopes": false, "LogLevel": { - "Default": "Verbose", + "Default": "Debug", "System": "Information", "Microsoft": "Information" } diff --git a/templates/KnockoutSpa/project.json b/templates/KnockoutSpa/project.json index 66ff147..d3e2777 100755 --- a/templates/KnockoutSpa/project.json +++ b/templates/KnockoutSpa/project.json @@ -4,7 +4,6 @@ "version": "1.0.0", "type": "platform" }, - "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0", "Microsoft.AspNetCore.SpaServices": "1.0.0-*", "Microsoft.AspNetCore.Diagnostics": "1.0.0", "Microsoft.AspNetCore.Mvc": "1.0.0", @@ -17,46 +16,16 @@ "Microsoft.AspNetCore.StaticFiles": "1.0.0", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", "Microsoft.Extensions.Configuration.Json": "1.0.0", + "Microsoft.Extensions.Configuration.CommandLine": "1.0.0", "Microsoft.Extensions.Logging": "1.0.0", "Microsoft.Extensions.Logging.Console": "1.0.0", "Microsoft.Extensions.Logging.Debug": "1.0.0", - "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { - "version": "1.0.0-preview2-final", - "type": "build" - }, - "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": { - "version": "1.0.0-preview2-final", - "type": "build" - } + "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0" }, "tools": { - "Microsoft.AspNetCore.Razor.Tools": { - "version": "1.0.0-preview2-final", - "imports": "portable-net45+win8+dnxcore50" - }, - "Microsoft.AspNetCore.Server.IISIntegration.Tools": { - "version": "1.0.0-preview2-final", - "imports": "portable-net45+win8+dnxcore50" - }, - "Microsoft.EntityFrameworkCore.Tools": { - "version": "1.0.0-preview2-final", - "imports": [ - "portable-net45+win8+dnxcore50", - "portable-net45+win8" - ] - }, - "Microsoft.Extensions.SecretManager.Tools": { - "version": "1.0.0-preview2-final", - "imports": "portable-net45+win8+dnxcore50" - }, - "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { - "version": "1.0.0-preview2-final", - "imports": [ - "portable-net45+win8+dnxcore50", - "portable-net45+win8" - ] - }, + "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final", + "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final", "Microsoft.DotNet.Watcher.Tools": "1.0.0-preview2-final" }, @@ -64,14 +33,12 @@ "netcoreapp1.0": { "imports": [ "dotnet5.6", - "dnxcore50", "portable-net45+win8" ] } }, "buildOptions": { - "debugType": "portable", "emitEntryPoint": true, "preserveCompilationContext": true }, diff --git a/templates/ReactReduxSpa/Program.cs b/templates/ReactReduxSpa/Program.cs new file mode 100644 index 0000000..b2e5e4b --- /dev/null +++ b/templates/ReactReduxSpa/Program.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; + +namespace WebApplicationBasic +{ + public class Program + { + public static void Main(string[] args) + { + var config = new ConfigurationBuilder() + .AddCommandLine(args) + .AddEnvironmentVariables(prefix: "ASPNETCORE_") + .Build(); + + var host = new WebHostBuilder() + .UseConfiguration(config) + .UseKestrel() + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseIISIntegration() + .UseStartup() + .Build(); + + host.Run(); + } + } +} diff --git a/templates/ReactReduxSpa/Startup.cs b/templates/ReactReduxSpa/Startup.cs index 6f4babb..750d79c 100755 --- a/templates/ReactReduxSpa/Startup.cs +++ b/templates/ReactReduxSpa/Startup.cs @@ -1,43 +1,58 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.SpaServices.Webpack; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Newtonsoft.Json.Serialization; namespace WebApplicationBasic { public class Startup { + public Startup(IHostingEnvironment env) + { + var builder = new ConfigurationBuilder() + .SetBasePath(env.ContentRootPath) + .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) + .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) + .AddEnvironmentVariables(); + Configuration = builder.Build(); + } + + public IConfigurationRoot Configuration { get; } + // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddMvc().AddJsonOptions(options => - { - options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); - }); + // Add framework services. + services.AddMvc(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { - app.UseDeveloperExceptionPage(); + loggerFactory.AddConsole(Configuration.GetSection("Logging")); + loggerFactory.AddDebug(); - if (env.IsDevelopment()) { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { HotModuleReplacement = true, ReactHotModuleReplacement = true }); } + else + { + app.UseExceptionHandler("/Home/Error"); + } app.UseStaticFiles(); - loggerFactory.AddConsole(); + app.UseMvc(routes => { routes.MapRoute( @@ -49,17 +64,5 @@ namespace WebApplicationBasic defaults: new { controller = "Home", action = "Index" }); }); } - - public static void Main(string[] args) - { - var host = new WebHostBuilder() - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseIISIntegration() - .UseKestrel() - .UseStartup() - .Build(); - - host.Run(); - } } } diff --git a/templates/ReactReduxSpa/appsettings.json b/templates/ReactReduxSpa/appsettings.json index e5472e5..723c096 100755 --- a/templates/ReactReduxSpa/appsettings.json +++ b/templates/ReactReduxSpa/appsettings.json @@ -2,7 +2,7 @@ "Logging": { "IncludeScopes": false, "LogLevel": { - "Default": "Verbose", + "Default": "Debug", "System": "Information", "Microsoft": "Information" } diff --git a/templates/ReactReduxSpa/project.json b/templates/ReactReduxSpa/project.json index f768eca..0794a38 100755 --- a/templates/ReactReduxSpa/project.json +++ b/templates/ReactReduxSpa/project.json @@ -4,7 +4,6 @@ "version": "1.0.0", "type": "platform" }, - "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0", "Microsoft.AspNetCore.ReactServices": "1.0.0-*", "Microsoft.AspNetCore.Diagnostics": "1.0.0", "Microsoft.AspNetCore.Mvc": "1.0.0", @@ -17,46 +16,16 @@ "Microsoft.AspNetCore.StaticFiles": "1.0.0", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", "Microsoft.Extensions.Configuration.Json": "1.0.0", + "Microsoft.Extensions.Configuration.CommandLine": "1.0.0", "Microsoft.Extensions.Logging": "1.0.0", "Microsoft.Extensions.Logging.Console": "1.0.0", "Microsoft.Extensions.Logging.Debug": "1.0.0", - "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { - "version": "1.0.0-preview2-final", - "type": "build" - }, - "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": { - "version": "1.0.0-preview2-final", - "type": "build" - } + "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0" }, "tools": { - "Microsoft.AspNetCore.Razor.Tools": { - "version": "1.0.0-preview2-final", - "imports": "portable-net45+win8+dnxcore50" - }, - "Microsoft.AspNetCore.Server.IISIntegration.Tools": { - "version": "1.0.0-preview2-final", - "imports": "portable-net45+win8+dnxcore50" - }, - "Microsoft.EntityFrameworkCore.Tools": { - "version": "1.0.0-preview2-final", - "imports": [ - "portable-net45+win8+dnxcore50", - "portable-net45+win8" - ] - }, - "Microsoft.Extensions.SecretManager.Tools": { - "version": "1.0.0-preview2-final", - "imports": "portable-net45+win8+dnxcore50" - }, - "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { - "version": "1.0.0-preview2-final", - "imports": [ - "portable-net45+win8+dnxcore50", - "portable-net45+win8" - ] - }, + "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final", + "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final", "Microsoft.DotNet.Watcher.Tools": "1.0.0-preview2-final" }, @@ -64,14 +33,12 @@ "netcoreapp1.0": { "imports": [ "dotnet5.6", - "dnxcore50", "portable-net45+win8" ] } }, "buildOptions": { - "debugType": "portable", "emitEntryPoint": true, "preserveCompilationContext": true }, diff --git a/templates/ReactSpa/Program.cs b/templates/ReactSpa/Program.cs new file mode 100644 index 0000000..b2e5e4b --- /dev/null +++ b/templates/ReactSpa/Program.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; + +namespace WebApplicationBasic +{ + public class Program + { + public static void Main(string[] args) + { + var config = new ConfigurationBuilder() + .AddCommandLine(args) + .AddEnvironmentVariables(prefix: "ASPNETCORE_") + .Build(); + + var host = new WebHostBuilder() + .UseConfiguration(config) + .UseKestrel() + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseIISIntegration() + .UseStartup() + .Build(); + + host.Run(); + } + } +} diff --git a/templates/ReactSpa/Startup.cs b/templates/ReactSpa/Startup.cs index 6f4babb..750d79c 100755 --- a/templates/ReactSpa/Startup.cs +++ b/templates/ReactSpa/Startup.cs @@ -1,43 +1,58 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.SpaServices.Webpack; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Newtonsoft.Json.Serialization; namespace WebApplicationBasic { public class Startup { + public Startup(IHostingEnvironment env) + { + var builder = new ConfigurationBuilder() + .SetBasePath(env.ContentRootPath) + .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) + .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) + .AddEnvironmentVariables(); + Configuration = builder.Build(); + } + + public IConfigurationRoot Configuration { get; } + // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddMvc().AddJsonOptions(options => - { - options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); - }); + // Add framework services. + services.AddMvc(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { - app.UseDeveloperExceptionPage(); + loggerFactory.AddConsole(Configuration.GetSection("Logging")); + loggerFactory.AddDebug(); - if (env.IsDevelopment()) { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { HotModuleReplacement = true, ReactHotModuleReplacement = true }); } + else + { + app.UseExceptionHandler("/Home/Error"); + } app.UseStaticFiles(); - loggerFactory.AddConsole(); + app.UseMvc(routes => { routes.MapRoute( @@ -49,17 +64,5 @@ namespace WebApplicationBasic defaults: new { controller = "Home", action = "Index" }); }); } - - public static void Main(string[] args) - { - var host = new WebHostBuilder() - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseIISIntegration() - .UseKestrel() - .UseStartup() - .Build(); - - host.Run(); - } } } diff --git a/templates/ReactSpa/appsettings.json b/templates/ReactSpa/appsettings.json index e5472e5..723c096 100755 --- a/templates/ReactSpa/appsettings.json +++ b/templates/ReactSpa/appsettings.json @@ -2,7 +2,7 @@ "Logging": { "IncludeScopes": false, "LogLevel": { - "Default": "Verbose", + "Default": "Debug", "System": "Information", "Microsoft": "Information" } diff --git a/templates/ReactSpa/project.json b/templates/ReactSpa/project.json index f768eca..0794a38 100755 --- a/templates/ReactSpa/project.json +++ b/templates/ReactSpa/project.json @@ -4,7 +4,6 @@ "version": "1.0.0", "type": "platform" }, - "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0", "Microsoft.AspNetCore.ReactServices": "1.0.0-*", "Microsoft.AspNetCore.Diagnostics": "1.0.0", "Microsoft.AspNetCore.Mvc": "1.0.0", @@ -17,46 +16,16 @@ "Microsoft.AspNetCore.StaticFiles": "1.0.0", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", "Microsoft.Extensions.Configuration.Json": "1.0.0", + "Microsoft.Extensions.Configuration.CommandLine": "1.0.0", "Microsoft.Extensions.Logging": "1.0.0", "Microsoft.Extensions.Logging.Console": "1.0.0", "Microsoft.Extensions.Logging.Debug": "1.0.0", - "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { - "version": "1.0.0-preview2-final", - "type": "build" - }, - "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": { - "version": "1.0.0-preview2-final", - "type": "build" - } + "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0" }, "tools": { - "Microsoft.AspNetCore.Razor.Tools": { - "version": "1.0.0-preview2-final", - "imports": "portable-net45+win8+dnxcore50" - }, - "Microsoft.AspNetCore.Server.IISIntegration.Tools": { - "version": "1.0.0-preview2-final", - "imports": "portable-net45+win8+dnxcore50" - }, - "Microsoft.EntityFrameworkCore.Tools": { - "version": "1.0.0-preview2-final", - "imports": [ - "portable-net45+win8+dnxcore50", - "portable-net45+win8" - ] - }, - "Microsoft.Extensions.SecretManager.Tools": { - "version": "1.0.0-preview2-final", - "imports": "portable-net45+win8+dnxcore50" - }, - "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { - "version": "1.0.0-preview2-final", - "imports": [ - "portable-net45+win8+dnxcore50", - "portable-net45+win8" - ] - }, + "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final", + "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final", "Microsoft.DotNet.Watcher.Tools": "1.0.0-preview2-final" }, @@ -64,14 +33,12 @@ "netcoreapp1.0": { "imports": [ "dotnet5.6", - "dnxcore50", "portable-net45+win8" ] } }, "buildOptions": { - "debugType": "portable", "emitEntryPoint": true, "preserveCompilationContext": true }, diff --git a/templates/WebApplicationBasic/Program.cs b/templates/WebApplicationBasic/Program.cs new file mode 100644 index 0000000..b2e5e4b --- /dev/null +++ b/templates/WebApplicationBasic/Program.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; + +namespace WebApplicationBasic +{ + public class Program + { + public static void Main(string[] args) + { + var config = new ConfigurationBuilder() + .AddCommandLine(args) + .AddEnvironmentVariables(prefix: "ASPNETCORE_") + .Build(); + + var host = new WebHostBuilder() + .UseConfiguration(config) + .UseKestrel() + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseIISIntegration() + .UseStartup() + .Build(); + + host.Run(); + } + } +} diff --git a/templates/WebApplicationBasic/Startup.cs b/templates/WebApplicationBasic/Startup.cs index 4ddc86c..fe5473d 100755 --- a/templates/WebApplicationBasic/Startup.cs +++ b/templates/WebApplicationBasic/Startup.cs @@ -1,11 +1,10 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -13,19 +12,42 @@ namespace WebApplicationBasic { public class Startup { + public Startup(IHostingEnvironment env) + { + var builder = new ConfigurationBuilder() + .SetBasePath(env.ContentRootPath) + .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) + .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) + .AddEnvironmentVariables(); + Configuration = builder.Build(); + } + + public IConfigurationRoot Configuration { get; } + // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { + // Add framework services. services.AddMvc(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { - app.UseDeveloperExceptionPage(); + loggerFactory.AddConsole(Configuration.GetSection("Logging")); + loggerFactory.AddDebug(); + + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + else + { + app.UseExceptionHandler("/Home/Error"); + } app.UseStaticFiles(); - loggerFactory.AddConsole(); + app.UseMvc(routes => { routes.MapRoute( @@ -33,17 +55,5 @@ namespace WebApplicationBasic template: "{controller=Home}/{action=Index}/{id?}"); }); } - - public static void Main(string[] args) - { - var host = new WebHostBuilder() - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseIISIntegration() - .UseKestrel() - .UseStartup() - .Build(); - - host.Run(); - } } } diff --git a/templates/WebApplicationBasic/appsettings.json b/templates/WebApplicationBasic/appsettings.json index e5472e5..723c096 100755 --- a/templates/WebApplicationBasic/appsettings.json +++ b/templates/WebApplicationBasic/appsettings.json @@ -2,7 +2,7 @@ "Logging": { "IncludeScopes": false, "LogLevel": { - "Default": "Verbose", + "Default": "Debug", "System": "Information", "Microsoft": "Information" } diff --git a/templates/WebApplicationBasic/project.json b/templates/WebApplicationBasic/project.json index a28b4b3..4464a43 100755 --- a/templates/WebApplicationBasic/project.json +++ b/templates/WebApplicationBasic/project.json @@ -4,7 +4,6 @@ "version": "1.0.0", "type": "platform" }, - "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0", "Microsoft.AspNetCore.Diagnostics": "1.0.0", "Microsoft.AspNetCore.Mvc": "1.0.0", "Microsoft.AspNetCore.Razor.Tools": { @@ -16,60 +15,28 @@ "Microsoft.AspNetCore.StaticFiles": "1.0.0", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", "Microsoft.Extensions.Configuration.Json": "1.0.0", + "Microsoft.Extensions.Configuration.CommandLine": "1.0.0", "Microsoft.Extensions.Logging": "1.0.0", "Microsoft.Extensions.Logging.Console": "1.0.0", "Microsoft.Extensions.Logging.Debug": "1.0.0", - "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { - "version": "1.0.0-preview2-final", - "type": "build" - }, - "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": { - "version": "1.0.0-preview2-final", - "type": "build" - } + "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0" }, "tools": { - "Microsoft.AspNetCore.Razor.Tools": { - "version": "1.0.0-preview2-final", - "imports": "portable-net45+win8+dnxcore50" - }, - "Microsoft.AspNetCore.Server.IISIntegration.Tools": { - "version": "1.0.0-preview2-final", - "imports": "portable-net45+win8+dnxcore50" - }, - "Microsoft.EntityFrameworkCore.Tools": { - "version": "1.0.0-preview2-final", - "imports": [ - "portable-net45+win8+dnxcore50", - "portable-net45+win8" - ] - }, - "Microsoft.Extensions.SecretManager.Tools": { - "version": "1.0.0-preview2-final", - "imports": "portable-net45+win8+dnxcore50" - }, - "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { - "version": "1.0.0-preview2-final", - "imports": [ - "portable-net45+win8+dnxcore50", - "portable-net45+win8" - ] - } + "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final", + "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final" }, "frameworks": { "netcoreapp1.0": { "imports": [ "dotnet5.6", - "dnxcore50", "portable-net45+win8" ] } }, "buildOptions": { - "debugType": "portable", "emitEntryPoint": true, "preserveCompilationContext": true },