From 10b63c06dbb940d49837e7d7ea8e9fd1b7d97533 Mon Sep 17 00:00:00 2001 From: Ryan Brandenburg Date: Thu, 17 Jan 2019 14:18:22 -0800 Subject: [PATCH] Fix Templates --- src/Templating/build/dependencies.props | 2 +- .../scripts/Run-Angular-Locally.ps1 | 2 +- .../scripts/Run-EmptyWeb-Locally.ps1 | 12 ++++++ src/Templating/scripts/Test-Template.ps1 | 3 +- src/Templating/scripts/web/Program.cs | 28 ++++++++++++++ src/Templating/scripts/web/Startup.cs | 37 +++++++++++++++++++ .../scripts/web/appsettings.Development.json | 9 +++++ src/Templating/scripts/web/appsettings.json | 8 ++++ src/Templating/scripts/web/web.csproj | 16 ++++++++ .../RazorClassLibrary-CSharp.csproj.in | 4 -- .../StarterWeb-CSharp.csproj.in | 1 - .../Angular-CSharp.csproj.in | 1 + ...oft.DotNet.Web.Spa.ProjectTemplates.csproj | 1 + .../React-CSharp.csproj.in | 1 + .../ReactRedux-CSharp.csproj.in | 1 + .../content/Angular-CSharp/Startup.cs | 3 +- .../content/React-CSharp/Startup.cs | 3 +- .../content/ReactRedux-CSharp/Startup.cs | 3 +- src/Templating/test/TemplateTests.props.in | 5 +++ .../test/Templates.Test/CdnScriptTagTests.cs | 9 ++--- .../Templates.Test/Helpers/AspNetProcess.cs | 3 +- .../Helpers/TemplateTestBase.cs | 5 --- .../RazorComponentsTemplateTest.cs | 5 ++- 23 files changed, 138 insertions(+), 24 deletions(-) create mode 100644 src/Templating/scripts/Run-EmptyWeb-Locally.ps1 create mode 100644 src/Templating/scripts/web/Program.cs create mode 100644 src/Templating/scripts/web/Startup.cs create mode 100644 src/Templating/scripts/web/appsettings.Development.json create mode 100644 src/Templating/scripts/web/appsettings.json create mode 100644 src/Templating/scripts/web/web.csproj diff --git a/src/Templating/build/dependencies.props b/src/Templating/build/dependencies.props index 3955eec3d7..0b89489c6e 100644 --- a/src/Templating/build/dependencies.props +++ b/src/Templating/build/dependencies.props @@ -4,7 +4,7 @@ $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - 3.0.0-preview-19065-0365 + 3.0.0-preview-19066-0374 3.0.0-preview-19059-0307 3.0.0-preview-19059-0307 3.0.0-preview-19064-0342 diff --git a/src/Templating/scripts/Run-Angular-Locally.ps1 b/src/Templating/scripts/Run-Angular-Locally.ps1 index 53f50b852f..b764ef88ad 100644 --- a/src/Templating/scripts/Run-Angular-Locally.ps1 +++ b/src/Templating/scripts/Run-Angular-Locally.ps1 @@ -9,4 +9,4 @@ $ErrorActionPreference = 'Stop' . $PSScriptRoot\Test-Template.ps1 -Test-Template "angular" "angular" "Microsoft.DotNet.Web.Spa.ProjectTemplates.3.0.0-alpha1.nupkg" $true +Test-Template "angular" "angular" "Microsoft.DotNet.Web.Spa.ProjectTemplates.3.0.0-preview-t000.nupkg" $true diff --git a/src/Templating/scripts/Run-EmptyWeb-Locally.ps1 b/src/Templating/scripts/Run-EmptyWeb-Locally.ps1 new file mode 100644 index 0000000000..a0125f658a --- /dev/null +++ b/src/Templating/scripts/Run-EmptyWeb-Locally.ps1 @@ -0,0 +1,12 @@ +#!/usr/bin/env pwsh +#requires -version 4 + +[CmdletBinding(PositionalBinding = $false)] +param() + +Set-StrictMode -Version 2 +$ErrorActionPreference = 'Stop' + +. $PSScriptRoot\Test-Template.ps1 + +Test-Template "web" "web" "Microsoft.DotNet.Web.ProjectTemplates.3.0.3.0.0-preview-t000.nupkg" $false diff --git a/src/Templating/scripts/Test-Template.ps1 b/src/Templating/scripts/Test-Template.ps1 index a575a6be80..b39cda25dc 100644 --- a/src/Templating/scripts/Test-Template.ps1 +++ b/src/Templating/scripts/Test-Template.ps1 @@ -1,6 +1,7 @@ function Test-Template($templateName, $templateArgs, $templateNupkg, $isSPA) { $tmpDir = "$PSScriptRoot/$templateName" Remove-Item -Path $tmpDir -Recurse -ErrorAction Ignore + dotnet pack Run-DotnetNew "--install", "$PSScriptRoot/../../../artifacts/Debug/packages/product/$templateNupkg" @@ -24,7 +25,7 @@ function Test-Template($templateName, $templateArgs, $templateNupkg, $isSPA) { ") $projContent | Set-Content $proj - + dotnet ef migrations add mvc dotnet publish --configuration Release dotnet bin\Release\netcoreapp3.0\publish\$templateName.dll } diff --git a/src/Templating/scripts/web/Program.cs b/src/Templating/scripts/web/Program.cs new file mode 100644 index 0000000000..323ed3d6ac --- /dev/null +++ b/src/Templating/scripts/web/Program.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace web +{ + 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(); + }); + } +} diff --git a/src/Templating/scripts/web/Startup.cs b/src/Templating/scripts/web/Startup.cs new file mode 100644 index 0000000000..0076dbb0a9 --- /dev/null +++ b/src/Templating/scripts/web/Startup.cs @@ -0,0 +1,37 @@ +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; + +namespace web +{ + 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, IHostingEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseRouting(routes => + { + routes.MapGet("/", async context => + { + await context.Response.WriteAsync("Hello World!"); + }); + }); + } + } +} diff --git a/src/Templating/scripts/web/appsettings.Development.json b/src/Templating/scripts/web/appsettings.Development.json new file mode 100644 index 0000000000..e203e9407e --- /dev/null +++ b/src/Templating/scripts/web/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/src/Templating/scripts/web/appsettings.json b/src/Templating/scripts/web/appsettings.json new file mode 100644 index 0000000000..def9159a7d --- /dev/null +++ b/src/Templating/scripts/web/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/src/Templating/scripts/web/web.csproj b/src/Templating/scripts/web/web.csproj new file mode 100644 index 0000000000..36ae57f998 --- /dev/null +++ b/src/Templating/scripts/web/web.csproj @@ -0,0 +1,16 @@ + + + + + + netcoreapp3.0 + + + + + + + + diff --git a/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/RazorClassLibrary-CSharp.csproj.in b/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/RazorClassLibrary-CSharp.csproj.in index c7a7314001..70c928a0fc 100644 --- a/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/RazorClassLibrary-CSharp.csproj.in +++ b/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/RazorClassLibrary-CSharp.csproj.in @@ -5,8 +5,4 @@ Company.RazorClassLibrary1 - - - - diff --git a/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/StarterWeb-CSharp.csproj.in b/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/StarterWeb-CSharp.csproj.in index 90f8ee0044..c6fbbb7bf0 100644 --- a/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/StarterWeb-CSharp.csproj.in +++ b/src/Templating/src/Microsoft.DotNet.Web.ProjectTemplates/StarterWeb-CSharp.csproj.in @@ -26,7 +26,6 @@ - diff --git a/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/Angular-CSharp.csproj.in b/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/Angular-CSharp.csproj.in index 3698833c2b..74e358bdf5 100644 --- a/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/Angular-CSharp.csproj.in +++ b/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/Angular-CSharp.csproj.in @@ -15,6 +15,7 @@ + diff --git a/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/Microsoft.DotNet.Web.Spa.ProjectTemplates.csproj b/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/Microsoft.DotNet.Web.Spa.ProjectTemplates.csproj index 19a07f29d5..6b82f0a5b9 100644 --- a/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/Microsoft.DotNet.Web.Spa.ProjectTemplates.csproj +++ b/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/Microsoft.DotNet.Web.Spa.ProjectTemplates.csproj @@ -23,6 +23,7 @@ MicrosoftAspNetCorePackageVersion=$(MicrosoftAspNetCorePackageVersion); MicrosoftAspNetCoreAppPackageVersion=$(MicrosoftAspNetCoreAppPackageVersion); + MicrosoftAspNetCoreMvcNewtonsoftJsonPackageVersion=$(MicrosoftAspNetCoreMvcNewtonsoftJsonPackageVersion); MicrosoftAspNetCoreSpaServicesExtensionsPackageVersion=$(MicrosoftAspNetCoreSpaServicesExtensionsPackageVersion); diff --git a/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/React-CSharp.csproj.in b/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/React-CSharp.csproj.in index 6bc19b7bd4..22d694c71a 100644 --- a/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/React-CSharp.csproj.in +++ b/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/React-CSharp.csproj.in @@ -12,6 +12,7 @@ + diff --git a/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/ReactRedux-CSharp.csproj.in b/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/ReactRedux-CSharp.csproj.in index 71a0a80686..eee417f529 100644 --- a/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/ReactRedux-CSharp.csproj.in +++ b/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/ReactRedux-CSharp.csproj.in @@ -12,6 +12,7 @@ + diff --git a/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/content/Angular-CSharp/Startup.cs b/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/content/Angular-CSharp/Startup.cs index 5758f368c1..c3fa490c3d 100644 --- a/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/content/Angular-CSharp/Startup.cs +++ b/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/content/Angular-CSharp/Startup.cs @@ -22,7 +22,8 @@ namespace Company.WebApplication1 // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddMvc(); + services.AddMvc() + .AddNewtonsoftJson(); ; // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => diff --git a/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/content/React-CSharp/Startup.cs b/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/content/React-CSharp/Startup.cs index 3009a15b7f..9b8508ddab 100644 --- a/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/content/React-CSharp/Startup.cs +++ b/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/content/React-CSharp/Startup.cs @@ -22,7 +22,8 @@ namespace Company.WebApplication1 // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddMvc(); + services.AddMvc() + .AddNewtonsoftJson(); // In production, the React files will be served from this directory services.AddSpaStaticFiles(configuration => diff --git a/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/content/ReactRedux-CSharp/Startup.cs b/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/content/ReactRedux-CSharp/Startup.cs index 3009a15b7f..9b8508ddab 100644 --- a/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/content/ReactRedux-CSharp/Startup.cs +++ b/src/Templating/src/Microsoft.DotNet.Web.Spa.ProjectTemplates/content/ReactRedux-CSharp/Startup.cs @@ -22,7 +22,8 @@ namespace Company.WebApplication1 // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddMvc(); + services.AddMvc() + .AddNewtonsoftJson(); // In production, the React files will be served from this directory services.AddSpaStaticFiles(configuration => diff --git a/src/Templating/test/TemplateTests.props.in b/src/Templating/test/TemplateTests.props.in index 89994217b7..9353422afa 100644 --- a/src/Templating/test/TemplateTests.props.in +++ b/src/Templating/test/TemplateTests.props.in @@ -4,6 +4,7 @@ ${RestoreSources} ${RuntimeFrameworkVersion} ${MicrosoftNETSdkRazorPackageVersion} + AspNetCoreModuleV2 @@ -13,4 +14,8 @@ LatestRuntimeFrameworkVersion="${MicrosoftAspNetCoreAppPackageVersion}" TargetingPackVersion="${MicrosoftAspNetCoreAppPackageVersion}" /> + + + + diff --git a/src/Templating/test/Templates.Test/CdnScriptTagTests.cs b/src/Templating/test/Templates.Test/CdnScriptTagTests.cs index 4a4ebc15f0..e14a54b071 100644 --- a/src/Templating/test/Templates.Test/CdnScriptTagTests.cs +++ b/src/Templating/test/Templates.Test/CdnScriptTagTests.cs @@ -13,6 +13,7 @@ using System.Linq; using System.Net.Http; using System.Security.Cryptography; using System.Threading.Tasks; +using Templates.Test.Helpers; using Xunit; using Xunit.Abstractions; @@ -22,16 +23,12 @@ namespace Templates.Test { private readonly ITestOutputHelper _output; private readonly HttpClient _httpClient; - private static readonly string _solutionDir; - private static readonly string _artifactsDir; private static List _scriptTags; private static List _linkTags; static CdnScriptTagTests() { - _solutionDir = GetSolutionDir(); - _artifactsDir = Path.Combine(_solutionDir, "artifacts", "build"); - var packages = Directory.GetFiles(_artifactsDir, "*.nupkg"); + var packages = MondoHelpers.GetNupkgFiles(); _scriptTags = new List(); _linkTags = new List(); @@ -164,7 +161,7 @@ namespace Templates.Test private static string GetFileContentFromArchive(ScriptTag scriptTag, string relativeFilePath) { - var file = Path.Combine(_artifactsDir, scriptTag.FileName); + var file = MondoHelpers.GetNupkgFiles().Single(f => f.EndsWith(scriptTag.FileName)); using (var zip = new ZipArchive(File.OpenRead(file), ZipArchiveMode.Read, leaveOpen: false)) { var entry = zip.Entries diff --git a/src/Templating/test/Templates.Test/Helpers/AspNetProcess.cs b/src/Templating/test/Templates.Test/Helpers/AspNetProcess.cs index 570dcd4b6c..e26b75759e 100644 --- a/src/Templating/test/Templates.Test/Helpers/AspNetProcess.cs +++ b/src/Templating/test/Templates.Test/Helpers/AspNetProcess.cs @@ -119,8 +119,9 @@ namespace Templates.Test.Helpers var listeningMessage = _process .OutputLinesAsEnumerable .Where(line => line != null) - .FirstOrDefault(line => line.StartsWith(ListeningMessagePrefix, StringComparison.Ordinal)); + .FirstOrDefault(line => line.Trim().StartsWith(ListeningMessagePrefix, StringComparison.Ordinal)); Assert.True(!string.IsNullOrEmpty(listeningMessage), $"ASP.NET process exited without listening for requests.\nOutput: { _process.Output }\nError: { _process.Error }"); + listeningMessage = listeningMessage.Trim(); // Verify we have a valid URL to make requests to var listeningUrlString = listeningMessage.Substring(ListeningMessagePrefix.Length); diff --git a/src/Templating/test/Templates.Test/Helpers/TemplateTestBase.cs b/src/Templating/test/Templates.Test/Helpers/TemplateTestBase.cs index 4ef1779deb..5aee2f0af9 100644 --- a/src/Templating/test/Templates.Test/Helpers/TemplateTestBase.cs +++ b/src/Templating/test/Templates.Test/Helpers/TemplateTestBase.cs @@ -56,11 +56,6 @@ $@" var directoryBuildTargetsContent = $@" - - - - - "; File.WriteAllText(Path.Combine(TemplateOutputDir, "Directory.Build.targets"), directoryBuildTargetsContent); diff --git a/src/Templating/test/Templates.Test/RazorComponentsTemplateTest.cs b/src/Templating/test/Templates.Test/RazorComponentsTemplateTest.cs index 34a52e2b3c..220361e2d6 100644 --- a/src/Templating/test/Templates.Test/RazorComponentsTemplateTest.cs +++ b/src/Templating/test/Templates.Test/RazorComponentsTemplateTest.cs @@ -29,7 +29,10 @@ namespace Templates.Test ""); File.WriteAllText( Path.Combine(TemplateOutputDir, "Directory.Build.targets"), - ""); + @" + + +"); // Run the "server" project ProjectName += ".Server";