From 25e5a4ffabc2cdd5fe437c648fd152933a2aeb40 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 19 Mar 2019 16:33:26 -0700 Subject: [PATCH] Infer Razor Configuration \ RazorLangVersion based on TFM (dotnet/aspnetcore-tooling#343) * Infer Razor Configuration \ RazorLangVersion based on TFM Fixes https://github.com/aspnet/AspNetCore/issues/6392 \n\nCommit migrated from https://github.com/dotnet/aspnetcore-tooling/commit/cfee40a19eb42f0c02365104c0a460e1025ad84c --- .../src/RazorLanguageVersion.cs | 1 + .../Microsoft.NET.Sdk.Razor.Component.targets | 8 + ...rosoft.NET.Sdk.Razor.Configuration.targets | 31 ++-- ...Microsoft.NET.Sdk.Razor.DesignTime.targets | 3 +- .../Sdk.Razor.CurrentVersion.targets | 116 +++++++++++--- .../test/IntegrationTests/Assert.cs | 66 +++++++- .../IntegrationTests/BuildIntegrationTest.cs | 31 +--- .../BuildIntegrationTest21.cs | 51 +----- .../BuildIntegrationTest22.cs | 31 +--- .../BuildIntegrationTestLegacy.cs | 145 ++++++++++++++++++ .../BuildIntrospectionTest.cs | 59 +++++++ .../BuildWithComponentsIntegrationTest.cs | 50 ++++++ .../InitializeTestProjectAttribute.cs | 6 +- .../IntegrationTests/PackIntegrationTest.cs | 48 +++--- .../PublishIntegrationTest.cs | 27 ---- .../ComponentBase.cs | 3 + .../AppWithP2PReference.csproj | 11 +- .../ClassLibrary/ClassLibrary.csproj | 20 ++- .../ClassLibrary2/ClassLibrary2.csproj | 13 +- .../ComponentApp/ComponentApp.csproj | 35 +++++ .../ComponentApp/Components/App.razor | 5 + .../Components/Pages/Counter.razor | 16 ++ .../Components/Pages/FetchData.razor | 45 ++++++ .../ComponentApp/Components/Pages/Index.razor | 5 + .../Components/Pages/_ViewImports.cshtml | 1 + .../Components/Shared/MainLayout.razor | 12 ++ .../Components/Shared/NavMenu.razor | 37 +++++ .../Components/_ViewImports.cshtml | 1 + .../test/testassets/ComponentApp/Program.cs | 10 ++ .../ComponentApp/Services/WeatherForecast.cs | 15 ++ .../Services/WeatherForecastService.cs | 25 +++ .../ComponentLibrary/ComponentLibrary.csproj | 7 - .../LargeProject/LargeProject.csproj | 18 ++- .../MvcWithComponents.csproj | 14 +- .../RazorTest.Introspection.targets | 5 + .../RestoreTestProjects.csproj | 1 + .../testassets/SimpleMvc/SimpleMvc.csproj | 16 +- .../SimpleMvcFSharp/SimpleMvcFSharp.fsproj | 13 +- .../testassets/SimplePages/SimplePages.csproj | 16 +- 39 files changed, 779 insertions(+), 238 deletions(-) create mode 100644 src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTestLegacy.cs create mode 100644 src/Razor/test/testassets/ComponentApp/ComponentApp.csproj create mode 100644 src/Razor/test/testassets/ComponentApp/Components/App.razor create mode 100644 src/Razor/test/testassets/ComponentApp/Components/Pages/Counter.razor create mode 100644 src/Razor/test/testassets/ComponentApp/Components/Pages/FetchData.razor create mode 100644 src/Razor/test/testassets/ComponentApp/Components/Pages/Index.razor create mode 100644 src/Razor/test/testassets/ComponentApp/Components/Pages/_ViewImports.cshtml create mode 100644 src/Razor/test/testassets/ComponentApp/Components/Shared/MainLayout.razor create mode 100644 src/Razor/test/testassets/ComponentApp/Components/Shared/NavMenu.razor create mode 100644 src/Razor/test/testassets/ComponentApp/Components/_ViewImports.cshtml create mode 100644 src/Razor/test/testassets/ComponentApp/Program.cs create mode 100644 src/Razor/test/testassets/ComponentApp/Services/WeatherForecast.cs create mode 100644 src/Razor/test/testassets/ComponentApp/Services/WeatherForecastService.cs diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorLanguageVersion.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorLanguageVersion.cs index 5d34d258f8..9fed605e2f 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorLanguageVersion.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorLanguageVersion.cs @@ -6,6 +6,7 @@ using System.Diagnostics; namespace Microsoft.AspNetCore.Razor.Language { + // Note: RazorSDK is aware of version monikers such as "latest", and "experimental". Update it if we introduce new monikers. [DebuggerDisplay("{" + nameof(DebuggerToString) + "(),nq}")] public sealed class RazorLanguageVersion : IEquatable, IComparable { diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Component.targets b/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Component.targets index 6061d8cbc8..4d5f644760 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Component.targets +++ b/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Component.targets @@ -12,6 +12,14 @@ Copyright (c) .NET Foundation. All rights reserved. + + + + $(RazorComponentGenerateDependsOn); + RazorComponentGenerateCore + + + <_RazorComponentInputHash> diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Configuration.targets b/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Configuration.targets index f904665aee..348888a839 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Configuration.targets +++ b/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Configuration.targets @@ -11,10 +11,6 @@ Copyright (c) .NET Foundation. All rights reserved. --> - - <_TargetingNETCoreApp30OrLater Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(_TargetFrameworkVersionWithoutV)' > '2.9'">true - - + + true + + + + - $(_TargetingNETCoreApp30OrLater) + true - $(_TargetingNETCoreApp30OrLater) + true Microsoft.AspNetCore.Mvc.ApplicationParts.CompiledRazorAssemblyApplicationPartFactory, Microsoft.AspNetCore.Mvc.Razor - - - true - - - - 3.0 - MVC-3.0 + MVC-3.0 + Default @@ -69,7 +67,8 @@ Copyright (c) .NET Foundation. All rights reserved. it here. The IDE is hardcoded to inject 2.0 support when needed. The settings flowing through MSBuild should reflect the project's runtime. --> - + + MVC-3.0;$(CustomRazorExtension) diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.DesignTime.targets b/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.DesignTime.targets index 7238792f50..330a192ea3 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.DesignTime.targets +++ b/src/Razor/Microsoft.NET.Sdk.Razor/src/build/netstandard2.0/Microsoft.NET.Sdk.Razor.DesignTime.targets @@ -26,8 +26,7 @@ Copyright (c) .NET Foundation. All rights reserved. Defines the ability to understand the configuration for the Razor language service provided by the runtime/toolset packages. Introduced in 2.1 --> - - + - + + <_TargetFrameworkVersionWithoutV>$(TargetFrameworkVersion.TrimStart('vV')) - <_EnableAllInclusiveRazorSdk Condition="'$(_EnableInclusiveRazorSdk)' == '' AND '$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(_TargetFrameworkVersionWithoutV)' > '2.9'">true + + + 3.0 + + + 2.1 + + + <_Targeting30OrNewerRazorLangVersion Condition=" + '$(RazorLangVersion)' == 'Latest' OR + '$(RazorLangVersion)' == 'Experimental' OR + ('$(RazorLangVersion)' != '' AND '$(RazorLangVersion)' > '2.9')">true + + + + + + <_IsTargetingRazor2X Condition="'$(IsRazorCompilerReferenced)'=='true'">true - .Views + .Views .Razor @@ -216,8 +246,16 @@ Copyright (c) .NET Foundation. All rights reserved. <_RazorDebugSymbolsProduced Condition="'$(DebugType)'=='embedded'">false - - + + + RazorSdk + + + PrecompilationTool @@ -228,7 +266,7 @@ Copyright (c) .NET Foundation. All rights reserved. $(RazorCompileToolset) - PrecompilationTool + PrecompilationTool true @@ -281,12 +319,12 @@ Copyright (c) .NET Foundation. All rights reserved. Condition="'$(IsRazorCompilerReferenced)' == 'true' AND '$(RazorCodeGenerationTargetsPath)' != '' AND Exists('$(RazorCodeGenerationTargetsPath)')" /> - + - - + + - + @@ -319,15 +357,28 @@ Copyright (c) .NET Foundation. All rights reserved. Computes the applicable @(ResolvedRazorConfiguration) and @(ResolvedRazorExtension) items that match the project's configuration. --> - - - + + - + + + + + + @@ -729,9 +780,34 @@ Copyright (c) .NET Foundation. All rights reserved. + transitive reference to 'Microsoft.AspNetCore.Razor.Design' and references required to compile Razor files are obtained by adding a PackageReference + for 'Microsoft.AspNetCore.Mvc' in your project. For more information, see https://go.microsoft.com/fwlink/?linkid=868374." /> + + + + + + + + + diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/Assert.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/Assert.cs index f2ee9393f6..deb92de412 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/Assert.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/Assert.cs @@ -18,8 +18,9 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests // Matches `{filename}: error {code}: {message} [{project}] // See https://stackoverflow.com/questions/3441452/msbuild-and-ignorestandarderrorwarningformat/5180353#5180353 private static readonly Regex ErrorRegex = new Regex(@"^(?'location'.+): error (?'errorcode'[A-Z0-9]+): (?'message'.+) \[(?'project'.+)\]$"); + private static readonly Regex WarningRegex = new Regex(@"^(?'location'.+): warning (?'errorcode'[A-Z0-9]+): (?'message'.+) \[(?'project'.+)\]$"); - public static void BuildPassed(MSBuildResult result) + public static void BuildPassed(MSBuildResult result, bool allowWarnings = false) { if (result == null) { @@ -30,6 +31,12 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests { throw new BuildFailedException(result); } + + var buildWarnings = GetBuildWarnings(result).Select(m => m.line); + if (!allowWarnings && buildWarnings.Any()) + { + throw new BuildWarningsException(result, buildWarnings); + } } public static void BuildError(MSBuildResult result, string errorCode, string location = null) @@ -65,6 +72,47 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests throw new BuildErrorMissingException(result, errorCode, location); } + public static void BuildWarning(MSBuildResult result, string errorCode, string location = null) + { + if (result == null) + { + throw new ArgumentNullException(nameof(result)); + } + + // We don't really need to search line by line, I'm doing this so that it's possible/easy to debug. + foreach (var (_, match) in GetBuildWarnings(result)) + { + if (match.Groups["errorcode"].Value != errorCode) + { + continue; + } + + if (location != null && match.Groups["location"].Value.Trim() != location) + { + continue; + } + + // This is a match + return; + } + + throw new BuildErrorMissingException(result, errorCode, location); + } + + private static IEnumerable<(string line, Match match)> GetBuildWarnings(MSBuildResult result) + { + var lines = result.Output.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); + for (var i = 0; i < lines.Length; i++) + { + var line = lines[i]; + var match = WarningRegex.Match(line); + if (match.Success) + { + yield return (line, match); + } + } + } + public static void BuildFailed(MSBuildResult result) { if (result == null) @@ -440,6 +488,9 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests message.AppendLine(); message.AppendLine(); message.Append(Result.Output); + message.AppendLine(); + message.Append("Exit Code:"); + message.Append(Result.ExitCode); return message.ToString(); } } @@ -479,6 +530,19 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests protected override string Heading => "Build failed."; } + private class BuildWarningsException : MSBuildXunitException + { + public BuildWarningsException(MSBuildResult result, IEnumerable warnings) + : base(result) + { + Warnings = warnings.ToList(); + } + + public List Warnings { get; } + + protected override string Heading => "Build contains unexpected warnings: " + string.Join(Environment.NewLine, Warnings); + } + private class BuildPassedException : MSBuildXunitException { public BuildPassedException(MSBuildResult result) diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest.cs index 0df7da2139..ee8c87d889 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest.cs @@ -370,19 +370,6 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests Assert.FileDoesNotContain(result, razorTargetAssemblyInfo, "[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ProvideApplicationPartFactoryAttribute"); } - [Fact] - [InitializeTestProject("SimpleMvc")] - public async Task Build_DoesNotAddRelatedAssemblyPart_IfToolSetIsNotRazorSdk() - { - var razorAssemblyInfo = Path.Combine(IntermediateOutputPath, "SimpleMvc.RazorAssemblyInfo.cs"); - var result = await DotnetMSBuild("Build", "/p:RazorCompileToolSet=MvcPrecompilation"); - - Assert.BuildPassed(result); - - Assert.FileDoesNotExist(result, razorAssemblyInfo); - Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.RazorTargetAssemblyInfo.cs"); - } - [Fact] [InitializeTestProject("SimpleMvc")] public async Task Build_DoesNotAddRelatedAssemblyPart_IfViewCompilationIsDisabled() @@ -661,19 +648,15 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests } [Fact] - [InitializeTestProject("ComponentLibrary")] - public async Task Building_NetstandardComponentLibrary() + [InitializeTestProject("SimpleMvc")] + public async Task Build_Mvc_WithoutAddRazorSupportForMvc() { - TargetFramework = "netstandard2.0"; + var result = await DotnetMSBuild( + "Build", + "/p:AddRazorSupportForMvc=false", + suppressBuildServer: true); - // Build - var result = await DotnetMSBuild("Build"); - - Assert.BuildPassed(result); - Assert.FileExists(result, OutputPath, "ComponentLibrary.dll"); - Assert.FileExists(result, OutputPath, "ComponentLibrary.pdb"); - Assert.FileDoesNotExist(result, OutputPath, "ComponentLibrary.Views.dll"); - Assert.FileDoesNotExist(result, OutputPath, "ComponentLibrary.Views.pdb"); + Assert.BuildWarning(result, "RAZORSDK1004"); } private static DependencyContext ReadDependencyContext(string depsFilePath) diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest21.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest21.cs index 061399ddfc..a513f29aa7 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest21.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest21.cs @@ -1,61 +1,16 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.IO; -using System.Threading.Tasks; -using Xunit; - namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests { - public class BuildIntegrationTest21 : MSBuildIntegrationTestBase, IClassFixture + public class BuildIntegrationTest21 : BuildIntegrationTestLegacy { public BuildIntegrationTest21(LegacyBuildServerTestFixture buildServer) : base(buildServer) { } - [Fact] - [InitializeTestProject("SimpleMvc21")] - public async Task Building_NETCoreApp21TargetingProject() - { - TargetFramework = "netcoreapp2.1"; - - // Build - var result = await DotnetMSBuild("Build"); - - Assert.BuildPassed(result); - Assert.FileExists(result, OutputPath, "SimpleMvc21.dll"); - Assert.FileExists(result, OutputPath, "SimpleMvc21.pdb"); - Assert.FileExists(result, OutputPath, "SimpleMvc21.Views.dll"); - Assert.FileExists(result, OutputPath, "SimpleMvc21.Views.pdb"); - - // Verify RazorTagHelper works - Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc21.TagHelpers.input.cache"); - Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc21.TagHelpers.output.cache"); - Assert.FileContains( - result, - Path.Combine(IntermediateOutputPath, "SimpleMvc21.TagHelpers.output.cache"), - @"""Name"":""SimpleMvc.SimpleTagHelper"""); - } - - [Fact] - [InitializeTestProject("SimpleMvc21")] - public async Task Publish_NETCoreApp21TargetingProject() - { - TargetFramework = "netcoreapp2.1"; - - var result = await DotnetMSBuild("Publish"); - - Assert.BuildPassed(result); - - Assert.FileExists(result, PublishOutputPath, "SimpleMvc21.dll"); - Assert.FileExists(result, PublishOutputPath, "SimpleMvc21.pdb"); - Assert.FileExists(result, PublishOutputPath, "SimpleMvc21.Views.dll"); - Assert.FileExists(result, PublishOutputPath, "SimpleMvc21.Views.pdb"); - - // By default refs and .cshtml files will not be copied on publish - Assert.FileCountEquals(result, 0, Path.Combine(PublishOutputPath, "refs"), "*.dll"); - Assert.FileCountEquals(result, 0, Path.Combine(PublishOutputPath, "Views"), "*.cshtml"); - } + public override string TestProjectName => "SimpleMvc21"; + public override string TargetFramework => "netcoreapp2.1"; } } diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest22.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest22.cs index 00a4bdc1dc..d857955351 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest22.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTest22.cs @@ -1,41 +1,16 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.IO; -using System.Threading.Tasks; -using Xunit; - namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests { - public class BuildIntegrationTest22 : MSBuildIntegrationTestBase, IClassFixture + public class BuildIntegrationTest22 : BuildIntegrationTestLegacy { public BuildIntegrationTest22(LegacyBuildServerTestFixture buildServer) : base(buildServer) { } - [Fact] - [InitializeTestProject("SimpleMvc22")] - public async Task Building_NETCoreApp22TargetingProject() - { - TargetFramework = "netcoreapp2.2"; - - // Build - var result = await DotnetMSBuild("Build"); - - Assert.BuildPassed(result); - Assert.FileExists(result, OutputPath, "SimpleMvc22.dll"); - Assert.FileExists(result, OutputPath, "SimpleMvc22.pdb"); - Assert.FileExists(result, OutputPath, "SimpleMvc22.Views.dll"); - Assert.FileExists(result, OutputPath, "SimpleMvc22.Views.pdb"); - - // Verify RazorTagHelper works - Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc22.TagHelpers.input.cache"); - Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc22.TagHelpers.output.cache"); - Assert.FileContains( - result, - Path.Combine(IntermediateOutputPath, "SimpleMvc22.TagHelpers.output.cache"), - @"""Name"":""SimpleMvc.SimpleTagHelper"""); - } + public override string TestProjectName => "SimpleMvc22"; + public override string TargetFramework => "netcoreapp2.2"; } } diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTestLegacy.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTestLegacy.cs new file mode 100644 index 0000000000..460cd6e117 --- /dev/null +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntegrationTestLegacy.cs @@ -0,0 +1,145 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.IO; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests +{ + public abstract class BuildIntegrationTestLegacy : + MSBuildIntegrationTestBase, + IClassFixture + { + public abstract string TestProjectName { get; } + public abstract new string TargetFramework { get; } + + public BuildIntegrationTestLegacy(LegacyBuildServerTestFixture buildServer) + : base(buildServer) + { + } + + protected IDisposable CreateTestProject() + { + Project = ProjectDirectory.Create(TestProjectName, TestProjectName, string.Empty, Array.Empty(), "C#"); + MSBuildIntegrationTestBase.TargetFramework = TargetFramework; + + return new Disposable(); + } + + [Fact] + public async Task Building_Project() + { + using (CreateTestProject()) + { + // Build + var result = await DotnetMSBuild("Build"); + + Assert.BuildPassed(result); + Assert.FileExists(result, OutputPath, $"{TestProjectName}.dll"); + Assert.FileExists(result, OutputPath, $"{TestProjectName}.pdb"); + Assert.FileExists(result, OutputPath, $"{TestProjectName}.Views.dll"); + Assert.FileExists(result, OutputPath, $"{TestProjectName}.Views.pdb"); + + // Verify RazorTagHelper works + Assert.FileExists(result, IntermediateOutputPath, $"{TestProjectName}.TagHelpers.input.cache"); + Assert.FileExists(result, IntermediateOutputPath, $"{TestProjectName}.TagHelpers.output.cache"); + Assert.FileContains( + result, + Path.Combine(IntermediateOutputPath, $"{TestProjectName}.TagHelpers.output.cache"), + @"""Name"":""SimpleMvc.SimpleTagHelper"""); + } + } + + [Fact] + public async Task Publish_Project() + { + using (CreateTestProject()) + { + var result = await DotnetMSBuild("Publish"); + + Assert.BuildPassed(result); + + Assert.FileExists(result, PublishOutputPath, $"{TestProjectName}.dll"); + Assert.FileExists(result, PublishOutputPath, $"{TestProjectName}.pdb"); + Assert.FileExists(result, PublishOutputPath, $"{TestProjectName}.Views.dll"); + Assert.FileExists(result, PublishOutputPath, $"{TestProjectName}.Views.pdb"); + + // By default refs and .cshtml files will not be copied on publish + Assert.FileCountEquals(result, 0, Path.Combine(PublishOutputPath, "refs"), "*.dll"); + Assert.FileCountEquals(result, 0, Path.Combine(PublishOutputPath, "Views"), "*.cshtml"); + } + } + + [Fact] + public async Task Publish_NoopsWithMvcRazorCompileOnPublish_False() + { + using (CreateTestProject()) + { + var result = await DotnetMSBuild("Publish", "/p:MvcRazorCompileOnPublish=false"); + + Assert.BuildPassed(result); + + // Everything we do should noop - including building the app. + Assert.FileExists(result, PublishOutputPath, $"{TestProjectName}.dll"); + Assert.FileExists(result, PublishOutputPath, $"{TestProjectName}.pdb"); + Assert.FileDoesNotExist(result, PublishOutputPath, $"{TestProjectName}.Views.dll"); + Assert.FileDoesNotExist(result, PublishOutputPath, $"{TestProjectName}.Views.pdb"); + } + } + + [Fact] // This will use the old precompilation tool, RazorSDK shouldn't get involved. + public async Task Build_WithMvcRazorCompileOnPublish_Noops() + { + using (CreateTestProject()) + { + var result = await DotnetMSBuild("Build", "/p:MvcRazorCompileOnPublish=true"); + + Assert.BuildPassed(result); + + Assert.FileExists(result, IntermediateOutputPath, $"{TestProjectName}.dll"); + Assert.FileExists(result, IntermediateOutputPath, $"{TestProjectName}.dll"); + Assert.FileDoesNotExist(result, IntermediateOutputPath, $"{TestProjectName}.Views.dll"); + Assert.FileDoesNotExist(result, IntermediateOutputPath, $"{TestProjectName}.Views.pdb"); + } + } + + [Fact] + public async Task Build_DoesNotAddRelatedAssemblyPart_IfToolSetIsNotRazorSdk() + { + using (CreateTestProject()) + { + var razorAssemblyInfo = Path.Combine(IntermediateOutputPath, $"{TestProjectName}.RazorAssemblyInfo.cs"); + var result = await DotnetMSBuild("Build", "/p:RazorCompileToolSet=MvcPrecompilation"); + + Assert.BuildPassed(result); + + Assert.FileDoesNotExist(result, razorAssemblyInfo); + Assert.FileDoesNotExist(result, IntermediateOutputPath, $"{TestProjectName}.RazorTargetAssemblyInfo.cs"); + } + } + + [Fact] + public async Task Build_DoesNotPrintsWarnings_IfProjectFileContainsRazorFiles() + { + using (CreateTestProject()) + { + File.WriteAllText(Path.Combine(Project.DirectoryPath, "Index.razor"), "Hello world"); + var result = await DotnetMSBuild("Build"); + + Assert.BuildPassed(result); + Assert.DoesNotContain("RAZORSDK1005", result.Output); + } + } + + private class Disposable : IDisposable + { + public void Dispose() + { + Project.Dispose(); + Project = null; + } + } + } +} diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntrospectionTest.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntrospectionTest.cs index 669a014e81..986fecd991 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntrospectionTest.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildIntrospectionTest.cs @@ -94,5 +94,64 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests Assert.BuildOutputDoesNotContainLine(result, "AllItemsFullPathWithTargetPath: ClassLibrary.Views.dll"); Assert.BuildOutputDoesNotContainLine(result, "AllItemsFullPathWithTargetPath: ClassLibrary.Views.pdb"); } + + [Fact] + [InitializeTestProject("SimpleMvc")] + public async Task RazorSdk_ResolvesRazorLangVersionTo30ForNetCoreApp30Projects() + { + var result = await DotnetMSBuild("ResolveRazorConfiguration", "/t:_IntrospectResolvedConfiguration"); + + Assert.BuildPassed(result); + Assert.BuildOutputContainsLine(result, "RazorLangVersion: 3.0"); + Assert.BuildOutputContainsLine(result, "ResolvedRazorConfiguration: MVC-3.0"); + } + + [Fact] + [InitializeTestProject("ComponentLibrary")] + public async Task RazorSdk_ResolvesRazorLangVersionFromValueSpecified() + { + var result = await DotnetMSBuild("ResolveRazorConfiguration", "/t:_IntrospectResolvedConfiguration"); + + Assert.BuildPassed(result); + Assert.BuildOutputContainsLine(result, "RazorLangVersion: 3.0"); + Assert.BuildOutputContainsLine(result, "ResolvedRazorConfiguration: Default"); + } + + [Fact] + [InitializeTestProject("ComponentLibrary")] + public async Task RazorSdk_ResolvesRazorLangVersionTo21WhenUnspecified() + { + // This is equivalent to not specifying a value for RazorLangVersion + AddProjectFileContent(""); + + var result = await DotnetMSBuild("ResolveRazorConfiguration", "/t:_IntrospectResolvedConfiguration"); + + Assert.BuildPassed(result, allowWarnings: true); + Assert.BuildOutputContainsLine(result, "RazorLangVersion: 2.1"); + // BuildOutputContainsLine matches entire lines, so it's fine to Assert the following. + Assert.BuildOutputContainsLine(result, "ResolvedRazorConfiguration:"); + } + + [Fact] + [InitializeTestProject("ComponentLibrary")] + public async Task RazorSdk_WithRazorLangVersionLatest() + { + var result = await DotnetMSBuild("ResolveRazorConfiguration", "/t:_IntrospectResolvedConfiguration /p:RazorLangVersion=Latest"); + + Assert.BuildPassed(result); + Assert.BuildOutputContainsLine(result, "RazorLangVersion: Latest"); + Assert.BuildOutputContainsLine(result, "ResolvedRazorConfiguration: Default"); + } + + [Fact] + [InitializeTestProject("SimpleMvc")] + public async Task RazorSdk_ResolvesRazorConfigurationToMvc30() + { + var result = await DotnetMSBuild("ResolveRazorConfiguration", "/t:_IntrospectResolvedConfiguration"); + + Assert.BuildPassed(result); + Assert.BuildOutputContainsLine(result, "RazorLangVersion: 3.0"); + Assert.BuildOutputContainsLine(result, "ResolvedRazorConfiguration: MVC-3.0"); + } } } diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildWithComponentsIntegrationTest.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildWithComponentsIntegrationTest.cs index 847fccafc3..1503141b88 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildWithComponentsIntegrationTest.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildWithComponentsIntegrationTest.cs @@ -24,6 +24,56 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests [InitializeTestProject("MvcWithComponents")] public Task Build_Components_WithDesktopMSBuild_Works() => Build_ComponentsWorks(MSBuildProcessKind.Desktop); + [Fact] + [InitializeTestProject("ComponentApp")] + public async Task Build_DoesNotProduceMvcArtifacts_IfAddRazorSupportForMvcIsFalse() + { + var result = await DotnetMSBuild("Build"); + + Assert.BuildPassed(result); + + Assert.FileExists(result, OutputPath, "ComponentApp.dll"); + Assert.FileExists(result, OutputPath, "ComponentApp.pdb"); + + // Verify component compilation succeeded + Assert.AssemblyContainsType(result, Path.Combine(OutputPath, "ComponentApp.dll"), "ComponentApp.Components.Pages.Counter"); + + // Verify MVC artifacts do not appear in the output. + Assert.FileDoesNotExist(result, OutputPath, "ComponentApp.Views.dll"); + Assert.FileDoesNotExist(result, OutputPath, "ComponentApp.Views.pdb"); + Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.RazorAssemblyInfo.cs"); + Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.RazorTargetAssemblyInfo.cs"); + } + + [Fact] + [InitializeTestProject("ComponentLibrary")] + public async Task Build_WithoutRazorLangVersion_ProducesWarning() + { + TargetFramework = "netstandard2.0"; + var result = await DotnetMSBuild("Build", "/p:RazorLangVersion="); + + Assert.BuildPassed(result, allowWarnings: true); + + // We should see a build warning + Assert.BuildWarning(result, "RAZORSDK1005"); + } + + [Fact] + [InitializeTestProject("ComponentLibrary")] + public async Task Building_NetstandardComponentLibrary() + { + TargetFramework = "netstandard2.0"; + + // Build + var result = await DotnetMSBuild("Build"); + + Assert.BuildPassed(result); + Assert.FileExists(result, OutputPath, "ComponentLibrary.dll"); + Assert.FileExists(result, OutputPath, "ComponentLibrary.pdb"); + Assert.FileDoesNotExist(result, OutputPath, "ComponentLibrary.Views.dll"); + Assert.FileDoesNotExist(result, OutputPath, "ComponentLibrary.Views.pdb"); + } + private async Task Build_ComponentsWorks(MSBuildProcessKind msBuildProcessKind) { var result = await DotnetMSBuild("Build", msBuildProcessKind: msBuildProcessKind); diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/InitializeTestProjectAttribute.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/InitializeTestProjectAttribute.cs index f04a14c449..5dc1651e47 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/InitializeTestProjectAttribute.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/InitializeTestProjectAttribute.cs @@ -37,7 +37,11 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests } MSBuildIntegrationTestBase.Project = ProjectDirectory.Create(_originalProjectName, _testProjectName, _baseDirectory, _additionalProjects, _language); - MSBuildIntegrationTestBase.TargetFramework = _originalProjectName.StartsWith("ClassLibrary") ? "netstandard2.0" : "netcoreapp3.0"; +#if NETCOREAPP3_0 + MSBuildIntegrationTestBase.TargetFramework = "netcoreapp3.0"; +#else +#error Target frameworks need to be updated +#endif } public override void After(MethodInfo methodUnderTest) diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/PackIntegrationTest.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/PackIntegrationTest.cs index 3037ba3171..be0a44c78b 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/PackIntegrationTest.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/PackIntegrationTest.cs @@ -28,12 +28,12 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests Assert.NuspecContains( result, Path.Combine("obj", Configuration, "ClassLibrary.1.0.0.nuspec"), - @""); + @""); Assert.NupkgContains( result, Path.Combine("bin", Configuration, "ClassLibrary.1.0.0.nupkg"), - Path.Combine("contentFiles", "any", "netstandard2.0", "Views", "Shared", "_Layout.cshtml")); + Path.Combine("contentFiles", "any", "netcoreapp3.0", "Views", "Shared", "_Layout.cshtml")); } [Fact] @@ -55,25 +55,25 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests Assert.NuspecContains( result, Path.Combine("obj", Configuration, "ClassLibrary.1.0.0.nuspec"), - $""); + $""); Assert.NuspecDoesNotContain( result, Path.Combine("obj", Configuration, "ClassLibrary.1.0.0.nuspec"), - $""); + $""); } Assert.NuspecDoesNotContain( result, Path.Combine("obj", Configuration, "ClassLibrary.1.0.0.nuspec"), - @""); + @""); Assert.NupkgContains( result, Path.Combine("bin", Configuration, "ClassLibrary.1.0.0.nupkg"), - Path.Combine("lib", "netstandard2.0", "ClassLibrary.Views.dll")); + Path.Combine("lib", "netcoreapp3.0", "ClassLibrary.Views.dll")); } [Fact] @@ -93,25 +93,25 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests Assert.NuspecContains( result, Path.Combine("obj", Configuration, "ClassLibrary.1.0.0.nuspec"), - $""); + $""); Assert.NuspecDoesNotContain( result, Path.Combine("obj", Configuration, "ClassLibrary.1.0.0.nuspec"), - $""); + $""); } Assert.NuspecDoesNotContain( result, Path.Combine("obj", Configuration, "ClassLibrary.1.0.0.nuspec"), - @""); + @""); Assert.NupkgContains( result, Path.Combine("bin", Configuration, "ClassLibrary.1.0.0.nupkg"), - Path.Combine("lib", "netstandard2.0", "ClassLibrary.Views.dll")); + Path.Combine("lib", "netcoreapp3.0", "ClassLibrary.Views.dll")); } [Fact] @@ -128,21 +128,21 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests Assert.NuspecContains( result, Path.Combine("obj", Configuration, "ClassLibrary.1.0.0.symbols.nuspec"), - $""); + $""); Assert.NuspecContains( result, Path.Combine("obj", Configuration, "ClassLibrary.1.0.0.symbols.nuspec"), - $""); + $""); } Assert.NupkgContains( result, Path.Combine("bin", Configuration, "ClassLibrary.1.0.0.symbols.nupkg"), - Path.Combine("lib", "netstandard2.0", "ClassLibrary.Views.dll"), - Path.Combine("lib", "netstandard2.0", "ClassLibrary.Views.pdb")); + Path.Combine("lib", "netcoreapp3.0", "ClassLibrary.Views.dll"), + Path.Combine("lib", "netcoreapp3.0", "ClassLibrary.Views.pdb")); } [Fact] @@ -162,19 +162,19 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests Assert.NuspecContains( result, Path.Combine("obj", Configuration, "ClassLibrary.1.0.0.nuspec"), - $""); + $""); Assert.NuspecContains( result, Path.Combine("obj", Configuration, "ClassLibrary.1.0.0.nuspec"), - @""); + @""); } Assert.NupkgContains( result, Path.Combine("bin", Configuration, "ClassLibrary.1.0.0.nupkg"), - Path.Combine("lib", "netstandard2.0", "ClassLibrary.Views.dll")); + Path.Combine("lib", "netcoreapp3.0", "ClassLibrary.Views.dll")); } } } diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/PublishIntegrationTest.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/PublishIntegrationTest.cs index 52a0582328..eb19bd2b5b 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/PublishIntegrationTest.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/PublishIntegrationTest.cs @@ -100,20 +100,6 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests Assert.FileCountEquals(result, 0, Path.Combine(PublishOutputPath, "Views"), "*.cshtml"); } - [Fact] // This will use the old precompilation tool, RazorSDK shouldn't get involved. - [InitializeTestProject("SimpleMvc")] - public async Task Publish_WithMvcRazorCompileOnPublish_Noops() - { - var result = await DotnetMSBuild("Publish", "/p:MvcRazorCompileOnPublish=true"); - - Assert.BuildPassed(result); - - Assert.FileExists(result, PublishOutputPath, "SimpleMvc.dll"); - Assert.FileExists(result, PublishOutputPath, "SimpleMvc.pdb"); - Assert.FileDoesNotExist(result, PublishOutputPath, "SimpleMvc.Views.dll"); - Assert.FileDoesNotExist(result, PublishOutputPath, "SimpleMvc.Views.pdb"); - } - [Fact] // This is an override to force the new toolset [InitializeTestProject("SimpleMvc")] public async Task Publish_WithMvcRazorCompileOnPublish_AndRazorSDK_PublishesAssembly() @@ -152,20 +138,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests Assert.FileCountEquals(result, 0, Path.Combine(PublishOutputPath, "refs"), "*.dll"); } - [Fact] - [InitializeTestProject("SimpleMvc")] - public async Task Publish_NoopsWithMvcRazorCompileOnPublish_False() - { - var result = await DotnetMSBuild("Publish", "/p:MvcRazorCompileOnPublish=false"); - Assert.BuildPassed(result); - - // Everything we do should noop - including building the app. - Assert.FileExists(result, PublishOutputPath, "SimpleMvc.dll"); - Assert.FileExists(result, PublishOutputPath, "SimpleMvc.pdb"); - Assert.FileDoesNotExist(result, PublishOutputPath, "SimpleMvc.Views.dll"); - Assert.FileDoesNotExist(result, PublishOutputPath, "SimpleMvc.Views.pdb"); - } [Fact] [InitializeTestProject("SimpleMvc")] diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.ComponentShim/Microsoft.AspNetCore.Components/ComponentBase.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.ComponentShim/Microsoft.AspNetCore.Components/ComponentBase.cs index 5675391bf3..4ec8e784fe 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.ComponentShim/Microsoft.AspNetCore.Components/ComponentBase.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.ComponentShim/Microsoft.AspNetCore.Components/ComponentBase.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Threading.Tasks; using Microsoft.AspNetCore.Components.RenderTree; namespace Microsoft.AspNetCore.Components @@ -19,6 +20,8 @@ namespace Microsoft.AspNetCore.Components { } + protected virtual Task OnInitAsync() => Task.CompletedTask; + protected void WriteLiteral(string literal) { } } } diff --git a/src/Razor/test/testassets/AppWithP2PReference/AppWithP2PReference.csproj b/src/Razor/test/testassets/AppWithP2PReference/AppWithP2PReference.csproj index 9386f89689..d85a5ebfb8 100644 --- a/src/Razor/test/testassets/AppWithP2PReference/AppWithP2PReference.csproj +++ b/src/Razor/test/testassets/AppWithP2PReference/AppWithP2PReference.csproj @@ -2,9 +2,17 @@ $(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\ - true + + true + true + + + + + + netcoreapp3.0 @@ -17,7 +25,6 @@ - diff --git a/src/Razor/test/testassets/ClassLibrary/ClassLibrary.csproj b/src/Razor/test/testassets/ClassLibrary/ClassLibrary.csproj index 036f56d5cb..caab60a992 100644 --- a/src/Razor/test/testassets/ClassLibrary/ClassLibrary.csproj +++ b/src/Razor/test/testassets/ClassLibrary/ClassLibrary.csproj @@ -4,19 +4,25 @@ $(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\ + - netstandard2.0 + true + true + + + + + + + netcoreapp3.0 © Microsoft Razor Test Microsoft ClassLibrary Description - - <_EnableAllInclusiveRazorSdk>true - 3.0 - MVC-3.0 - true - true diff --git a/src/Razor/test/testassets/ClassLibrary2/ClassLibrary2.csproj b/src/Razor/test/testassets/ClassLibrary2/ClassLibrary2.csproj index eaf99c9257..ea67bc1e7f 100644 --- a/src/Razor/test/testassets/ClassLibrary2/ClassLibrary2.csproj +++ b/src/Razor/test/testassets/ClassLibrary2/ClassLibrary2.csproj @@ -5,11 +5,16 @@ - netstandard2.0 + true + true + - <_EnableAllInclusiveRazorSdk>true - 3.0 - MVC-3.0 + + + + + + netcoreapp3.0 diff --git a/src/Razor/test/testassets/ComponentApp/ComponentApp.csproj b/src/Razor/test/testassets/ComponentApp/ComponentApp.csproj new file mode 100644 index 0000000000..a346743179 --- /dev/null +++ b/src/Razor/test/testassets/ComponentApp/ComponentApp.csproj @@ -0,0 +1,35 @@ + + + + $(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\ + <_RazorComponentInclude>**\*.cshtml + + + + netcoreapp3.0 + true + 8.0 + + + + + + + + + false + + + + + + + + + + + + + + + diff --git a/src/Razor/test/testassets/ComponentApp/Components/App.razor b/src/Razor/test/testassets/ComponentApp/Components/App.razor new file mode 100644 index 0000000000..03eee81cef --- /dev/null +++ b/src/Razor/test/testassets/ComponentApp/Components/App.razor @@ -0,0 +1,5 @@ +@* + The Router component displays whichever component has a @page + directive matching the current URI. +*@ + diff --git a/src/Razor/test/testassets/ComponentApp/Components/Pages/Counter.razor b/src/Razor/test/testassets/ComponentApp/Components/Pages/Counter.razor new file mode 100644 index 0000000000..e7244066a2 --- /dev/null +++ b/src/Razor/test/testassets/ComponentApp/Components/Pages/Counter.razor @@ -0,0 +1,16 @@ +@page "/counter" + +

Counter

+ +

Current count: @currentCount

+ + + +@functions { + int currentCount = 0; + + void IncrementCount() + { + currentCount++; + } +} diff --git a/src/Razor/test/testassets/ComponentApp/Components/Pages/FetchData.razor b/src/Razor/test/testassets/ComponentApp/Components/Pages/FetchData.razor new file mode 100644 index 0000000000..f06b62f911 --- /dev/null +++ b/src/Razor/test/testassets/ComponentApp/Components/Pages/FetchData.razor @@ -0,0 +1,45 @@ +@page "/fetchdata" +@using ComponentApp.Services +@inject WeatherForecastService ForecastService + +

Weather forecast

+ +

This component demonstrates fetching data from a service.

+ +@if (forecasts == null) +{ +

Loading...

+} +else +{ + + + + + + + + + + + @foreach (var forecast in forecasts) + { + + + + + + + } + +
DateTemp. (C)Temp. (F)Summary
@forecast.Date.ToShortDateString()@forecast.TemperatureC@forecast.TemperatureF@forecast.Summary
+} + +@functions { + WeatherForecast[] forecasts; + + protected override async Task OnInitAsync() + { + forecasts = await ForecastService.GetForecastAsync(DateTime.Now); + } +} diff --git a/src/Razor/test/testassets/ComponentApp/Components/Pages/Index.razor b/src/Razor/test/testassets/ComponentApp/Components/Pages/Index.razor new file mode 100644 index 0000000000..16dac31925 --- /dev/null +++ b/src/Razor/test/testassets/ComponentApp/Components/Pages/Index.razor @@ -0,0 +1,5 @@ +@page "/" + +

Hello, world!

+ +Welcome to your new app. diff --git a/src/Razor/test/testassets/ComponentApp/Components/Pages/_ViewImports.cshtml b/src/Razor/test/testassets/ComponentApp/Components/Pages/_ViewImports.cshtml new file mode 100644 index 0000000000..0f24edaf1d --- /dev/null +++ b/src/Razor/test/testassets/ComponentApp/Components/Pages/_ViewImports.cshtml @@ -0,0 +1 @@ +@layout MainLayout diff --git a/src/Razor/test/testassets/ComponentApp/Components/Shared/MainLayout.razor b/src/Razor/test/testassets/ComponentApp/Components/Shared/MainLayout.razor new file mode 100644 index 0000000000..160546ccca --- /dev/null +++ b/src/Razor/test/testassets/ComponentApp/Components/Shared/MainLayout.razor @@ -0,0 +1,12 @@ + + +
+
+ About +
+ +
+
+
diff --git a/src/Razor/test/testassets/ComponentApp/Components/Shared/NavMenu.razor b/src/Razor/test/testassets/ComponentApp/Components/Shared/NavMenu.razor new file mode 100644 index 0000000000..8269b96b25 --- /dev/null +++ b/src/Razor/test/testassets/ComponentApp/Components/Shared/NavMenu.razor @@ -0,0 +1,37 @@ + + +
+ +
+ +@functions { + bool collapseNavMenu = true; + + string NavMenuCssClass => collapseNavMenu ? "collapse" : null; + + void ToggleNavMenu() + { + collapseNavMenu = !collapseNavMenu; + } +} diff --git a/src/Razor/test/testassets/ComponentApp/Components/_ViewImports.cshtml b/src/Razor/test/testassets/ComponentApp/Components/_ViewImports.cshtml new file mode 100644 index 0000000000..08636e04e8 --- /dev/null +++ b/src/Razor/test/testassets/ComponentApp/Components/_ViewImports.cshtml @@ -0,0 +1 @@ +@using ComponentApp.Components.Shared diff --git a/src/Razor/test/testassets/ComponentApp/Program.cs b/src/Razor/test/testassets/ComponentApp/Program.cs new file mode 100644 index 0000000000..6c1ff60bcd --- /dev/null +++ b/src/Razor/test/testassets/ComponentApp/Program.cs @@ -0,0 +1,10 @@ + +namespace ComponentApp +{ + public class Program + { + public static void Main(string[] args) + { + } + } +} diff --git a/src/Razor/test/testassets/ComponentApp/Services/WeatherForecast.cs b/src/Razor/test/testassets/ComponentApp/Services/WeatherForecast.cs new file mode 100644 index 0000000000..e55989b058 --- /dev/null +++ b/src/Razor/test/testassets/ComponentApp/Services/WeatherForecast.cs @@ -0,0 +1,15 @@ +using System; + +namespace ComponentApp.Services +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF { get; set; } + + public string Summary { get; set; } + } +} diff --git a/src/Razor/test/testassets/ComponentApp/Services/WeatherForecastService.cs b/src/Razor/test/testassets/ComponentApp/Services/WeatherForecastService.cs new file mode 100644 index 0000000000..a1020e22b8 --- /dev/null +++ b/src/Razor/test/testassets/ComponentApp/Services/WeatherForecastService.cs @@ -0,0 +1,25 @@ +using System; +using System.Linq; +using System.Threading.Tasks; + +namespace ComponentApp.Services +{ + public class WeatherForecastService + { + private static string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + public Task GetForecastAsync(DateTime startDate) + { + var rng = new Random(); + return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = startDate.AddDays(index), + TemperatureC = rng.Next(-20, 55), + Summary = Summaries[rng.Next(Summaries.Length)] + }).ToArray()); + } + } +} diff --git a/src/Razor/test/testassets/ComponentLibrary/ComponentLibrary.csproj b/src/Razor/test/testassets/ComponentLibrary/ComponentLibrary.csproj index 0aca4f7bc1..c1b50b877b 100644 --- a/src/Razor/test/testassets/ComponentLibrary/ComponentLibrary.csproj +++ b/src/Razor/test/testassets/ComponentLibrary/ComponentLibrary.csproj @@ -7,10 +7,7 @@ netstandard2.0 - - <_EnableAllInclusiveRazorSdk>true 3.0 - MVC-3.0 @@ -28,10 +25,6 @@ - - - -
diff --git a/src/Razor/test/testassets/LargeProject/LargeProject.csproj b/src/Razor/test/testassets/LargeProject/LargeProject.csproj index 8e8dea1809..c9dcbb4f7c 100644 --- a/src/Razor/test/testassets/LargeProject/LargeProject.csproj +++ b/src/Razor/test/testassets/LargeProject/LargeProject.csproj @@ -2,9 +2,21 @@ $(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\ - true + + + true + <_ReferencesAspNetCoreApp>true + + + + + + netcoreapp3.0 @@ -14,10 +26,6 @@ false - - - - diff --git a/src/Razor/test/testassets/MvcWithComponents/MvcWithComponents.csproj b/src/Razor/test/testassets/MvcWithComponents/MvcWithComponents.csproj index 523061d189..eead930882 100644 --- a/src/Razor/test/testassets/MvcWithComponents/MvcWithComponents.csproj +++ b/src/Razor/test/testassets/MvcWithComponents/MvcWithComponents.csproj @@ -2,10 +2,18 @@ $(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\ - true <_RazorComponentInclude>Components\**\*.cshtml + + true + true + + + + + + netcoreapp3.0 @@ -15,10 +23,6 @@ false - - - - diff --git a/src/Razor/test/testassets/RazorTest.Introspection.targets b/src/Razor/test/testassets/RazorTest.Introspection.targets index b3e93737f3..ea4f3d100e 100644 --- a/src/Razor/test/testassets/RazorTest.Introspection.targets +++ b/src/Razor/test/testassets/RazorTest.Introspection.targets @@ -33,4 +33,9 @@ + + + + + diff --git a/src/Razor/test/testassets/RestoreTestProjects/RestoreTestProjects.csproj b/src/Razor/test/testassets/RestoreTestProjects/RestoreTestProjects.csproj index 051be921c2..05505c5df3 100644 --- a/src/Razor/test/testassets/RestoreTestProjects/RestoreTestProjects.csproj +++ b/src/Razor/test/testassets/RestoreTestProjects/RestoreTestProjects.csproj @@ -9,6 +9,7 @@ + diff --git a/src/Razor/test/testassets/SimpleMvc/SimpleMvc.csproj b/src/Razor/test/testassets/SimpleMvc/SimpleMvc.csproj index 21ed48c476..634cf28232 100644 --- a/src/Razor/test/testassets/SimpleMvc/SimpleMvc.csproj +++ b/src/Razor/test/testassets/SimpleMvc/SimpleMvc.csproj @@ -1,10 +1,18 @@ - + $(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\ - true + + true + true + + + + + + netcoreapp3.0 @@ -14,10 +22,6 @@ false - - - - diff --git a/src/Razor/test/testassets/SimpleMvcFSharp/SimpleMvcFSharp.fsproj b/src/Razor/test/testassets/SimpleMvcFSharp/SimpleMvcFSharp.fsproj index e9a2f2c754..eaad6c8d99 100644 --- a/src/Razor/test/testassets/SimpleMvcFSharp/SimpleMvcFSharp.fsproj +++ b/src/Razor/test/testassets/SimpleMvcFSharp/SimpleMvcFSharp.fsproj @@ -2,9 +2,16 @@ $(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\ + + + true + + + + netcoreapp3.0 @@ -19,10 +26,6 @@ - - - - @@ -31,7 +34,7 @@ - + diff --git a/src/Razor/test/testassets/SimplePages/SimplePages.csproj b/src/Razor/test/testassets/SimplePages/SimplePages.csproj index 66d48660f4..634cf28232 100644 --- a/src/Razor/test/testassets/SimplePages/SimplePages.csproj +++ b/src/Razor/test/testassets/SimplePages/SimplePages.csproj @@ -2,9 +2,17 @@ $(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\ - true + + true + true + + + + + + netcoreapp3.0 @@ -14,10 +22,6 @@ false - - - - @@ -29,5 +33,5 @@ - +