diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorServerWeb-CSharp/Pages/CallWebApi.razor b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorServerWeb-CSharp/Pages/CallWebApi.razor index d3bad28a25d4..beac855d317a 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorServerWeb-CSharp/Pages/CallWebApi.razor +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorServerWeb-CSharp/Pages/CallWebApi.razor @@ -21,8 +21,8 @@ else } @code { - private HttpResponseMessage response; - private string apiResult; + private HttpResponseMessage? response; + private string? apiResult; protected override async Task OnInitializedAsync() { diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorServerWeb-CSharp/Program.cs b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorServerWeb-CSharp/Program.cs index 7560314201a3..a7d6854d0ba3 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorServerWeb-CSharp/Program.cs +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorServerWeb-CSharp/Program.cs @@ -32,7 +32,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; #if (GenerateGraph) -using Microsoft.Graph; +using Graph = Microsoft.Graph; #endif #if(MultiOrgAuth) using Microsoft.IdentityModel.Tokens; diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/ComponentsWebAssembly-CSharp/Server/Program.cs b/src/ProjectTemplates/Web.ProjectTemplates/content/ComponentsWebAssembly-CSharp/Server/Program.cs index 0c98ca375207..81337ad83cc1 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/ComponentsWebAssembly-CSharp/Server/Program.cs +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/ComponentsWebAssembly-CSharp/Server/Program.cs @@ -15,7 +15,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; #if (GenerateGraph) -using Microsoft.Graph; +using Graph = Microsoft.Graph; #endif #if (OrganizationalAuth || IndividualB2CAuth) using Microsoft.Identity.Web; diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Program.cs b/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Program.cs index f4753edc53bc..731984c6831f 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Program.cs +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Program.cs @@ -28,7 +28,7 @@ using Microsoft.IdentityModel.Tokens; #endif #if (GenerateGraph) -using Microsoft.Graph; +using Graph = Microsoft.Graph; #endif #if (IndividualLocalAuth) using Company.WebApplication1.Data; diff --git a/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/Angular-CSharp/Program.cs b/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/Angular-CSharp/Program.cs index 549d0b8bb8a1..b7ff9f83e146 100644 --- a/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/Angular-CSharp/Program.cs +++ b/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/Angular-CSharp/Program.cs @@ -1,26 +1,92 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +#if (IndividualLocalAuth) +using Microsoft.AspNetCore.Authentication; +#endif +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +#if (IndividualLocalAuth) +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity.UI; +#endif +#if (IndividualLocalAuth) +using Microsoft.EntityFrameworkCore; +#endif using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; +#if (IndividualLocalAuth) +using Company.WebApplication1.Data; +using Company.WebApplication1.Models; +#endif -namespace Company.WebApplication1 +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +#if (IndividualLocalAuth) +var connectionString = Configuration.GetConnectionString("DefaultConnection"); +builder.Services.AddDbContext(options => +#if (UseLocalDB) + options.UseSqlServer(connectionString)); +#else + options.UseSqlite(connectionString)); +#endif +builder.Services.AddDatabaseDeveloperPageExceptionFilter(); + +builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) + .AddEntityFrameworkStores(); + +builder.Services.AddIdentityServer() + .AddApiAuthorization(); + +builder.Services.AddAuthentication() + .AddIdentityServerJwt(); +#endif + +builder.Services.AddControllersWithViews(); +#if (IndividualLocalAuth) +builder.Services.AddRazorPages(); +#endif + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseDeveloperExceptionPage(); +#if (IndividualLocalAuth) + app.UseMigrationsEndPoint(); +#endif +} +else { - 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(); - }); - } +#if (RequiresHttps) + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); +} + +app.UseHttpsRedirection(); +#else } + +#endif +app.UseStaticFiles(); +app.UseRouting(); + +#if (IndividualLocalAuth) +app.UseAuthentication(); +app.UseIdentityServer(); +#endif +#if (!NoAuth) +app.UseAuthorization(); +#endif + +app.MapControllerRoute( + name: "default", + pattern: "{controller}/{action=Index}/{id?}"); +#if (IndividualLocalAuth) +app.MapRazorPages(); +#endif + +app.MapFallbackToFile("index.html");; + +app.Run(); diff --git a/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/Angular-CSharp/Startup.cs b/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/Angular-CSharp/Startup.cs deleted file mode 100644 index c29f37c468be..000000000000 --- a/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/Angular-CSharp/Startup.cs +++ /dev/null @@ -1,109 +0,0 @@ -#if (IndividualLocalAuth) -using Microsoft.AspNetCore.Authentication; -#endif -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -#if (IndividualLocalAuth) -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Identity.UI; -#endif -#if (RequiresHttps) -using Microsoft.AspNetCore.HttpsPolicy; -#endif -#if (IndividualLocalAuth) -using Microsoft.EntityFrameworkCore; -using Company.WebApplication1.Data; -using Company.WebApplication1.Models; -#endif -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace Company.WebApplication1 -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - // This method gets called by the runtime. Use this method to add services to the container. - public void ConfigureServices(IServiceCollection services) - { -#if (IndividualLocalAuth) - services.AddDbContext(options => -#if (UseLocalDB) - options.UseSqlServer( - Configuration.GetConnectionString("DefaultConnection"))); -#else - options.UseSqlite( - Configuration.GetConnectionString("DefaultConnection"))); -#endif - - services.AddDatabaseDeveloperPageExceptionFilter(); - - services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) - .AddEntityFrameworkStores(); - - services.AddIdentityServer() - .AddApiAuthorization(); - - services.AddAuthentication() - .AddIdentityServerJwt(); -#endif - - services.AddControllersWithViews(); -#if (IndividualLocalAuth) - services.AddRazorPages(); -#endif - } - - // 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(); -#if (IndividualLocalAuth) - app.UseMigrationsEndPoint(); -#endif - } - else - { -#if (RequiresHttps) - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } - - app.UseHttpsRedirection(); -#else - } - -#endif - app.UseStaticFiles(); - app.UseRouting(); - -#if (IndividualLocalAuth) - app.UseAuthentication(); - app.UseIdentityServer(); -#endif -#if (!NoAuth) - app.UseAuthorization(); -#endif - app.UseEndpoints(endpoints => - { - endpoints.MapControllerRoute( - name: "default", - pattern: "{controller}/{action=Index}/{id?}"); -#if (IndividualLocalAuth) - endpoints.MapRazorPages(); -#endif - - endpoints.MapFallbackToFile("index.html"); - }); - } - } -} diff --git a/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/React-CSharp/Program.cs b/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/React-CSharp/Program.cs index 549d0b8bb8a1..b7ff9f83e146 100644 --- a/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/React-CSharp/Program.cs +++ b/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/React-CSharp/Program.cs @@ -1,26 +1,92 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +#if (IndividualLocalAuth) +using Microsoft.AspNetCore.Authentication; +#endif +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +#if (IndividualLocalAuth) +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity.UI; +#endif +#if (IndividualLocalAuth) +using Microsoft.EntityFrameworkCore; +#endif using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; +#if (IndividualLocalAuth) +using Company.WebApplication1.Data; +using Company.WebApplication1.Models; +#endif -namespace Company.WebApplication1 +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +#if (IndividualLocalAuth) +var connectionString = Configuration.GetConnectionString("DefaultConnection"); +builder.Services.AddDbContext(options => +#if (UseLocalDB) + options.UseSqlServer(connectionString)); +#else + options.UseSqlite(connectionString)); +#endif +builder.Services.AddDatabaseDeveloperPageExceptionFilter(); + +builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) + .AddEntityFrameworkStores(); + +builder.Services.AddIdentityServer() + .AddApiAuthorization(); + +builder.Services.AddAuthentication() + .AddIdentityServerJwt(); +#endif + +builder.Services.AddControllersWithViews(); +#if (IndividualLocalAuth) +builder.Services.AddRazorPages(); +#endif + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseDeveloperExceptionPage(); +#if (IndividualLocalAuth) + app.UseMigrationsEndPoint(); +#endif +} +else { - 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(); - }); - } +#if (RequiresHttps) + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); +} + +app.UseHttpsRedirection(); +#else } + +#endif +app.UseStaticFiles(); +app.UseRouting(); + +#if (IndividualLocalAuth) +app.UseAuthentication(); +app.UseIdentityServer(); +#endif +#if (!NoAuth) +app.UseAuthorization(); +#endif + +app.MapControllerRoute( + name: "default", + pattern: "{controller}/{action=Index}/{id?}"); +#if (IndividualLocalAuth) +app.MapRazorPages(); +#endif + +app.MapFallbackToFile("index.html");; + +app.Run(); diff --git a/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/React-CSharp/Startup.cs b/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/React-CSharp/Startup.cs deleted file mode 100644 index c29f37c468be..000000000000 --- a/src/ProjectTemplates/Web.Spa.ProjectTemplates/content/React-CSharp/Startup.cs +++ /dev/null @@ -1,109 +0,0 @@ -#if (IndividualLocalAuth) -using Microsoft.AspNetCore.Authentication; -#endif -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -#if (IndividualLocalAuth) -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Identity.UI; -#endif -#if (RequiresHttps) -using Microsoft.AspNetCore.HttpsPolicy; -#endif -#if (IndividualLocalAuth) -using Microsoft.EntityFrameworkCore; -using Company.WebApplication1.Data; -using Company.WebApplication1.Models; -#endif -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace Company.WebApplication1 -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - // This method gets called by the runtime. Use this method to add services to the container. - public void ConfigureServices(IServiceCollection services) - { -#if (IndividualLocalAuth) - services.AddDbContext(options => -#if (UseLocalDB) - options.UseSqlServer( - Configuration.GetConnectionString("DefaultConnection"))); -#else - options.UseSqlite( - Configuration.GetConnectionString("DefaultConnection"))); -#endif - - services.AddDatabaseDeveloperPageExceptionFilter(); - - services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) - .AddEntityFrameworkStores(); - - services.AddIdentityServer() - .AddApiAuthorization(); - - services.AddAuthentication() - .AddIdentityServerJwt(); -#endif - - services.AddControllersWithViews(); -#if (IndividualLocalAuth) - services.AddRazorPages(); -#endif - } - - // 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(); -#if (IndividualLocalAuth) - app.UseMigrationsEndPoint(); -#endif - } - else - { -#if (RequiresHttps) - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } - - app.UseHttpsRedirection(); -#else - } - -#endif - app.UseStaticFiles(); - app.UseRouting(); - -#if (IndividualLocalAuth) - app.UseAuthentication(); - app.UseIdentityServer(); -#endif -#if (!NoAuth) - app.UseAuthorization(); -#endif - app.UseEndpoints(endpoints => - { - endpoints.MapControllerRoute( - name: "default", - pattern: "{controller}/{action=Index}/{id?}"); -#if (IndividualLocalAuth) - endpoints.MapRazorPages(); -#endif - - endpoints.MapFallbackToFile("index.html"); - }); - } - } -} diff --git a/src/ProjectTemplates/test/template-baselines.json b/src/ProjectTemplates/test/template-baselines.json index 2ed1c8bb1827..a149fd5afd52 100644 --- a/src/ProjectTemplates/test/template-baselines.json +++ b/src/ProjectTemplates/test/template-baselines.json @@ -8,7 +8,6 @@ "appsettings.Development.json", "appsettings.json", "Program.cs", - "Startup.cs", "Areas/Identity/Pages/_ViewStart.cshtml", "Data/ApplicationDbContext.cs", "Data/Migrations/00000000000000_CreateIdentitySchema.cs", @@ -72,7 +71,6 @@ "appsettings.Development.json", "appsettings.json", "Program.cs", - "Startup.cs", "Pages/Error.cshtml", "Pages/Error.cshtml.cs", "Pages/Index.cshtml", @@ -130,7 +128,6 @@ "appsettings.Development.json", "appsettings.json", "Program.cs", - "Startup.cs", "Pages/Error.cshtml", "Pages/Error.cshtml.cs", "Pages/Index.cshtml", @@ -189,7 +186,6 @@ "appsettings.Development.json", "appsettings.json", "Program.cs", - "Startup.cs", "Pages/Error.cshtml", "Pages/Error.cshtml.cs", "Pages/Index.cshtml", @@ -248,7 +244,6 @@ "appsettings.Development.json", "appsettings.json", "Program.cs", - "Startup.cs", "Pages/Error.cshtml", "Pages/Error.cshtml.cs", "Pages/Index.cshtml", @@ -306,7 +301,6 @@ "appsettings.Development.json", "appsettings.json", "Program.cs", - "Startup.cs", "Pages/Error.cshtml", "Pages/Error.cshtml.cs", "Pages/Index.cshtml", @@ -395,7 +389,6 @@ "appsettings.Development.json", "appsettings.json", "Program.cs", - "Startup.cs", "WeatherForecast.cs", "Controllers/WeatherForecastController.cs", "Properties/launchSettings.json" @@ -409,7 +402,6 @@ "appsettings.Development.json", "appsettings.json", "Program.cs", - "Startup.cs", "WeatherForecast.cs", "Controllers/WeatherForecastController.cs", "Properties/launchSettings.json" @@ -423,7 +415,6 @@ "appsettings.Development.json", "appsettings.json", "Program.cs", - "Startup.cs", "WeatherForecast.cs", "Controllers/WeatherForecastController.cs", "Properties/launchSettings.json" @@ -437,7 +428,6 @@ "appsettings.Development.json", "appsettings.json", "Program.cs", - "Startup.cs", "WeatherForecast.cs", "Controllers/WeatherForecastController.cs", "Properties/launchSettings.json" @@ -467,7 +457,6 @@ "appsettings.Development.json", "appsettings.json", "Program.cs", - "Startup.cs", "Areas/Identity/Pages/_ViewStart.cshtml", "Controllers/HomeController.cs", "Data/ApplicationDbContext.cs", @@ -530,7 +519,6 @@ "appsettings.Development.json", "appsettings.json", "Program.cs", - "Startup.cs", "Controllers/HomeController.cs", "Models/ErrorViewModel.cs", "Properties/launchSettings.json", @@ -587,7 +575,6 @@ "appsettings.Development.json", "appsettings.json", "Program.cs", - "Startup.cs", "Controllers/HomeController.cs", "Models/ErrorViewModel.cs", "Properties/launchSettings.json", @@ -645,7 +632,6 @@ "appsettings.Development.json", "appsettings.json", "Program.cs", - "Startup.cs", "Controllers/HomeController.cs", "Models/ErrorViewModel.cs", "Properties/launchSettings.json", @@ -703,7 +689,6 @@ "appsettings.Development.json", "appsettings.json", "Program.cs", - "Startup.cs", "Controllers/HomeController.cs", "Models/ErrorViewModel.cs", "Properties/launchSettings.json", @@ -760,7 +745,6 @@ "appsettings.Development.json", "appsettings.json", "Program.cs", - "Startup.cs", "Controllers/HomeController.cs", "Models/ErrorViewModel.cs", "Properties/launchSettings.json", @@ -900,7 +884,6 @@ "appsettings.Development.json", "appsettings.json", "Program.cs", - "Startup.cs", "_Imports.razor", "Areas/Identity/Pages/Account/LogOut.cshtml", "Areas/Identity/Pages/Shared/_LoginPartial.cshtml", @@ -947,7 +930,6 @@ "appsettings.Development.json", "appsettings.json", "Program.cs", - "Startup.cs", "_Imports.razor", "Data/WeatherForecast.cs", "Data/WeatherForecastService.cs", @@ -987,7 +969,6 @@ "appsettings.Development.json", "appsettings.json", "Program.cs", - "Startup.cs", "_Imports.razor", "Data/WeatherForecast.cs", "Data/WeatherForecastService.cs", @@ -1027,7 +1008,6 @@ "appsettings.Development.json", "appsettings.json", "Program.cs", - "Startup.cs", "_Imports.razor", "Data/WeatherForecast.cs", "Data/WeatherForecastService.cs", @@ -1066,7 +1046,6 @@ "appsettings.Development.json", "appsettings.json", "Program.cs", - "Startup.cs", "_Imports.razor", "Data/WeatherForecast.cs", "Data/WeatherForecastService.cs", @@ -1106,7 +1085,6 @@ "appsettings.Development.json", "appsettings.json", "Program.cs", - "Startup.cs", "_Imports.razor", "Data/WeatherForecast.cs", "Data/WeatherForecastService.cs", @@ -1202,8 +1180,7 @@ ".gitignore", "appsettings.Development.json", "appsettings.json", - "Program.cs", - "Startup.cs" + "Program.cs" ] } }, @@ -1244,8 +1221,7 @@ ".gitignore", "appsettings.Development.json", "appsettings.json", - "Program.cs", - "Startup.cs" + "Program.cs" ] } }