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 cfee40a19e
This commit is contained in:
parent
2c39457306
commit
25e5a4ffab
|
|
@ -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<RazorLanguageVersion>, IComparable<RazorLanguageVersion>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,6 +12,14 @@ Copyright (c) .NET Foundation. All rights reserved.
|
|||
|
||||
<Project ToolsVersion="14.0">
|
||||
|
||||
<!-- Wire up RazorComponentGenerateCore only once we know we are importing this target file. This prevents avoidable build failures. -->
|
||||
<PropertyGroup>
|
||||
<RazorComponentGenerateDependsOn>
|
||||
$(RazorComponentGenerateDependsOn);
|
||||
RazorComponentGenerateCore
|
||||
</RazorComponentGenerateDependsOn>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- Used for tracking inputs to component generation -->
|
||||
<_RazorComponentInputHash></_RazorComponentInputHash>
|
||||
|
|
|
|||
|
|
@ -11,10 +11,6 @@ Copyright (c) .NET Foundation. All rights reserved.
|
|||
-->
|
||||
<Project ToolsVersion="14.0">
|
||||
|
||||
<PropertyGroup>
|
||||
<_TargetingNETCoreApp30OrLater Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(_TargetFrameworkVersionWithoutV)' > '2.9'">true</_TargetingNETCoreApp30OrLater>
|
||||
</PropertyGroup>
|
||||
|
||||
<!--
|
||||
Initialize properties and items inferred using the project version. This file is not imported in projects referencing
|
||||
MVC \ Razor 2.2 or earlier since values specified here are provided via targets and props imported from NuGet packages
|
||||
|
|
@ -27,16 +23,24 @@ Copyright (c) .NET Foundation. All rights reserved.
|
|||
would be to detect whether the ASP.NET Core shared framework is referenced.
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<!-- Continue setting this property to maintain compat with legacy Razor.Design -->
|
||||
<IsRazorCompilerReferenced Condition="'$(IsRazorCompilerReferenced)'==''">true</IsRazorCompilerReferenced>
|
||||
</PropertyGroup>
|
||||
|
||||
<!--
|
||||
Configure MVC specific configuration if the application uses a configuration that supports MVC.
|
||||
-->
|
||||
<PropertyGroup Condition="'$(AddRazorSupportForMvc)' == 'true'">
|
||||
<!--
|
||||
MVC uses a ProvideApplicationPartFactoryAttribute on the generated assembly to load compiled views from assembly. Set this to false, to prevent generating this attribute.
|
||||
-->
|
||||
<GenerateProvideApplicationPartFactoryAttribute Condition="'$(GenerateProvideApplicationPartFactoryAttribute)'==''">$(_TargetingNETCoreApp30OrLater)</GenerateProvideApplicationPartFactoryAttribute>
|
||||
<GenerateProvideApplicationPartFactoryAttribute Condition="'$(GenerateProvideApplicationPartFactoryAttribute)'==''">true</GenerateProvideApplicationPartFactoryAttribute>
|
||||
|
||||
<!--
|
||||
Determines if the Sdk is allowed to add additional attributes to the project assembly.
|
||||
For instance, MVC will generally want to add attributes to support view discovery and runtime compilation.
|
||||
-->
|
||||
<GenerateRazorAssemblyInfo Condition="'$(GenerateRazorAssemblyInfo)'==''">$(_TargetingNETCoreApp30OrLater)</GenerateRazorAssemblyInfo>
|
||||
<GenerateRazorAssemblyInfo Condition="'$(GenerateRazorAssemblyInfo)'==''">true</GenerateRazorAssemblyInfo>
|
||||
|
||||
<!--
|
||||
MVC will generally want to add support for runtime compilation, but only for applications.
|
||||
|
|
@ -47,20 +51,14 @@ Copyright (c) .NET Foundation. All rights reserved.
|
|||
The type name of the ApplicationPartFactory applied to the generated Razor file.
|
||||
-->
|
||||
<ProvideApplicationPartFactoryAttributeTypeName Condition="'$(ProvideApplicationPartFactoryAttributeTypeName)' == ''">Microsoft.AspNetCore.Mvc.ApplicationParts.CompiledRazorAssemblyApplicationPartFactory, Microsoft.AspNetCore.Mvc.Razor</ProvideApplicationPartFactoryAttributeTypeName>
|
||||
|
||||
<!-- Continue setting this property to maintain compat with legacy Razor.Design -->
|
||||
<IsRazorCompilerReferenced Condition="'$(IsRazorCompilerReferenced)'==''">true</IsRazorCompilerReferenced>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(RazorLangVersion)'==''">
|
||||
<RazorLangVersion Condition="'$(_TargetingNETCoreApp30OrLater)' == 'true'">3.0</RazorLangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<!--
|
||||
Set the primary configuration supported by this SDK as the default configuration for Razor.
|
||||
Determine the default Razor configuration
|
||||
-->
|
||||
<PropertyGroup Condition="'$(RazorDefaultConfiguration)'==''">
|
||||
<RazorDefaultConfiguration Condition="'$(_TargetingNETCoreApp30OrLater)' == 'true'">MVC-3.0</RazorDefaultConfiguration>
|
||||
<RazorDefaultConfiguration Condition="'$(AddRazorSupportForMvc)'=='true'">MVC-3.0</RazorDefaultConfiguration>
|
||||
<RazorDefaultConfiguration Condition="'$(RazorDefaultConfiguration)'==''">Default</RazorDefaultConfiguration>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -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.
|
||||
-->
|
||||
<RazorConfiguration Include="MVC-3.0">
|
||||
<RazorConfiguration Include="Default" />
|
||||
<RazorConfiguration Include="MVC-3.0" >
|
||||
<Extensions>MVC-3.0;$(CustomRazorExtension)</Extensions>
|
||||
</RazorConfiguration>
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
-->
|
||||
<ProjectCapability Include="DotNetCoreRazorConfiguration" Condition="'$(_TargetingNETCoreApp30OrLater)'=='true'"/>
|
||||
|
||||
<ProjectCapability Include="DotNetCoreRazorConfiguration" Condition="'$(_Targeting30OrNewerRazorLangVersion)' == 'true'"/>
|
||||
|
||||
<!--
|
||||
Activates the set of nesting behaviors we want from solution explorer.
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and
|
|||
Copyright (c) .NET Foundation. All rights reserved.
|
||||
***********************************************************************************************
|
||||
-->
|
||||
<Project ToolsVersion="14.0" TreatAsLocalProperty="_RazorSdkTasksTFM">
|
||||
<Project ToolsVersion="14.0" TreatAsLocalProperty="_RazorSdkTasksTFM;_Targeting30OrNewerRazorLangVersion">
|
||||
<!--
|
||||
Targets supporting Razor MSBuild integration. Contain support for generating C# code using Razor
|
||||
and including the generated code in the project lifecycle, including compiling, publishing and producing
|
||||
|
|
@ -28,9 +28,38 @@ Copyright (c) .NET Foundation. All rights reserved.
|
|||
<_RazorSdkTasksTFM Condition=" '$(MSBuildRuntimeType)' == 'Core'">netstandard2.0</_RazorSdkTasksTFM>
|
||||
<_RazorSdkTasksTFM Condition=" '$(_RazorSdkTasksTFM)' == ''">net46</_RazorSdkTasksTFM>
|
||||
<RazorSdkBuildTasksAssembly>$(RazorSdkBuildTasksDirectoryRoot)$(_RazorSdkTasksTFM)\Microsoft.NET.Sdk.Razor.Tasks.dll</RazorSdkBuildTasksAssembly>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Resolve the RazorLangVersion based on values imported or TFM. -->
|
||||
<PropertyGroup>
|
||||
<_TargetFrameworkVersionWithoutV>$(TargetFrameworkVersion.TrimStart('vV'))</_TargetFrameworkVersionWithoutV>
|
||||
<_EnableAllInclusiveRazorSdk Condition="'$(_EnableInclusiveRazorSdk)' == '' AND '$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(_TargetFrameworkVersionWithoutV)' > '2.9'">true</_EnableAllInclusiveRazorSdk>
|
||||
|
||||
<!--
|
||||
Infer the RazorLangVersion if no value was specified. When adding support for newer target frameworks, list newer language versions first.
|
||||
-->
|
||||
<RazorLangVersion Condition="'$(RazorLangVersion)' == '' AND '$(_TargetFrameworkVersionWithoutV)' > '2.9'">3.0</RazorLangVersion>
|
||||
|
||||
<!--
|
||||
In 3.0, we expect RazorLangVersion to either be specified in the template or inferred via TFM. In 2.x, RazorLangVersion is
|
||||
specified via the Razor.Design package. We'll default to a version of 2.1, the earliest version that the SDK supports.
|
||||
A 2.1 version should result in a build warning if the project contains Components.
|
||||
-->
|
||||
<RazorLangVersion Condition="'$(RazorLangVersion)' == ''">2.1</RazorLangVersion>
|
||||
|
||||
<!-- Keep this in sync with RazorLangVersion.cs if we introduce new text based values. -->
|
||||
<_Targeting30OrNewerRazorLangVersion Condition="
|
||||
'$(RazorLangVersion)' == 'Latest' OR
|
||||
'$(RazorLangVersion)' == 'Experimental' OR
|
||||
('$(RazorLangVersion)' != '' AND '$(RazorLangVersion)' > '2.9')">true</_Targeting30OrNewerRazorLangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<PropertyGroup>
|
||||
<!--
|
||||
The property IsRazorCompilerReferenced is defined by the 2.x Razor.Design package. We can use this as a best guess to determine if a project is targeting 2.x or earlier.
|
||||
This is useful to provide 3.0 or newer specific build warnings. However, since it's not very reliable, we should not use this to make build-altering decisions.
|
||||
-->
|
||||
<_IsTargetingRazor2X Condition="'$(IsRazorCompilerReferenced)'=='true'">true</_IsTargetingRazor2X>
|
||||
</PropertyGroup>
|
||||
|
||||
<!--
|
||||
|
|
@ -47,12 +76,14 @@ Copyright (c) .NET Foundation. All rights reserved.
|
|||
AssignRazorGenerateTargetPaths;
|
||||
ResolveAssemblyReferenceRazorGenerateInputs;
|
||||
_CheckForMissingRazorCompiler;
|
||||
_CheckForIncorrectMvcConfiguration;
|
||||
ResolveTagHelperRazorGenerateInputs
|
||||
</PrepareForRazorGenerateDependsOn>
|
||||
|
||||
<PrepareForRazorComponentGenerateDependsOn>
|
||||
ResolveRazorConfiguration;
|
||||
ResolveRazorComponentInputs;
|
||||
_CheckForIncorrectComponentsConfiguration;
|
||||
AssignRazorComponentTargetPaths;
|
||||
</PrepareForRazorComponentGenerateDependsOn>
|
||||
|
||||
|
|
@ -63,8 +94,7 @@ Copyright (c) .NET Foundation. All rights reserved.
|
|||
</RazorGenerateDependsOn>
|
||||
|
||||
<RazorComponentGenerateDependsOn>
|
||||
PrepareForRazorComponentGenerate;
|
||||
RazorComponentGenerateCore
|
||||
PrepareForRazorComponentGenerate
|
||||
</RazorComponentGenerateDependsOn>
|
||||
|
||||
<PrepareForRazorCompileDependsOn>
|
||||
|
|
@ -155,7 +185,7 @@ Copyright (c) .NET Foundation. All rights reserved.
|
|||
<!--
|
||||
Use the suffix .Views when producing compiled view assemblies. This matches the requirements for Mvc's ViewsFeatureProvider.
|
||||
-->
|
||||
<RazorTargetNameSuffix Condition="'$(_EnableInclusiveRazorSdk)' == '' AND '$(RazorTargetNameSuffix)'==''">.Views</RazorTargetNameSuffix>
|
||||
<RazorTargetNameSuffix Condition="'$(RazorTargetNameSuffix)'=='' AND '$(_Targeting30OrNewerRazorLangVersion)' == 'true'">.Views</RazorTargetNameSuffix>
|
||||
|
||||
<!-- Suffix appended to $(TargetName) to produce $(RazorTargetName), the name of the assembly produced by Razor -->
|
||||
<RazorTargetNameSuffix Condition="'$(RazorTargetNameSuffix)' == ''">.Razor</RazorTargetNameSuffix>
|
||||
|
|
@ -216,8 +246,16 @@ Copyright (c) .NET Foundation. All rights reserved.
|
|||
<_RazorDebugSymbolsProduced Condition="'$(DebugType)'=='embedded'">false</_RazorDebugSymbolsProduced>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Resolve the toolset to use -->
|
||||
<PropertyGroup>
|
||||
<!--
|
||||
Resolve the toolset to use. This specifically applies to compilation with 2.x projects where compilation could be performed either using
|
||||
the PrecompilationTool (Microsoft.AspNetCore.Mvc.Razor.ViewCompilation) or the RazorSDK and we have to infer the tool that is to be used.
|
||||
In 3.0 or later, there is only the RazorSdk.
|
||||
-->
|
||||
<PropertyGroup Condition="'$(_Targeting30OrNewerRazorLangVersion)' == 'true'">
|
||||
<ResolvedRazorCompileToolset>RazorSdk</ResolvedRazorCompileToolset>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(ResolvedRazorCompileToolset)' == ''">
|
||||
<!-- Default value for the property 'MvcRazorCompileOnPublish' is empty. If it has been explicitly enabled, continue using precompilation. -->
|
||||
<ResolvedRazorCompileToolset Condition="'$(MvcRazorCompileOnPublish)' == 'true'">PrecompilationTool</ResolvedRazorCompileToolset>
|
||||
|
||||
|
|
@ -228,7 +266,7 @@ Copyright (c) .NET Foundation. All rights reserved.
|
|||
<ResolvedRazorCompileToolset Condition="'$(MvcRazorCompileOnPublish)' == '' AND '$(RazorCompileToolset)' == 'RazorSdk'">$(RazorCompileToolset)</ResolvedRazorCompileToolset>
|
||||
|
||||
<!-- If RazorSdk is not referenced, fall-back to Precompilation tool when referenced by a 2.2 or earlier targeting project. -->
|
||||
<ResolvedRazorCompileToolset Condition="'$(ResolvedRazorCompileToolset)' == 'RazorSdk' And '$(IsRazorCompilerReferenced)' != 'true' AND '$(_EnableAllInclusiveRazorSdk)' != 'true'">PrecompilationTool</ResolvedRazorCompileToolset>
|
||||
<ResolvedRazorCompileToolset Condition="'$(ResolvedRazorCompileToolset)' == 'RazorSdk' And '$(IsRazorCompilerReferenced)' != 'true'">PrecompilationTool</ResolvedRazorCompileToolset>
|
||||
|
||||
<!-- Previous versions of the precompilation tool still depends on the msbuild property 'MvcRazorCompileOnPublish'. Hence, setting it to the old default value -->
|
||||
<MvcRazorCompileOnPublish Condition="'$(MvcRazorCompileOnPublish)' == ''">true</MvcRazorCompileOnPublish>
|
||||
|
|
@ -281,12 +319,12 @@ Copyright (c) .NET Foundation. All rights reserved.
|
|||
Condition="'$(IsRazorCompilerReferenced)' == 'true' AND '$(RazorCodeGenerationTargetsPath)' != '' AND Exists('$(RazorCodeGenerationTargetsPath)')" />
|
||||
|
||||
<!-- When targeting 3.x and later projects, we have to infer configuration by inspecting the project. -->
|
||||
<Import Project="Microsoft.NET.Sdk.Razor.Configuration.targets" Condition="'$(_EnableAllInclusiveRazorSdk)' == 'true'" />
|
||||
<Import Project="Microsoft.NET.Sdk.Razor.Configuration.targets" Condition="'$(_Targeting30OrNewerRazorLangVersion)' == 'true'" />
|
||||
|
||||
<!-- For projects targeting 3.x and later, use the compiler that ships in the Sdk -->
|
||||
<Import Project="Microsoft.NET.Sdk.Razor.CodeGeneration.targets" Condition="'$(_EnableAllInclusiveRazorSdk)' == 'true'" />
|
||||
<!-- For projects targeting 3.x and later, use the compiler that ships in the SDK -->
|
||||
<Import Project="Microsoft.NET.Sdk.Razor.CodeGeneration.targets" Condition="'$(_Targeting30OrNewerRazorLangVersion)' == 'true'" />
|
||||
|
||||
<Import Project="Microsoft.NET.Sdk.Razor.Component.targets" />
|
||||
<Import Project="Microsoft.NET.Sdk.Razor.Component.targets" Condition="'$(_Targeting30OrNewerRazorLangVersion)' == 'true'" />
|
||||
|
||||
<Import Project="Microsoft.NET.Sdk.Razor.GenerateAssemblyInfo.targets" />
|
||||
|
||||
|
|
@ -319,15 +357,28 @@ Copyright (c) .NET Foundation. All rights reserved.
|
|||
Computes the applicable @(ResolvedRazorConfiguration) and @(ResolvedRazorExtension) items that match the project's
|
||||
configuration.
|
||||
-->
|
||||
<Target
|
||||
Name="ResolveRazorConfiguration"
|
||||
Condition="'$(RazorDefaultConfiguration)'!=''">
|
||||
|
||||
<ItemGroup>
|
||||
<Target Name="ResolveRazorConfiguration">
|
||||
<ItemGroup Condition="'$(RazorDefaultConfiguration)'!=''">
|
||||
<ResolvedRazorConfiguration Include="@(RazorConfiguration->WithMetadataValue('Identity', '$(RazorDefaultConfiguration)')->Distinct())" />
|
||||
</ItemGroup>
|
||||
|
||||
<FindInList List="@(RazorExtension)" ItemSpecToFind="@(ResolvedRazorConfiguration->Metadata('Extensions'))">
|
||||
<!--
|
||||
ResolvedRazorConfiguration should only ever have one item in it. If misconfigured, we may resolve more than one item which
|
||||
may result in incorrect results or poorly worded build errors.
|
||||
-->
|
||||
<Warning Text="Unable to resolve a Razor configuration for the value '$(_RazorConfiguration)'. Available configurations '@(RazorConfiguration)'.'"
|
||||
Code="RazorSDK1000"
|
||||
Condition="'@(ResolvedRazorConfiguration->Count())' == '0'" />
|
||||
|
||||
<Warning Text="More than one Razor configuration was resolved for the value '$(_RazorConfiguration)'. Available configurations '@(RazorConfiguration)'.
|
||||
A common cause is a reference to an incompatible version of the 'Microsoft.AspNetCore.Mvc' or 'Microsoft.AspNetCore.Razor.Design' package."
|
||||
Code="RazorSDK1001"
|
||||
Condition="'@(ResolvedRazorConfiguration->Count())' > '1'" />
|
||||
|
||||
<FindInList
|
||||
List="@(RazorExtension)"
|
||||
ItemSpecToFind="@(ResolvedRazorConfiguration->Metadata('Extensions'))"
|
||||
Condition="'@(ResolvedRazorConfiguration->HasMetadata('Extensions')->Count())' != '0'">
|
||||
<Output TaskParameter="ItemFound" ItemName="ResolvedRazorExtension" />
|
||||
</FindInList>
|
||||
</Target>
|
||||
|
|
@ -729,9 +780,34 @@ Copyright (c) .NET Foundation. All rights reserved.
|
|||
|
||||
<Target Name="_CheckForMissingRazorCompiler" Condition="'$(IsRazorCompilerReferenced)' != 'true'">
|
||||
<Error
|
||||
Code="RAZORSDK1003"
|
||||
Text="A PackageReference for 'Microsoft.AspNetCore.Razor.Design' was not included in your project. This package is required to compile Razor files. Typically, a
|
||||
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." />
|
||||
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." />
|
||||
</Target>
|
||||
|
||||
<Target Name="_CheckForIncorrectMvcConfiguration"
|
||||
Condition="'@(ResolvedRazorConfiguration)' == 'Default' AND
|
||||
('$(RazorCompileOnBuild)' == 'true' OR '$(RazorCompileOnPublish)' =='true') AND
|
||||
'@(RazorGenerate->Count())' != '0' AND
|
||||
'$(_Targeting30OrNewerRazorLangVersion)' == 'true' AND
|
||||
'$(_IsTargetingRazor2X)' != 'true'">
|
||||
<Warning
|
||||
Code="RAZORSDK1004"
|
||||
Text="One or more Razor view or page files were found, but the project is not configured to add Razor support for MVC. The MSBuild property 'AddRazorSupportForMvc' must be set to correctly
|
||||
compile Razor files that target MVC. For more information, see https://go.microsoft.com/fwlink/?linkid=868374." />
|
||||
</Target>
|
||||
|
||||
<Target Name="_CheckForIncorrectComponentsConfiguration"
|
||||
Condition="('$(RazorCompileOnBuild)' == 'true' OR '$(RazorCompileOnPublish)' =='true') AND
|
||||
'@(RazorComponent->Count())' != '0' AND
|
||||
'$(_Targeting30OrNewerRazorLangVersion)' != 'true' AND
|
||||
'$(_IsTargetingRazor2X)' != 'true'">
|
||||
|
||||
<Warning
|
||||
Code="RAZORSDK1005"
|
||||
Text="One or more Razor component files (.razor) were found, but the project is not configured to compile Razor Components. Configure the project by targeting RazorLangVersion 3.0 or newer.
|
||||
For more information, see https://go.microsoft.com/fwlink/?linkid=868374." />
|
||||
</Target>
|
||||
|
||||
<Target Name="_ResolveRazorTargetPath">
|
||||
|
|
|
|||
|
|
@ -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<string> warnings)
|
||||
: base(result)
|
||||
{
|
||||
Warnings = warnings.ToList();
|
||||
}
|
||||
|
||||
public List<string> Warnings { get; }
|
||||
|
||||
protected override string Heading => "Build contains unexpected warnings: " + string.Join(Environment.NewLine, Warnings);
|
||||
}
|
||||
|
||||
private class BuildPassedException : MSBuildXunitException
|
||||
{
|
||||
public BuildPassedException(MSBuildResult result)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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<LegacyBuildServerTestFixture>
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<LegacyBuildServerTestFixture>
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<LegacyBuildServerTestFixture>
|
||||
{
|
||||
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<string>(), "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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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("<PropertyGroup><RazorLangVersion /></PropertyGroup>");
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -28,12 +28,12 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
|
|||
Assert.NuspecContains(
|
||||
result,
|
||||
Path.Combine("obj", Configuration, "ClassLibrary.1.0.0.nuspec"),
|
||||
@"<files include=""any/netstandard2.0/Views/Shared/_Layout.cshtml"" buildAction=""Content"" />");
|
||||
@"<files include=""any/netcoreapp3.0/Views/Shared/_Layout.cshtml"" buildAction=""Content"" />");
|
||||
|
||||
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"),
|
||||
$"<file src=\"{Path.Combine(Project.DirectoryPath, "bin", Configuration, "netstandard2.0", "ClassLibrary.Views.dll")}\" " +
|
||||
$"target=\"{Path.Combine("lib", "netstandard2.0", "ClassLibrary.Views.dll")}\" />");
|
||||
$"<file src=\"{Path.Combine(Project.DirectoryPath, "bin", Configuration, "netcoreapp3.0", "ClassLibrary.Views.dll")}\" " +
|
||||
$"target=\"{Path.Combine("lib", "netcoreapp3.0", "ClassLibrary.Views.dll")}\" />");
|
||||
|
||||
Assert.NuspecDoesNotContain(
|
||||
result,
|
||||
Path.Combine("obj", Configuration, "ClassLibrary.1.0.0.nuspec"),
|
||||
$"<file src=\"{Path.Combine(Project.DirectoryPath, "bin", Configuration, "netstandard2.0", "ClassLibrary.Views.pdb")}\" " +
|
||||
$"target=\"{Path.Combine("lib", "netstandard2.0", "ClassLibrary.Views.pdb")}\" />");
|
||||
$"<file src=\"{Path.Combine(Project.DirectoryPath, "bin", Configuration, "netcoreapp3.0", "ClassLibrary.Views.pdb")}\" " +
|
||||
$"target=\"{Path.Combine("lib", "netcoreapp3.0", "ClassLibrary.Views.pdb")}\" />");
|
||||
}
|
||||
|
||||
Assert.NuspecDoesNotContain(
|
||||
result,
|
||||
Path.Combine("obj", Configuration, "ClassLibrary.1.0.0.nuspec"),
|
||||
@"<files include=""any/netstandard2.0/Views/Shared/_Layout.cshtml"" buildAction=""Content"" />");
|
||||
@"<files include=""any/netcoreapp3.0/Views/Shared/_Layout.cshtml"" buildAction=""Content"" />");
|
||||
|
||||
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"),
|
||||
$"<file src=\"{Path.Combine(Project.DirectoryPath, "bin", Configuration, "netstandard2.0", "ClassLibrary.Views.dll")}\" " +
|
||||
$"target=\"{Path.Combine("lib", "netstandard2.0", "ClassLibrary.Views.dll")}\" />");
|
||||
$"<file src=\"{Path.Combine(Project.DirectoryPath, "bin", Configuration, "netcoreapp3.0", "ClassLibrary.Views.dll")}\" " +
|
||||
$"target=\"{Path.Combine("lib", "netcoreapp3.0", "ClassLibrary.Views.dll")}\" />");
|
||||
|
||||
Assert.NuspecDoesNotContain(
|
||||
result,
|
||||
Path.Combine("obj", Configuration, "ClassLibrary.1.0.0.nuspec"),
|
||||
$"<file src=\"{Path.Combine(Project.DirectoryPath, "bin", Configuration, "netstandard2.0", "ClassLibrary.Views.pdb")}\" " +
|
||||
$"target=\"{Path.Combine("lib", "netstandard2.0", "ClassLibrary.Views.pdb")}\" />");
|
||||
$"<file src=\"{Path.Combine(Project.DirectoryPath, "bin", Configuration, "netcoreapp3.0", "ClassLibrary.Views.pdb")}\" " +
|
||||
$"target=\"{Path.Combine("lib", "netcoreapp3.0", "ClassLibrary.Views.pdb")}\" />");
|
||||
}
|
||||
|
||||
Assert.NuspecDoesNotContain(
|
||||
result,
|
||||
Path.Combine("obj", Configuration, "ClassLibrary.1.0.0.nuspec"),
|
||||
@"<files include=""any/netstandard2.0/Views/Shared/_Layout.cshtml"" buildAction=""Content"" />");
|
||||
@"<files include=""any/netcoreapp3.0/Views/Shared/_Layout.cshtml"" buildAction=""Content"" />");
|
||||
|
||||
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"),
|
||||
$"<file src=\"{Path.Combine(Project.DirectoryPath, "bin", Configuration, "netstandard2.0", "ClassLibrary.Views.dll")}\" " +
|
||||
$"target=\"{Path.Combine("lib", "netstandard2.0", "ClassLibrary.Views.dll")}\" />");
|
||||
$"<file src=\"{Path.Combine(Project.DirectoryPath, "bin", Configuration, "netcoreapp3.0", "ClassLibrary.Views.dll")}\" " +
|
||||
$"target=\"{Path.Combine("lib", "netcoreapp3.0", "ClassLibrary.Views.dll")}\" />");
|
||||
|
||||
Assert.NuspecContains(
|
||||
result,
|
||||
Path.Combine("obj", Configuration, "ClassLibrary.1.0.0.symbols.nuspec"),
|
||||
$"<file src=\"{Path.Combine(Project.DirectoryPath, "bin", Configuration, "netstandard2.0", "ClassLibrary.Views.pdb")}\" " +
|
||||
$"target=\"{Path.Combine("lib", "netstandard2.0", "ClassLibrary.Views.pdb")}\" />");
|
||||
$"<file src=\"{Path.Combine(Project.DirectoryPath, "bin", Configuration, "netcoreapp3.0", "ClassLibrary.Views.pdb")}\" " +
|
||||
$"target=\"{Path.Combine("lib", "netcoreapp3.0", "ClassLibrary.Views.pdb")}\" />");
|
||||
}
|
||||
|
||||
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"),
|
||||
$"<file src=\"{Path.Combine(Project.DirectoryPath, "bin", Configuration, "netstandard2.0", "ClassLibrary.Views.dll")}\" " +
|
||||
$"target=\"{Path.Combine("lib", "netstandard2.0", "ClassLibrary.Views.dll")}\" />");
|
||||
$"<file src=\"{Path.Combine(Project.DirectoryPath, "bin", Configuration, "netcoreapp3.0", "ClassLibrary.Views.dll")}\" " +
|
||||
$"target=\"{Path.Combine("lib", "netcoreapp3.0", "ClassLibrary.Views.dll")}\" />");
|
||||
|
||||
Assert.NuspecContains(
|
||||
result,
|
||||
Path.Combine("obj", Configuration, "ClassLibrary.1.0.0.nuspec"),
|
||||
@"<files include=""any/netstandard2.0/Views/Shared/_Layout.cshtml"" buildAction=""Content"" />");
|
||||
@"<files include=""any/netcoreapp3.0/Views/Shared/_Layout.cshtml"" buildAction=""Content"" />");
|
||||
}
|
||||
|
||||
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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")]
|
||||
|
|
|
|||
|
|
@ -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) { }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,17 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<RazorSdkDirectoryRoot>$(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\</RazorSdkDirectoryRoot>
|
||||
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
|
||||
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.NETCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
|
@ -17,7 +25,6 @@
|
|||
<!-- Test Placeholder -->
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.NETCore.App" />
|
||||
<ProjectReference Include="..\ClassLibrary\ClassLibrary.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -4,19 +4,25 @@
|
|||
<RazorSdkDirectoryRoot>$(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\</RazorSdkDirectoryRoot>
|
||||
</PropertyGroup>
|
||||
|
||||
<!--
|
||||
The AspNetCore repo depends on AspNetCore-Tooling, and we want to avoid creating a cylical dependency between the two
|
||||
by adding a reference to Microsoft.AspNetCore.App. We'll instead simulate the presence of the reference.
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
|
||||
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.NETCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<Copyright>© Microsoft</Copyright>
|
||||
<Product>Razor Test</Product>
|
||||
<Company>Microsoft</Company>
|
||||
<Description>ClassLibrary Description</Description>
|
||||
|
||||
<_EnableAllInclusiveRazorSdk>true</_EnableAllInclusiveRazorSdk>
|
||||
<RazorLangVersion>3.0</RazorLangVersion>
|
||||
<RazorDefaultConfiguration>MVC-3.0</RazorDefaultConfiguration>
|
||||
<GenerateRazorAssemblyInfo>true</GenerateRazorAssemblyInfo>
|
||||
<GenerateProvideApplicationPartFactoryAttribute>true</GenerateProvideApplicationPartFactoryAttribute>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(RunningAsTest)' == ''">
|
||||
|
|
|
|||
|
|
@ -5,11 +5,16 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
|
||||
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
|
||||
</PropertyGroup>
|
||||
|
||||
<_EnableAllInclusiveRazorSdk>true</_EnableAllInclusiveRazorSdk>
|
||||
<RazorLangVersion>3.0</RazorLangVersion>
|
||||
<RazorDefaultConfiguration>MVC-3.0</RazorDefaultConfiguration>
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.NETCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(RunningAsTest)' == ''">
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<RazorSdkDirectoryRoot>$(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\</RazorSdkDirectoryRoot>
|
||||
<_RazorComponentInclude>**\*.cshtml</_RazorComponentInclude>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.NETCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(RunningAsTest)' == ''">
|
||||
<!-- We don't want to run build server when not running as tests. -->
|
||||
<UseRazorBuildServer>false</UseRazorBuildServer>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- DO NOT add addition references here. This is meant to simulate a non-MVC library -->
|
||||
<ItemGroup Condition="'$(BinariesRoot)'==''">
|
||||
<!-- In test scenarios $(BinariesRoot) is defined in a generated Directory.Build.props file -->
|
||||
<ProjectReference Include="..\..\Microsoft.AspNetCore.Razor.Test.ComponentShim\Microsoft.AspNetCore.Razor.Test.ComponentShim.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(BinariesRoot)'!=''">
|
||||
<Reference Include="$(BinariesRoot)\Microsoft.AspNetCore.Razor.Test.ComponentShim.dll"/>
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Test Placeholder -->
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
@*
|
||||
The Router component displays whichever component has a @page
|
||||
directive matching the current URI.
|
||||
*@
|
||||
<Router AppAssembly="typeof(Startup).Assembly" />
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
@page "/counter"
|
||||
|
||||
<h1>Counter</h1>
|
||||
|
||||
<p>Current count: @currentCount</p>
|
||||
|
||||
<button class="btn btn-primary" onclick="@IncrementCount">Click me</button>
|
||||
|
||||
@functions {
|
||||
int currentCount = 0;
|
||||
|
||||
void IncrementCount()
|
||||
{
|
||||
currentCount++;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
@page "/fetchdata"
|
||||
@using ComponentApp.Services
|
||||
@inject WeatherForecastService ForecastService
|
||||
|
||||
<h1>Weather forecast</h1>
|
||||
|
||||
<p>This component demonstrates fetching data from a service.</p>
|
||||
|
||||
@if (forecasts == null)
|
||||
{
|
||||
<p><em>Loading...</em></p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Temp. (C)</th>
|
||||
<th>Temp. (F)</th>
|
||||
<th>Summary</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var forecast in forecasts)
|
||||
{
|
||||
<tr>
|
||||
<td>@forecast.Date.ToShortDateString()</td>
|
||||
<td>@forecast.TemperatureC</td>
|
||||
<td>@forecast.TemperatureF</td>
|
||||
<td>@forecast.Summary</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
|
||||
@functions {
|
||||
WeatherForecast[] forecasts;
|
||||
|
||||
protected override async Task OnInitAsync()
|
||||
{
|
||||
forecasts = await ForecastService.GetForecastAsync(DateTime.Now);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
@page "/"
|
||||
|
||||
<h1>Hello, world!</h1>
|
||||
|
||||
Welcome to your new app.
|
||||
|
|
@ -0,0 +1 @@
|
|||
@layout MainLayout
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
<div class="sidebar">
|
||||
<NavMenu />
|
||||
</div>
|
||||
|
||||
<div class="main">
|
||||
<div class="top-row px-4">
|
||||
<a href="https://docs.microsoft.com/en-us/aspnet/" target="_blank" class="ml-md-auto">About</a>
|
||||
</div>
|
||||
|
||||
<div class="content px-4">
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
<div class="top-row pl-4 navbar navbar-dark">
|
||||
<a class="navbar-brand" href="">ComponentApp</a>
|
||||
<button class="navbar-toggler" onclick="@ToggleNavMenu">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="@NavMenuCssClass" onclick="@ToggleNavMenu">
|
||||
<ul class="nav flex-column">
|
||||
<li class="nav-item px-3">
|
||||
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
|
||||
<span class="oi oi-home" aria-hidden="true"></span> Home
|
||||
</NavLink>
|
||||
</li>
|
||||
<li class="nav-item px-3">
|
||||
<NavLink class="nav-link" href="counter">
|
||||
<span class="oi oi-plus" aria-hidden="true"></span> Counter
|
||||
</NavLink>
|
||||
</li>
|
||||
<li class="nav-item px-3">
|
||||
<NavLink class="nav-link" href="fetchdata">
|
||||
<span class="oi oi-list-rich" aria-hidden="true"></span> Fetch data
|
||||
</NavLink>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@functions {
|
||||
bool collapseNavMenu = true;
|
||||
|
||||
string NavMenuCssClass => collapseNavMenu ? "collapse" : null;
|
||||
|
||||
void ToggleNavMenu()
|
||||
{
|
||||
collapseNavMenu = !collapseNavMenu;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
@using ComponentApp.Components.Shared
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
namespace ComponentApp
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
|
@ -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<WeatherForecast[]> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,10 +7,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
|
||||
<_EnableAllInclusiveRazorSdk>true</_EnableAllInclusiveRazorSdk>
|
||||
<RazorLangVersion>3.0</RazorLangVersion>
|
||||
<RazorDefaultConfiguration>MVC-3.0</RazorDefaultConfiguration>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(RunningAsTest)' == ''">
|
||||
|
|
@ -28,10 +25,6 @@
|
|||
<Reference Include="$(BinariesRoot)\Microsoft.AspNetCore.Razor.Test.ComponentShim.dll"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectCapability Include="DotNetCoreRazorConfiguration" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Test Placeholder -->
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -2,9 +2,21 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<RazorSdkDirectoryRoot>$(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\</RazorSdkDirectoryRoot>
|
||||
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
|
||||
</PropertyGroup>
|
||||
|
||||
<!--
|
||||
The AspNetCore repo depends on AspNetCore-Tooling, and we want to avoid creating a cylical dependency between the two
|
||||
by adding a reference to Microsoft.AspNetCore.App. We'll instead simulate the presence of the reference.
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
|
||||
<_ReferencesAspNetCoreApp>true</_ReferencesAspNetCoreApp>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.NETCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
|
@ -14,10 +26,6 @@
|
|||
<UseRazorBuildServer>false</UseRazorBuildServer>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.NETCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(BinariesRoot)'==''">
|
||||
<!-- In test scenarios $(BinariesRoot) is defined in a generated Directory.Build.props file -->
|
||||
<ProjectReference Include="..\..\Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib\Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib.csproj"/>
|
||||
|
|
|
|||
|
|
@ -2,10 +2,18 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<RazorSdkDirectoryRoot>$(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\</RazorSdkDirectoryRoot>
|
||||
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
|
||||
<_RazorComponentInclude>Components\**\*.cshtml</_RazorComponentInclude>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
|
||||
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.NETCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
|
@ -15,10 +23,6 @@
|
|||
<UseRazorBuildServer>false</UseRazorBuildServer>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.NETCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(BinariesRoot)'==''">
|
||||
<!-- In test scenarios $(BinariesRoot) is defined in a generated Directory.Build.props file -->
|
||||
<ProjectReference Include="..\..\Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib\Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib.csproj"/>
|
||||
|
|
|
|||
|
|
@ -33,4 +33,9 @@
|
|||
<Target Name="_IntrospectProjectCapabilityItems">
|
||||
<Message Text="ProjectCapability: %(ProjectCapability.Identity)" Importance="High" />
|
||||
</Target>
|
||||
|
||||
<Target Name="_IntrospectResolvedConfiguration">
|
||||
<Message Text="RazorLangVersion: $(RazorLangVersion)" Importance="High" />
|
||||
<Message Text="ResolvedRazorConfiguration: @(ResolvedRazorConfiguration)" Importance="High" />
|
||||
</Target>
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
<ProjectReference Include="..\ClassLibrary2\ClassLibrary2.csproj" />
|
||||
<ProjectReference Include="..\ClassLibraryMvc21\ClassLibraryMvc21.csproj" />
|
||||
<ProjectReference Include="..\ComponentLibrary\ComponentLibrary.csproj" />
|
||||
<ProjectReference Include="..\ComponentApp\ComponentApp.csproj" />
|
||||
<ProjectReference Include="..\LargeProject\LargeProject.csproj" />
|
||||
<ProjectReference Include="..\SimpleMvcFSharp\SimpleMvcFSharp.fsproj" />
|
||||
<ProjectReference Include="..\SimpleMvc\SimpleMvc.csproj" />
|
||||
|
|
|
|||
|
|
@ -1,10 +1,18 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
|
||||
<PropertyGroup>
|
||||
<RazorSdkDirectoryRoot>$(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\</RazorSdkDirectoryRoot>
|
||||
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
|
||||
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.NETCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
|
@ -14,10 +22,6 @@
|
|||
<UseRazorBuildServer>false</UseRazorBuildServer>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.NETCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(BinariesRoot)'==''">
|
||||
<!-- In test scenarios $(BinariesRoot) is defined in a generated Directory.Build.props file -->
|
||||
<ProjectReference Include="..\..\Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib\Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib.csproj"/>
|
||||
|
|
|
|||
|
|
@ -2,9 +2,16 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<RazorSdkDirectoryRoot>$(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\</RazorSdkDirectoryRoot>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.NETCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
|
@ -19,10 +26,6 @@
|
|||
<Compile Include="Program.fs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.NETCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(BinariesRoot)'==''">
|
||||
<!-- In test scenarios $(BinariesRoot) is defined in a generated Directory.Build.props file -->
|
||||
<ProjectReference Include="..\..\Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib\Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib.csproj"/>
|
||||
|
|
@ -31,7 +34,7 @@
|
|||
<ItemGroup Condition="'$(BinariesRoot)'!=''">
|
||||
<Reference Include="$(BinariesRoot)\Microsoft.AspNetCore.Razor.Test.ComponentShim.dll"/>
|
||||
<Reference Include="$(BinariesRoot)\Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib.dll"/>
|
||||
</ItemGroup>
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Test Placeholder -->
|
||||
|
||||
|
|
|
|||
|
|
@ -2,9 +2,17 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<RazorSdkDirectoryRoot>$(RazorSdkArtifactsDirectory)$(Configuration)\sdk-output\</RazorSdkDirectoryRoot>
|
||||
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
|
||||
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.NETCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
|
@ -14,10 +22,6 @@
|
|||
<UseRazorBuildServer>false</UseRazorBuildServer>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.NETCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(BinariesRoot)'==''">
|
||||
<!-- In test scenarios $(BinariesRoot) is defined in a generated Directory.Build.props file -->
|
||||
<ProjectReference Include="..\..\Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib\Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib.csproj"/>
|
||||
|
|
@ -29,5 +33,5 @@
|
|||
</ItemGroup>
|
||||
|
||||
<!-- Test Placeholder -->
|
||||
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
Loading…
Reference in New Issue