Continue generating RelatedAssemblyPart on assembly if GenerateAssemblyInfo=false

Fixes #2257
This commit is contained in:
Pranav K 2018-04-12 14:42:25 -07:00
parent 60b6ec047d
commit 95835d6c37
7 changed files with 237 additions and 158 deletions

View File

@ -1,11 +1,14 @@
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<!--
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)'==''">true</GenerateRazorAssemblyInfo>
<!-- <!--
MVC will generally want to add support for runtime compilation, but only for applications. MVC will generally want to add support for runtime compilation, but only for applications.
--> -->
<GenerateRazorAssemblyInfo Condition="'$(GenerateRazorAssemblyInfo)'==''">true</GenerateRazorAssemblyInfo>
<GenerateRazorHostingAssemblyInfo Condition="'$(GenerateRazorHostingAssemblyInfo)'=='' AND '$(OutputType)'=='exe'">$(GenerateRazorAssemblyInfo)</GenerateRazorHostingAssemblyInfo> <GenerateRazorHostingAssemblyInfo Condition="'$(GenerateRazorHostingAssemblyInfo)'=='' AND '$(OutputType)'=='exe'">$(GenerateRazorAssemblyInfo)</GenerateRazorHostingAssemblyInfo>
<!-- <!--
@ -20,14 +23,14 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup Condition="'$(GenerateRazorAssemblyInfo)'=='true' AND '$(ResolvedRazorCompileToolset)'=='RazorSdk' AND ('$(RazorCompileOnBuild)' == 'true' OR '$(RazorCompileOnPublish)' == 'true')"> <ItemGroup Condition="'$(GenerateRazorAssemblyInfo)'=='true' AND '$(ResolvedRazorCompileToolset)'=='RazorSdk' AND ('$(RazorCompileOnBuild)' == 'true' OR '$(RazorCompileOnPublish)' == 'true')">
<AssemblyAttribute Include="Microsoft.AspNetCore.Mvc.ApplicationParts.RelatedAssemblyAttribute"> <_RazorAssemblyAttribute Include="Microsoft.AspNetCore.Mvc.ApplicationParts.RelatedAssemblyAttribute">
<_Parameter1>$(RazorTargetName)</_Parameter1> <_Parameter1>$(RazorTargetName)</_Parameter1>
</AssemblyAttribute> </_RazorAssemblyAttribute>
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(GenerateProvideApplicationPartFactoryAttribute)' == 'true' AND '$(ProvideApplicationPartFactoryAttributeTypeName)'!=''"> <ItemGroup Condition="'$(GenerateProvideApplicationPartFactoryAttribute)' == 'true' AND '$(ProvideApplicationPartFactoryAttributeTypeName)'!=''">
<RazorAssemblyAttribute Include="Microsoft.AspNetCore.Mvc.ApplicationParts.ProvideApplicationPartFactoryAttribute"> <RazorTargetAssemblyAttribute Include="Microsoft.AspNetCore.Mvc.ApplicationParts.ProvideApplicationPartFactoryAttribute">
<_Parameter1>$(ProvideApplicationPartFactoryAttributeTypeName)</_Parameter1> <_Parameter1>$(ProvideApplicationPartFactoryAttributeTypeName)</_Parameter1>
</RazorAssemblyAttribute> </RazorTargetAssemblyAttribute>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -12,53 +12,55 @@ Copyright (c) .NET Foundation. All rights reserved.
<Project ToolsVersion="14.0"> <Project ToolsVersion="14.0">
<PropertyGroup> <PropertyGroup>
<!-- Determines if the generated Razor assembly includes an auto-generated assembly info. --> <!-- Determines if the generated Razor assembly includes an auto-generated assembly info. -->
<GenerateRazorTargetAssemblyInfo Condition="'$(GenerateRazorTargetAssemblyInfo)'==''">$(GenerateAssemblyInfo)</GenerateRazorTargetAssemblyInfo>
<GenerateRazorTargetAssemblyInfo Condition="'$(GenerateRazorTargetAssemblyInfo)'==''">true</GenerateRazorTargetAssemblyInfo> <GenerateRazorTargetAssemblyInfo Condition="'$(GenerateRazorTargetAssemblyInfo)'==''">true</GenerateRazorTargetAssemblyInfo>
<!-- Set to true, to automatically include some AssemblyAttributes inferred from the project metadata in the generated Razor assembly --> <!-- Set to true, to automatically include some AssemblyAttributes inferred from the project metadata in the generated Razor assembly -->
<EnableDefaultRazorTargetAssemblyInfoAttributes Condition="'$(EnableDefaultRazorTargetAssemblyInfoAttributes)'==''">true</EnableDefaultRazorTargetAssemblyInfoAttributes> <EnableDefaultRazorTargetAssemblyInfoAttributes Condition="'$(EnableDefaultRazorTargetAssemblyInfoAttributes)'==''">true</EnableDefaultRazorTargetAssemblyInfoAttributes>
<GeneratedRazorTargetAssemblyInfo Condition="'$(GeneratedRazorTargetAssemblyInfo)'==''">$(IntermediateOutputPath)$(MSBuildProjectName).RazorAssemblyInfo.cs</GeneratedRazorTargetAssemblyInfo> <!-- AssemblyInfo that gets added to the generated Razor dll -->
<RazorTargetAssemblyInfo Condition="'$(RazorTargetAssemblyInfo)'==''">$(IntermediateOutputPath)$(MSBuildProjectName).RazorTargetAssemblyInfo.cs</RazorTargetAssemblyInfo>
<_RazorTargetAssemblyInfoInputsCacheFile>$(IntermediateOutputPath)$(MSBuildProjectName).RazorTargetAssemblyInfo.cache</_RazorTargetAssemblyInfoInputsCacheFile>
<_GeneratedRazorAssemblyInfoInputsCacheFile>$(IntermediateOutputPath)$(MSBuildProjectName).RazorAssemblyInfoInputs.cache</_GeneratedRazorAssemblyInfoInputsCacheFile> <!-- AssemblyInfo that gets added to the project being compiled -->
<_RazorAssemblyInfo>$(IntermediateOutputPath)$(MSBuildProjectName).RazorAssemblyInfo.cs</_RazorAssemblyInfo>
<_RazorAssemblyInfoInputsCacheFile>$(IntermediateOutputPath)$(MSBuildProjectName).RazorAssemblyInfo.cache</_RazorAssemblyInfoInputsCacheFile>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<GenerateRazorAssemblyInfoDependsOn> <GenerateRazorTargetAssemblyInfoDependsOn>
GetRazorAssemblyAttributes; GetRazorTargetAssemblyAttributes;
CreateRazorGeneratedAssemblyInfoInputsCacheFile; _CreateRazorTargetAssemblyInfoInputsCacheFile;
CoreGenerateRazorAssemblyInfo CoreGenerateRazorTargetAssemblyInfo
</GenerateRazorAssemblyInfoDependsOn> </GenerateRazorTargetAssemblyInfoDependsOn>
</PropertyGroup> </PropertyGroup>
<Target <Target
Name="GenerateRazorAssemblyInfo" Name="GenerateRazorTargetAssemblyInfo"
DependsOnTargets="$(GenerateRazorAssemblyInfoDependsOn)" DependsOnTargets="$(GenerateRazorTargetAssemblyInfoDependsOn)">
Condition="'$(GenerateRazorTargetAssemblyInfo)'=='true'">
</Target> </Target>
<Target <Target
Name="CoreGenerateRazorAssemblyInfo" Name="CoreGenerateRazorTargetAssemblyInfo"
Inputs="$(_GeneratedRazorAssemblyInfoInputsCacheFile)" Inputs="$(_RazorTargetAssemblyInfoInputsCacheFile)"
Outputs="$(GeneratedRazorTargetAssemblyInfo)" Outputs="$(RazorTargetAssemblyInfo)"
Condition="'@(RazorCompile)'!=''"> Condition="'$(GenerateRazorTargetAssemblyInfo)'=='true' AND '@(RazorCompile)'!=''">
<ItemGroup Condition="'$(GenerateRazorTargetAssemblyInfo)'=='true'"> <ItemGroup Condition="'$(GenerateRazorTargetAssemblyInfo)'=='true'">
<!-- Ensure the generated assemblyinfo file is not already part of RazorCompile sources --> <!-- Ensure the generated assemblyinfo file is not already part of RazorCompile sources -->
<RazorCompile Remove="$(GeneratedRazorTargetAssemblyInfo)" /> <RazorCompile Remove="$(RazorTargetAssemblyInfo)" />
<RazorCompile Include="$(GeneratedRazorTargetAssemblyInfo)" /> <RazorCompile Include="$(RazorTargetAssemblyInfo)" />
</ItemGroup> </ItemGroup>
<WriteCodeFragment AssemblyAttributes="@(RazorAssemblyAttribute)" Language="C#" OutputFile="$(GeneratedRazorTargetAssemblyInfo)" /> <WriteCodeFragment AssemblyAttributes="@(RazorTargetAssemblyAttribute)" Language="C#" OutputFile="$(RazorTargetAssemblyInfo)" />
<ItemGroup> <ItemGroup>
<FileWrites Include="$(GeneratedRazorTargetAssemblyInfo)" /> <FileWrites Include="$(RazorTargetAssemblyInfo)" />
</ItemGroup> </ItemGroup>
</Target> </Target>
<Target <Target
Name="GetRazorAssemblyAttributes" Name="GetRazorTargetAssemblyAttributes"
DependsOnTargets="GetAssemblyVersion" DependsOnTargets="GetAssemblyVersion"
Condition="'$(EnableDefaultRazorTargetAssemblyInfoAttributes)'=='true'"> Condition="'$(EnableDefaultRazorTargetAssemblyInfoAttributes)'=='true'">
@ -71,37 +73,37 @@ Copyright (c) .NET Foundation. All rights reserved.
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<RazorAssemblyAttribute Include="System.Reflection.AssemblyCompanyAttribute" Condition="'$(Company)' != '' and '$(GenerateAssemblyCompanyAttribute)' == 'true'"> <RazorTargetAssemblyAttribute Include="System.Reflection.AssemblyCompanyAttribute" Condition="'$(Company)' != '' and '$(GenerateAssemblyCompanyAttribute)' == 'true'">
<_Parameter1>$(Company)</_Parameter1> <_Parameter1>$(Company)</_Parameter1>
</RazorAssemblyAttribute> </RazorTargetAssemblyAttribute>
<RazorAssemblyAttribute Include="System.Reflection.AssemblyConfigurationAttribute" Condition="'$(Configuration)' != '' and '$(GenerateAssemblyConfigurationAttribute)' == 'true'"> <RazorTargetAssemblyAttribute Include="System.Reflection.AssemblyConfigurationAttribute" Condition="'$(Configuration)' != '' and '$(GenerateAssemblyConfigurationAttribute)' == 'true'">
<_Parameter1>$(Configuration)</_Parameter1> <_Parameter1>$(Configuration)</_Parameter1>
</RazorAssemblyAttribute> </RazorTargetAssemblyAttribute>
<RazorAssemblyAttribute Include="System.Reflection.AssemblyCopyrightAttribute" Condition="'$(Copyright)' != '' and '$(GenerateAssemblyCopyrightAttribute)' == 'true'"> <RazorTargetAssemblyAttribute Include="System.Reflection.AssemblyCopyrightAttribute" Condition="'$(Copyright)' != '' and '$(GenerateAssemblyCopyrightAttribute)' == 'true'">
<_Parameter1>$(Copyright)</_Parameter1> <_Parameter1>$(Copyright)</_Parameter1>
</RazorAssemblyAttribute> </RazorTargetAssemblyAttribute>
<RazorAssemblyAttribute Include="System.Reflection.AssemblyProductAttribute" Condition="'$(Product)' != '' and '$(GenerateAssemblyProductAttribute)' == 'true'"> <RazorTargetAssemblyAttribute Include="System.Reflection.AssemblyProductAttribute" Condition="'$(Product)' != '' and '$(GenerateAssemblyProductAttribute)' == 'true'">
<_Parameter1>$(Product)</_Parameter1> <_Parameter1>$(Product)</_Parameter1>
</RazorAssemblyAttribute> </RazorTargetAssemblyAttribute>
<RazorAssemblyAttribute Include="System.Resources.NeutralResourcesLanguageAttribute" Condition="'$(NeutralLanguage)' != '' and '$(GenerateNeutralResourcesLanguageAttribute)' == 'true'"> <RazorTargetAssemblyAttribute Include="System.Resources.NeutralResourcesLanguageAttribute" Condition="'$(NeutralLanguage)' != '' and '$(GenerateNeutralResourcesLanguageAttribute)' == 'true'">
<_Parameter1>$(NeutralLanguage)</_Parameter1> <_Parameter1>$(NeutralLanguage)</_Parameter1>
</RazorAssemblyAttribute> </RazorTargetAssemblyAttribute>
<RazorAssemblyAttribute Include="System.Reflection.AssemblyDescriptionAttribute" Condition="'$(RazorAssemblyDescription)' != '' and '$(GenerateAssemblyDescriptionAttribute)' == 'true'"> <RazorTargetAssemblyAttribute Include="System.Reflection.AssemblyDescriptionAttribute" Condition="'$(RazorAssemblyDescription)' != '' and '$(GenerateAssemblyDescriptionAttribute)' == 'true'">
<_Parameter1>$(RazorAssemblyDescription)</_Parameter1> <_Parameter1>$(RazorAssemblyDescription)</_Parameter1>
</RazorAssemblyAttribute> </RazorTargetAssemblyAttribute>
<RazorAssemblyAttribute Include="System.Reflection.AssemblyFileVersionAttribute" Condition="'$(RazorAssemblyFileVersion)' != '' and '$(GenerateAssemblyFileVersionAttribute)' == 'true'"> <RazorTargetAssemblyAttribute Include="System.Reflection.AssemblyFileVersionAttribute" Condition="'$(RazorAssemblyFileVersion)' != '' and '$(GenerateAssemblyFileVersionAttribute)' == 'true'">
<_Parameter1>$(RazorAssemblyFileVersion)</_Parameter1> <_Parameter1>$(RazorAssemblyFileVersion)</_Parameter1>
</RazorAssemblyAttribute> </RazorTargetAssemblyAttribute>
<RazorAssemblyAttribute Include="System.Reflection.AssemblyInformationalVersionAttribute" Condition="'$(RazorAssemblyInformationalVersion)' != '' and '$(GenerateAssemblyInformationalVersionAttribute)' == 'true'"> <RazorTargetAssemblyAttribute Include="System.Reflection.AssemblyInformationalVersionAttribute" Condition="'$(RazorAssemblyInformationalVersion)' != '' and '$(GenerateAssemblyInformationalVersionAttribute)' == 'true'">
<_Parameter1>$(RazorAssemblyInformationalVersion)</_Parameter1> <_Parameter1>$(RazorAssemblyInformationalVersion)</_Parameter1>
</RazorAssemblyAttribute> </RazorTargetAssemblyAttribute>
<RazorAssemblyAttribute Include="System.Reflection.AssemblyTitleAttribute" Condition="'$(RazorAssemblyTitle)' != '' and '$(GenerateAssemblyTitleAttribute)' == 'true'"> <RazorTargetAssemblyAttribute Include="System.Reflection.AssemblyTitleAttribute" Condition="'$(RazorAssemblyTitle)' != '' and '$(GenerateAssemblyTitleAttribute)' == 'true'">
<_Parameter1>$(RazorAssemblyTitle)</_Parameter1> <_Parameter1>$(RazorAssemblyTitle)</_Parameter1>
</RazorAssemblyAttribute> </RazorTargetAssemblyAttribute>
<RazorAssemblyAttribute Include="System.Reflection.AssemblyVersionAttribute" Condition="'$(RazorAssemblyVersion)' != '' and '$(GenerateAssemblyVersionAttribute)' == 'true'"> <RazorTargetAssemblyAttribute Include="System.Reflection.AssemblyVersionAttribute" Condition="'$(RazorAssemblyVersion)' != '' and '$(GenerateAssemblyVersionAttribute)' == 'true'">
<_Parameter1>$(RazorAssemblyVersion)</_Parameter1> <_Parameter1>$(RazorAssemblyVersion)</_Parameter1>
</RazorAssemblyAttribute> </RazorTargetAssemblyAttribute>
</ItemGroup> </ItemGroup>
</Target> </Target>
@ -111,23 +113,73 @@ Copyright (c) .NET Foundation. All rights reserved.
create a hash of all assembly attributes so that the cache file will change with the calculated create a hash of all assembly attributes so that the cache file will change with the calculated
assembly attribute values and msbuild will then execute CoreGenerateAssembly to generate a new file. assembly attribute values and msbuild will then execute CoreGenerateAssembly to generate a new file.
--> -->
<Target Name="CreateRazorGeneratedAssemblyInfoInputsCacheFile" Condition="'@(RazorAssemblyAttribute)' != ''"> <Target Name="_CreateRazorTargetAssemblyInfoInputsCacheFile" Condition="'@(RazorTargetAssemblyAttribute)' != ''">
<!-- We only use up to _Parameter1 for most attributes, but other targets may add additional assembly attributes with multiple parameters. --> <!-- We only use up to _Parameter1 for most attributes, but other targets may add additional assembly attributes with multiple parameters. -->
<Hash ItemsToHash="@(RazorAssemblyAttribute->'%(Identity)%(_Parameter1)%(_Parameter2)%(_Parameter3)%(_Parameter4)%(_Parameter5)%(_Parameter6)%(_Parameter7)%(_Parameter8)')"> <Hash ItemsToHash="@(RazorTargetAssemblyAttribute->'%(Identity)%(_Parameter1)%(_Parameter2)%(_Parameter3)%(_Parameter4)%(_Parameter5)%(_Parameter6)%(_Parameter7)%(_Parameter8)')">
<Output TaskParameter="HashResult" PropertyName="_RazorTargetAssemblyAttributesHash" />
</Hash>
<WriteLinesToFile
Lines="$(_RazorTargetAssemblyAttributesHash)"
File="$(_RazorTargetAssemblyInfoInputsCacheFile)"
Overwrite="True"
WriteOnlyWhenDifferent="True" />
<ItemGroup>
<FileWrites Include="$(_RazorTargetAssemblyInfoInputsCacheFile)" />
</ItemGroup>
</Target>
<Target Name="_CreateRazorAssemblyInfoInputsCacheFile" Condition="'@(_RazorAssemblyAttribute)' != ''">
<!-- We only use up to _Parameter1 for most attributes, but other targets may add additional assembly attributes with multiple parameters. -->
<Hash ItemsToHash="@(_RazorAssemblyAttribute->'%(Identity)%(_Parameter1)%(_Parameter2)%(_Parameter3)%(_Parameter4)%(_Parameter5)%(_Parameter6)%(_Parameter7)%(_Parameter8)')">
<Output TaskParameter="HashResult" PropertyName="_RazorAssemblyAttributesHash" /> <Output TaskParameter="HashResult" PropertyName="_RazorAssemblyAttributesHash" />
</Hash> </Hash>
<WriteLinesToFile <WriteLinesToFile
Lines="$(_RazorAssemblyAttributesHash)" Lines="$(_RazorAssemblyAttributesHash)"
File="$(_GeneratedRazorAssemblyInfoInputsCacheFile)" File="$(_RazorAssemblyInfoInputsCacheFile)"
Overwrite="True" Overwrite="True"
WriteOnlyWhenDifferent="True" /> WriteOnlyWhenDifferent="True" />
<ItemGroup> <ItemGroup>
<FileWrites Include="$(_GeneratedRazorAssemblyInfoInputsCacheFile)" /> <FileWrites Include="$(_RazorAssemblyInfoInputsCacheFile)" />
</ItemGroup> </ItemGroup>
</Target> </Target>
<Target
Name="_CoreGenerateRazorAssemblyInfo"
DependsOnTargets="_CreateRazorAssemblyInfoInputsCacheFile"
Inputs="$(_RazorAssemblyInfoInputsCacheFile)"
Outputs="$(_RazorAssemblyInfo)"
Condition="'@(_RazorAssemblyAttribute)' != ''">
<ItemGroup Condition="'$(GenerateRazorAssemblyInfo)'=='true'">
<Compile Remove="$(_RazorAssemblyInfo)" />
<Compile Include="$(_RazorAssemblyInfo)" />
</ItemGroup>
<WriteCodeFragment AssemblyAttributes="@(_RazorAssemblyAttribute)" Language="$(Language)" OutputFile="$(_RazorAssemblyInfo)" />
<ItemGroup>
<FileWrites Include="$(_RazorAssemblyInfo)" />
</ItemGroup>
</Target>
<PropertyGroup>
<!-- Generate attributes in the main assembly if we're targeting a C# project and using the Razor Sdk. -->
<CoreCompileDependsOn Condition="'$(ResolvedRazorCompileToolset)'=='RazorSdk' and '$(Language)' == 'C#' and '$(GenerateRazorAssemblyInfo)' == 'true'">
$(CoreCompileDependsOn);_GenerateRazorAssemblyInfo
</CoreCompileDependsOn>
<_GenerateRazorAssemblyInfoDependsOn>PrepareForBuild;_CoreGenerateRazorAssemblyInfo</_GenerateRazorAssemblyInfoDependsOn>
</PropertyGroup>
<Target Name="_GenerateRazorAssemblyInfo" DependsOnTargets="$(_GenerateRazorAssemblyInfoDependsOn)" />
</Project> </Project>

View File

@ -47,7 +47,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<PrepareForRazorCompileDependsOn> <PrepareForRazorCompileDependsOn>
RazorGenerate; RazorGenerate;
ResolveRazorCompileInputs; ResolveRazorCompileInputs;
GenerateRazorAssemblyInfo GenerateRazorTargetAssemblyInfo
</PrepareForRazorCompileDependsOn> </PrepareForRazorCompileDependsOn>
<ResolveRazorCompileInputsDependsOn> <ResolveRazorCompileInputsDependsOn>
@ -230,7 +230,7 @@ Copyright (c) .NET Foundation. All rights reserved.
</Target> </Target>
<!-- <!--
Generates assembly attributes in support for Razor runtime code generation. This is a set of standard Gets assembly attributes in support for Razor runtime code generation. This is a set of standard
metadata attributes (defined in Microsoft.AspNetCore.Razor.Runtime) that capture the build-time metadata attributes (defined in Microsoft.AspNetCore.Razor.Runtime) that capture the build-time
Razor configuration of an application to be used at runtime. Razor configuration of an application to be used at runtime.
@ -240,22 +240,25 @@ Copyright (c) .NET Foundation. All rights reserved.
The SDK expects configurations that use runtime compilation to set $(GenerateRazorHostingAssemblyInfo) to true, The SDK expects configurations that use runtime compilation to set $(GenerateRazorHostingAssemblyInfo) to true,
it will be unset by default. it will be unset by default.
--> -->
<PropertyGroup>
<_GenerateRazorAssemblyInfoDependsOn>RazorGetAssemblyAttributes;$(_GenerateRazorAssemblyInfoDependsOn)</_GenerateRazorAssemblyInfoDependsOn>
</PropertyGroup>
<Target <Target
Name="RazorGetAssemblyAttributes" Name="RazorGetAssemblyAttributes"
AfterTargets="GetAssemblyAttributes"
Condition="'$(GenerateRazorHostingAssemblyInfo)'=='true' and '$(RazorDefaultConfiguration)'!=''" Condition="'$(GenerateRazorHostingAssemblyInfo)'=='true' and '$(RazorDefaultConfiguration)'!=''"
DependsOnTargets="ResolveRazorConfiguration"> DependsOnTargets="ResolveRazorConfiguration">
<ItemGroup> <ItemGroup>
<AssemblyAttribute Include="Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute"> <_RazorAssemblyAttribute Include="Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute">
<_Parameter1>$(RazorLangVersion)</_Parameter1> <_Parameter1>$(RazorLangVersion)</_Parameter1>
</AssemblyAttribute> </_RazorAssemblyAttribute>
<AssemblyAttribute Include="Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute"> <_RazorAssemblyAttribute Include="Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute">
<_Parameter1>$(RazorDefaultConfiguration)</_Parameter1> <_Parameter1>$(RazorDefaultConfiguration)</_Parameter1>
</AssemblyAttribute> </_RazorAssemblyAttribute>
<AssemblyAttribute Include="Microsoft.AspNetCore.Razor.Hosting.RazorExtensionAssemblyNameAttribute" Condition="'%(ResolvedRazorExtension.AssemblyName)'!=''"> <_RazorAssemblyAttribute Include="Microsoft.AspNetCore.Razor.Hosting.RazorExtensionAssemblyNameAttribute" Condition="'%(ResolvedRazorExtension.AssemblyName)'!=''">
<_Parameter1>%(ResolvedRazorExtension.Identity)</_Parameter1> <_Parameter1>%(ResolvedRazorExtension.Identity)</_Parameter1>
<_Parameter2>%(ResolvedRazorExtension.AssemblyName)</_Parameter2> <_Parameter2>%(ResolvedRazorExtension.AssemblyName)</_Parameter2>
</AssemblyAttribute> </_RazorAssemblyAttribute>
</ItemGroup> </ItemGroup>
</Target> </Target>

View File

@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;

View File

@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.Views.dll"); Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.Views.dll");
Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.Views.pdb"); Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.Views.pdb");
Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.RazorAssemblyInfo.cs"); Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.RazorTargetAssemblyInfo.cs");
} }
[Fact] [Fact]
@ -260,27 +260,27 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
[InitializeTestProject("ClassLibrary")] [InitializeTestProject("ClassLibrary")]
public async Task Build_CodeGensAssemblyInfoUsingValuesFromProject() public async Task Build_CodeGensAssemblyInfoUsingValuesFromProject()
{ {
var assemblyInfoPath = Path.Combine(IntermediateOutputPath, "ClassLibrary.RazorAssemblyInfo.cs"); var razorAssemblyInfoPath = Path.Combine(IntermediateOutputPath, "ClassLibrary.RazorTargetAssemblyInfo.cs");
var result = await DotnetMSBuild("Build"); var result = await DotnetMSBuild("Build");
Assert.BuildPassed(result); Assert.BuildPassed(result);
Assert.FileExists(result, assemblyInfoPath); Assert.FileExists(result, razorAssemblyInfoPath);
Assert.FileContains(result, assemblyInfoPath, "[assembly: System.Reflection.AssemblyCopyrightAttribute(\"© Microsoft\")]"); Assert.FileContains(result, razorAssemblyInfoPath, "[assembly: System.Reflection.AssemblyCopyrightAttribute(\"© Microsoft\")]");
Assert.FileContains(result, assemblyInfoPath, "[assembly: System.Reflection.AssemblyProductAttribute(\"Razor Test\")]"); Assert.FileContains(result, razorAssemblyInfoPath, "[assembly: System.Reflection.AssemblyProductAttribute(\"Razor Test\")]");
Assert.FileContains(result, assemblyInfoPath, "[assembly: System.Reflection.AssemblyCompanyAttribute(\"Microsoft\")]"); Assert.FileContains(result, razorAssemblyInfoPath, "[assembly: System.Reflection.AssemblyCompanyAttribute(\"Microsoft\")]");
Assert.FileContains(result, assemblyInfoPath, "[assembly: System.Reflection.AssemblyTitleAttribute(\"ClassLibrary.Views\")]"); Assert.FileContains(result, razorAssemblyInfoPath, "[assembly: System.Reflection.AssemblyTitleAttribute(\"ClassLibrary.Views\")]");
Assert.FileContains(result, assemblyInfoPath, "[assembly: System.Reflection.AssemblyVersionAttribute(\"1.0.0.0\")]"); Assert.FileContains(result, razorAssemblyInfoPath, "[assembly: System.Reflection.AssemblyVersionAttribute(\"1.0.0.0\")]");
Assert.FileContains(result, assemblyInfoPath, "[assembly: System.Reflection.AssemblyFileVersionAttribute(\"1.0.0.0\")]"); Assert.FileContains(result, razorAssemblyInfoPath, "[assembly: System.Reflection.AssemblyFileVersionAttribute(\"1.0.0.0\")]");
Assert.FileContains(result, assemblyInfoPath, "[assembly: System.Reflection.AssemblyInformationalVersionAttribute(\"1.0.0\")]"); Assert.FileContains(result, razorAssemblyInfoPath, "[assembly: System.Reflection.AssemblyInformationalVersionAttribute(\"1.0.0\")]");
Assert.FileContains(result, assemblyInfoPath, "[assembly: System.Reflection.AssemblyDescriptionAttribute(\"ClassLibrary Description\")]"); Assert.FileContains(result, razorAssemblyInfoPath, "[assembly: System.Reflection.AssemblyDescriptionAttribute(\"ClassLibrary Description\")]");
} }
[Fact] [Fact]
[InitializeTestProject("ClassLibrary")] [InitializeTestProject("ClassLibrary")]
public async Task Build_UsesRazorSpecificAssemblyProperties() public async Task Build_UsesRazorSpecificAssemblyProperties()
{ {
var assemblyInfoPath = Path.Combine(IntermediateOutputPath, "ClassLibrary.RazorAssemblyInfo.cs"); var razorTargetAssemblyInfo = Path.Combine(IntermediateOutputPath, "ClassLibrary.RazorTargetAssemblyInfo.cs");
var buildArguments = "/p:RazorAssemblyFileVersion=2.0.0.100 /p:RazorAssemblyInformationalVersion=2.0.0-preview " + var buildArguments = "/p:RazorAssemblyFileVersion=2.0.0.100 /p:RazorAssemblyInformationalVersion=2.0.0-preview " +
"/p:RazorAssemblyTitle=MyRazorViews /p:RazorAssemblyVersion=2.0.0 " + "/p:RazorAssemblyTitle=MyRazorViews /p:RazorAssemblyVersion=2.0.0 " +
"/p:RazorAssemblyDescription=MyRazorDescription"; "/p:RazorAssemblyDescription=MyRazorDescription";
@ -288,172 +288,184 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
Assert.BuildPassed(result); Assert.BuildPassed(result);
Assert.FileExists(result, assemblyInfoPath); Assert.FileExists(result, razorTargetAssemblyInfo);
Assert.FileContains(result, assemblyInfoPath, "[assembly: System.Reflection.AssemblyDescriptionAttribute(\"MyRazorDescription\")]"); Assert.FileContains(result, razorTargetAssemblyInfo, "[assembly: System.Reflection.AssemblyDescriptionAttribute(\"MyRazorDescription\")]");
Assert.FileContains(result, assemblyInfoPath, "[assembly: System.Reflection.AssemblyTitleAttribute(\"MyRazorViews\")]"); Assert.FileContains(result, razorTargetAssemblyInfo, "[assembly: System.Reflection.AssemblyTitleAttribute(\"MyRazorViews\")]");
Assert.FileContains(result, assemblyInfoPath, "[assembly: System.Reflection.AssemblyVersionAttribute(\"2.0.0\")]"); Assert.FileContains(result, razorTargetAssemblyInfo, "[assembly: System.Reflection.AssemblyVersionAttribute(\"2.0.0\")]");
Assert.FileContains(result, assemblyInfoPath, "[assembly: System.Reflection.AssemblyFileVersionAttribute(\"2.0.0.100\")]"); Assert.FileContains(result, razorTargetAssemblyInfo, "[assembly: System.Reflection.AssemblyFileVersionAttribute(\"2.0.0.100\")]");
Assert.FileContains(result, assemblyInfoPath, "[assembly: System.Reflection.AssemblyInformationalVersionAttribute(\"2.0.0-preview\")]"); Assert.FileContains(result, razorTargetAssemblyInfo, "[assembly: System.Reflection.AssemblyInformationalVersionAttribute(\"2.0.0-preview\")]");
} }
[Fact] [Fact]
[InitializeTestProject("ClassLibrary")] [InitializeTestProject("ClassLibrary")]
public async Task Build_DoesNotGenerateAssemblyInfo_IfGenerateRazorTargetAssemblyInfo_IsSetToFalse() public async Task Build_DoesNotGenerateAssemblyInfo_IfGenerateRazorTargetAssemblyInfo_IsSetToFalse()
{ {
var result = await DotnetMSBuild("Build", "/p:GeneratedRazorTargetAssemblyInfo=false"); var result = await DotnetMSBuild("Build", "/p:GenerateRazorTargetAssemblyInfo=false");
Assert.BuildPassed(result); Assert.BuildPassed(result);
Assert.FileExists(result, IntermediateOutputPath, "ClassLibrary.AssemblyInfo.cs"); Assert.FileExists(result, IntermediateOutputPath, "ClassLibrary.AssemblyInfo.cs");
Assert.FileDoesNotExist(result, IntermediateOutputPath, "ClassLibrary.RazorAssemblyInfo.cs"); Assert.FileDoesNotExist(result, IntermediateOutputPath, "ClassLibrary.RazorTargetAssemblyInfo.cs");
} }
[Fact] [Fact]
[InitializeTestProject("SimpleMvc")] [InitializeTestProject("SimpleMvc")]
public async Task Build_AddsApplicationPartAttributes() public async Task Build_AddsApplicationPartAttributes()
{ {
var assemblyInfoPath = Path.Combine(IntermediateOutputPath, "SimpleMvc.AssemblyInfo.cs");
var razorAssemblyInfoPath = Path.Combine(IntermediateOutputPath, "SimpleMvc.RazorAssemblyInfo.cs"); var razorAssemblyInfoPath = Path.Combine(IntermediateOutputPath, "SimpleMvc.RazorAssemblyInfo.cs");
var razorTargetAssemblyInfo = Path.Combine(IntermediateOutputPath, "SimpleMvc.RazorTargetAssemblyInfo.cs");
var result = await DotnetMSBuild("Build"); var result = await DotnetMSBuild("Build");
Assert.BuildPassed(result); Assert.BuildPassed(result);
Assert.FileExists(result, assemblyInfoPath);
Assert.FileContains(result, assemblyInfoPath, "[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.RelatedAssemblyAttribute(\"SimpleMvc.Views\")]");
Assert.FileExists(result, razorAssemblyInfoPath); Assert.FileExists(result, razorAssemblyInfoPath);
Assert.FileContains(result, razorAssemblyInfoPath, "[assembly: System.Reflection.AssemblyTitleAttribute(\"SimpleMvc.Views\")]"); Assert.FileContains(result, razorAssemblyInfoPath, "[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.RelatedAssemblyAttribute(\"SimpleMvc.Views\")]");
Assert.FileContains(result, razorAssemblyInfoPath, "[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ProvideApplicationPartFactoryAttribute(\"Microsoft.AspNetCore.Mvc.ApplicationParts.CompiledRazorAssemblyApplicationPartFac\"");
Assert.FileExists(result, razorTargetAssemblyInfo);
Assert.FileContains(result, razorTargetAssemblyInfo, "[assembly: System.Reflection.AssemblyTitleAttribute(\"SimpleMvc.Views\")]");
Assert.FileContains(result, razorTargetAssemblyInfo, "[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ProvideApplicationPartFactoryAttribute(\"Microsoft.AspNetCore.Mvc.ApplicationParts.CompiledRazorAssemblyApplicationPartFac\"");
} }
[Fact] [Fact]
[InitializeTestProject("SimpleMvc")] [InitializeTestProject("SimpleMvc")]
public async Task Build_AddsApplicationPartAttributes_WhenEnableDefaultRazorTargetAssemblyInfoAttributes_IsFalse() public async Task Build_AddsApplicationPartAttributes_WhenEnableDefaultRazorTargetAssemblyInfoAttributes_IsFalse()
{ {
var razorAssemblyInfoPath = Path.Combine(IntermediateOutputPath, "SimpleMvc.RazorAssemblyInfo.cs"); var razorTargetAssemblyInfo = Path.Combine(IntermediateOutputPath, "SimpleMvc.RazorTargetAssemblyInfo.cs");
var result = await DotnetMSBuild("Build", "/p:EnableDefaultRazorTargetAssemblyInfoAttributes=false"); var result = await DotnetMSBuild("Build", "/p:EnableDefaultRazorTargetAssemblyInfoAttributes=false");
Assert.BuildPassed(result); Assert.BuildPassed(result);
Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.AssemblyInfo.cs"); Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.AssemblyInfo.cs");
Assert.FileExists(result, razorAssemblyInfoPath); Assert.FileExists(result, razorTargetAssemblyInfo);
Assert.FileDoesNotContain(result, razorAssemblyInfoPath, "[assembly: System.Reflection.AssemblyTitleAttribute"); Assert.FileDoesNotContain(result, razorTargetAssemblyInfo, "[assembly: System.Reflection.AssemblyTitleAttribute");
Assert.FileContains(result, razorAssemblyInfoPath, "[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ProvideApplicationPartFactoryAttribute(\"Microsoft.AspNetCore.Mvc.ApplicationParts.CompiledRazorAssemblyApplicationPartFac\""); Assert.FileContains(result, razorTargetAssemblyInfo, "[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ProvideApplicationPartFactoryAttribute(\"Microsoft.AspNetCore.Mvc.ApplicationParts.CompiledRazorAssemblyApplicationPartFac\"");
} }
[Fact] [Fact]
[InitializeTestProject("ClassLibrary")] [InitializeTestProject("ClassLibrary")]
public async Task Build_UsesSpecifiedApplicationPartFactoryTypeName() public async Task Build_UsesSpecifiedApplicationPartFactoryTypeName()
{ {
var razorAssemblyInfo = Path.Combine(IntermediateOutputPath, "ClassLibrary.RazorAssemblyInfo.cs"); var razorTargetAssemblyInfo = Path.Combine(IntermediateOutputPath, "ClassLibrary.RazorTargetAssemblyInfo.cs");
var result = await DotnetMSBuild("Build", "/p:ProvideApplicationPartFactoryAttributeTypeName=CustomFactory"); var result = await DotnetMSBuild("Build", "/p:ProvideApplicationPartFactoryAttributeTypeName=CustomFactory");
Assert.BuildPassed(result); Assert.BuildPassed(result);
Assert.FileExists(result, razorAssemblyInfo); Assert.FileExists(result, razorTargetAssemblyInfo);
Assert.FileContains(result, razorAssemblyInfo, "[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ProvideApplicationPartFactoryAttribute(\"CustomFactory\""); Assert.FileContains(result, razorTargetAssemblyInfo, "[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ProvideApplicationPartFactoryAttribute(\"CustomFactory\"");
} }
[Fact] [Fact]
[InitializeTestProject("ClassLibrary")] [InitializeTestProject("ClassLibrary")]
public async Task Build_DoesNotGenerateProvideApplicationPartFactoryAttribute_IfGenerateProvideApplicationPartFactoryAttributeIsUnset() public async Task Build_DoesNotGenerateProvideApplicationPartFactoryAttribute_IfGenerateProvideApplicationPartFactoryAttributeIsUnset()
{ {
var razorAssemblyInfo = Path.Combine(IntermediateOutputPath, "ClassLibrary.RazorAssemblyInfo.cs"); var razorTargetAssemblyInfo = Path.Combine(IntermediateOutputPath, "ClassLibrary.RazorTargetAssemblyInfo.cs");
var result = await DotnetMSBuild("Build", "/p:GenerateProvideApplicationPartFactoryAttribute=false"); var result = await DotnetMSBuild("Build", "/p:GenerateProvideApplicationPartFactoryAttribute=false");
Assert.BuildPassed(result); Assert.BuildPassed(result);
Assert.FileExists(result, razorAssemblyInfo); Assert.FileExists(result, razorTargetAssemblyInfo);
Assert.FileDoesNotContain(result, razorAssemblyInfo, "[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ProvideApplicationPartFactoryAttribute"); Assert.FileDoesNotContain(result, razorTargetAssemblyInfo, "[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ProvideApplicationPartFactoryAttribute");
} }
[Fact] [Fact]
[InitializeTestProject("SimpleMvc")] [InitializeTestProject("SimpleMvc")]
public async Task Build_DoesNotAddRelatedAssemblyPart_IfToolSetIsNotRazorSdk() public async Task Build_DoesNotAddRelatedAssemblyPart_IfToolSetIsNotRazorSdk()
{ {
var assemblyInfo = Path.Combine(IntermediateOutputPath, "SimpleMvc.AssemblyInfo.cs"); var razorAssemblyInfo = Path.Combine(IntermediateOutputPath, "SimpleMvc.RazorAssemblyInfo.cs");
var result = await DotnetMSBuild("Build", "/p:RazorCompileToolSet=MvcPrecompilation"); var result = await DotnetMSBuild("Build", "/p:RazorCompileToolSet=MvcPrecompilation");
Assert.BuildPassed(result); Assert.BuildPassed(result);
Assert.FileExists(result, assemblyInfo); Assert.FileDoesNotExist(result, razorAssemblyInfo);
Assert.FileDoesNotContain(result, assemblyInfo, "RelatedAssemblyAttribute"); Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.RazorTargetAssemblyInfo.cs");
Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.RazorAssemblyInfo.cs");
} }
[Fact] [Fact]
[InitializeTestProject("SimpleMvc")] [InitializeTestProject("SimpleMvc")]
public async Task Build_DoesNotAddRelatedAssemblyPart_IfViewCompilationIsDisabled() public async Task Build_DoesNotAddRelatedAssemblyPart_IfViewCompilationIsDisabled()
{ {
var assemblyInfo = Path.Combine(IntermediateOutputPath, "SimpleMvc.AssemblyInfo.cs"); var razorAssemblyInfo = Path.Combine(IntermediateOutputPath, "SimpleMvc.RazorAssemblyInfo.cs");
var result = await DotnetMSBuild("Build", "/p:RazorCompileOnBuild=false /p:RazorCompileOnPublish=false"); var result = await DotnetMSBuild("Build", "/p:RazorCompileOnBuild=false /p:RazorCompileOnPublish=false");
Assert.BuildPassed(result); Assert.BuildPassed(result);
Assert.FileExists(result, assemblyInfo); Assert.FileExists(result, razorAssemblyInfo);
Assert.FileDoesNotContain(result, assemblyInfo, "RelatedAssemblyAttribute"); Assert.FileDoesNotContain(result, razorAssemblyInfo, "RelatedAssemblyAttribute");
Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.RazorAssemblyInfo.cs"); Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.RazorTargetAssemblyInfo.cs");
} }
[Fact] [Fact]
[InitializeTestProject("SimpleMvc")] [InitializeTestProject("SimpleMvc")]
public async Task Build_AddsRelatedAssemblyPart_IfCompileOnPublishIsAllowed() public async Task Build_AddsRelatedAssemblyPart_IfCompileOnPublishIsAllowed()
{ {
var assemblyInfo = Path.Combine(IntermediateOutputPath, "SimpleMvc.AssemblyInfo.cs"); var razorAssemblyInfo = Path.Combine(IntermediateOutputPath, "SimpleMvc.RazorAssemblyInfo.cs");
var result = await DotnetMSBuild("Build", "/p:RazorCompileOnBuild=false"); var result = await DotnetMSBuild("Build", "/p:RazorCompileOnBuild=false");
Assert.BuildPassed(result); Assert.BuildPassed(result);
Assert.FileExists(result, assemblyInfo); Assert.FileExists(result, razorAssemblyInfo);
Assert.FileContains(result, assemblyInfo, "[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.RelatedAssemblyAttribute(\"SimpleMvc.Views\")]"); Assert.FileContains(result, razorAssemblyInfo, "[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.RelatedAssemblyAttribute(\"SimpleMvc.Views\")]");
Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.RazorAssemblyInfo.cs"); Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.RazorTargetAssemblyInfo.cs");
}
[Fact]
[InitializeTestProject("SimpleMvc")]
public async Task Build_AddsRelatedAssemblyPart_IfGenerateAssemblyInfoIsFalse()
{
var razorAssemblyInfo = Path.Combine(IntermediateOutputPath, "SimpleMvc.RazorAssemblyInfo.cs");
var result = await DotnetMSBuild("Build", "/p:GenerateAssemblyInfo=false");
Assert.BuildPassed(result);
Assert.FileExists(result, razorAssemblyInfo);
Assert.FileContains(result, razorAssemblyInfo, "[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.RelatedAssemblyAttribute(\"SimpleMvc.Views\")]");
} }
[Fact] [Fact]
[InitializeTestProject("SimpleMvc")] [InitializeTestProject("SimpleMvc")]
public async Task Build_WithGenerateRazorHostingAssemblyInfoFalse_DoesNotGenerateHostingAttributes() public async Task Build_WithGenerateRazorHostingAssemblyInfoFalse_DoesNotGenerateHostingAttributes()
{ {
var assemblyInfo = Path.Combine(IntermediateOutputPath, "SimpleMvc.AssemblyInfo.cs"); var razorAssemblyInfo = Path.Combine(IntermediateOutputPath, "SimpleMvc.RazorAssemblyInfo.cs");
var result = await DotnetMSBuild("Build", "/p:GenerateRazorHostingAssemblyInfo=false"); var result = await DotnetMSBuild("Build", "/p:GenerateRazorHostingAssemblyInfo=false");
Assert.BuildPassed(result); Assert.BuildPassed(result);
Assert.FileExists(result, assemblyInfo); Assert.FileExists(result, razorAssemblyInfo);
Assert.FileDoesNotContain(result, assemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute"); Assert.FileDoesNotContain(result, razorAssemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute");
Assert.FileDoesNotContain(result, assemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute"); Assert.FileDoesNotContain(result, razorAssemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute");
Assert.FileDoesNotContain(result, assemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorExtensionAssemblyNameAttribute"); Assert.FileDoesNotContain(result, razorAssemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorExtensionAssemblyNameAttribute");
Assert.FileContains(result, razorAssemblyInfo, "[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.RelatedAssemblyAttribute(\"SimpleMvc.Views\")]");
} }
[Fact] [Fact]
[InitializeTestProject("ClassLibrary")] [InitializeTestProject("ClassLibrary")]
public async Task Build_DoesNotGenerateHostingAttributes_InClassLibraryProjects() public async Task Build_DoesNotGenerateHostingAttributes_InClassLibraryProjects()
{ {
var assemblyInfo = Path.Combine(IntermediateOutputPath, "ClassLibrary.AssemblyInfo.cs"); var razorAssemblyInfo = Path.Combine(IntermediateOutputPath, "ClassLibrary.AssemblyInfo.cs");
var result = await DotnetMSBuild("Build"); var result = await DotnetMSBuild("Build");
Assert.BuildPassed(result); Assert.BuildPassed(result);
Assert.FileExists(result, assemblyInfo); Assert.FileExists(result, razorAssemblyInfo);
Assert.FileDoesNotContain(result, assemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute"); Assert.FileDoesNotContain(result, razorAssemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute");
Assert.FileDoesNotContain(result, assemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute"); Assert.FileDoesNotContain(result, razorAssemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute");
Assert.FileDoesNotContain(result, assemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorExtensionAssemblyNameAttribute"); Assert.FileDoesNotContain(result, razorAssemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorExtensionAssemblyNameAttribute");
} }
[Fact] [Fact]
[InitializeTestProject("SimpleMvc")] [InitializeTestProject("SimpleMvc")]
public async Task Build_GeneratesHostingAttributesByDefault() public async Task Build_GeneratesHostingAttributesByDefault()
{ {
var assemblyInfo = Path.Combine(IntermediateOutputPath, "SimpleMvc.AssemblyInfo.cs"); var razorAssemblyInfo = Path.Combine(IntermediateOutputPath, "SimpleMvc.AssemblyInfo.cs");
var result = await DotnetMSBuild("Build", "/p:GenerateRazorHostingAssemblyInfo=false"); var result = await DotnetMSBuild("Build", "/p:GenerateRazorHostingAssemblyInfo=false");
Assert.BuildPassed(result); Assert.BuildPassed(result);
Assert.FileExists(result, assemblyInfo); Assert.FileExists(result, razorAssemblyInfo);
Assert.FileDoesNotContain(result, assemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute(\"2.1\")"); Assert.FileDoesNotContain(result, razorAssemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute(\"2.1\")");
Assert.FileDoesNotContain(result, assemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute(\"MVC-2-1\")"); Assert.FileDoesNotContain(result, razorAssemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute(\"MVC-2-1\")");
} }
[Fact] [Fact]
@ -471,6 +483,40 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvcFSharp.Views.dll"); Assert.FileDoesNotExist(result, OutputPath, "SimpleMvcFSharp.Views.dll");
Assert.FileDoesNotExist(result, OutputPath, "SimpleMvcFSharp.Views.pdb"); Assert.FileDoesNotExist(result, OutputPath, "SimpleMvcFSharp.Views.pdb");
Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvcFSharp.RazorAssemblyInfo.cs");
Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvcFSharp.RazorAssemblyInfo.fs");
}
[Fact]
[InitializeTestProject("SimpleMvc")]
public async Task Build_WithGenerateRazorAssemblyInfo_False_DoesNotGenerateAssemblyInfo()
{
var razorAssemblyInfo = Path.Combine(IntermediateOutputPath, "SimpleMvc.RazorAssemblyInfo.cs");
var result = await DotnetMSBuild("Build", "/p:GenerateRazorAssemblyInfo=false");
Assert.BuildPassed(result);
Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.Views.dll");
Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.Views.pdb");
Assert.FileDoesNotExist(result, razorAssemblyInfo);
}
[Fact]
[InitializeTestProject("SimpleMvc")]
public async Task Build_WithGenerateRazorTargetAssemblyInfo_False_DoesNotGenerateAssemblyInfo()
{
var razorAssemblyInfo = Path.Combine(IntermediateOutputPath, "SimpleMvc.RazorAssemblyInfo.cs");
var razorTargetAssemblyInfo = Path.Combine(IntermediateOutputPath, "SimpleMvc.RazorTargetAssemblyInfo.cs");
var result = await DotnetMSBuild("Build", "/p:GenerateRazorTargetAssemblyInfo=false");
Assert.BuildPassed(result);
Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.Views.dll");
Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.Views.pdb");
Assert.FileExists(result, razorAssemblyInfo);
Assert.FileDoesNotExist(result, razorTargetAssemblyInfo);
} }
[Fact] [Fact]

View File

@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
Assert.BuildPassed(result); Assert.BuildPassed(result);
Assert.BuildOutputContainsLine(result, $"RazorCompile: {Path.Combine(IntermediateOutputPath, "Razor", "Views", "Home", "Index.g.cshtml.cs")}"); Assert.BuildOutputContainsLine(result, $"RazorCompile: {Path.Combine(IntermediateOutputPath, "Razor", "Views", "Home", "Index.g.cshtml.cs")}");
Assert.BuildOutputContainsLine(result, $"RazorCompile: {Path.Combine(IntermediateOutputPath, "SimpleMvc.RazorAssemblyInfo.cs")}"); Assert.BuildOutputContainsLine(result, $"RazorCompile: {Path.Combine(IntermediateOutputPath, "SimpleMvc.RazorTargetAssemblyInfo.cs")}");
} }
[Fact] [Fact]

View File

@ -18,6 +18,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
[InitializeTestProject("SimpleMvc")] [InitializeTestProject("SimpleMvc")]
public async Task Build_WithMvc_AddsConfigurationMetadata() public async Task Build_WithMvc_AddsConfigurationMetadata()
{ {
var razorAssemblyInfo = Path.Combine(IntermediateOutputPath, "SimpleMvc.RazorAssemblyInfo.cs");
var result = await DotnetMSBuild("Build"); var result = await DotnetMSBuild("Build");
Assert.BuildPassed(result); Assert.BuildPassed(result);
@ -25,51 +26,26 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.Views.dll"); Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.Views.dll");
Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.Views.pdb"); Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.Views.pdb");
Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.AssemblyInfo.cs"); Assert.FileExists(result, razorAssemblyInfo);
Assert.FileContainsLine( Assert.FileContainsLine(
result, result,
Path.Combine(IntermediateOutputPath, "SimpleMvc.AssemblyInfo.cs"), razorAssemblyInfo,
"[assembly: Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute(\"2.1\")]"); "[assembly: Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute(\"2.1\")]");
Assert.FileContainsLine( Assert.FileContainsLine(
result, result,
Path.Combine(IntermediateOutputPath, "SimpleMvc.AssemblyInfo.cs"), razorAssemblyInfo,
"[assembly: Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute(\"MVC-2.1\")]"); "[assembly: Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute(\"MVC-2.1\")]");
Assert.FileContainsLine( Assert.FileContainsLine(
result, result,
Path.Combine(IntermediateOutputPath, "SimpleMvc.AssemblyInfo.cs"), razorAssemblyInfo,
"[assembly: Microsoft.AspNetCore.Razor.Hosting.RazorExtensionAssemblyNameAttribute(\"MVC-2.1\", \"Microsoft.AspNetCore.Mvc.Razor.Extensions\")]"); "[assembly: Microsoft.AspNetCore.Razor.Hosting.RazorExtensionAssemblyNameAttribute(\"MVC-2.1\", \"Microsoft.AspNetCore.Mvc.Razor.Extensions\")]");
} }
[Fact]
[InitializeTestProject("SimpleMvc")]
public async Task Build_WithGenerateRazorAssemblyInfo_False_SuppressesConfigurationMetadata()
{
var result = await DotnetMSBuild("Build", "/p:GenerateRazorAssemblyInfo=false");
Assert.BuildPassed(result);
Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.Views.dll");
Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.Views.pdb");
Assert.FileExists(result, IntermediateOutputPath, "SimpleMvc.AssemblyInfo.cs");
Assert.FileDoesNotContainLine(
result,
Path.Combine(IntermediateOutputPath, "SimpleMvc.AssemblyInfo.cs"),
"[assembly: Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute(\"2.1\")]");
Assert.FileDoesNotContainLine(
result,
Path.Combine(IntermediateOutputPath, "SimpleMvc.AssemblyInfo.cs"),
"[assembly: Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute(\"MVC-2.1\")]");
Assert.FileDoesNotContainLine(
result,
Path.Combine(IntermediateOutputPath, "SimpleMvc.AssemblyInfo.cs"),
"[assembly: Microsoft.AspNetCore.Razor.Hosting.RazorExtensionAssemblyNameAttribute(\"MVC-2.1\", \"Microsoft.AspNetCore.Razor.Extensions\")]");
}
[Fact] [Fact]
[InitializeTestProject("ClassLibrary")] [InitializeTestProject("ClassLibrary")]
public async Task Build_ForClassLibrary_SuppressesConfigurationMetadata() public async Task Build_ForClassLibrary_SuppressesConfigurationMetadata()
{ {
var razorAssemblyInfo = Path.Combine(IntermediateOutputPath, "ClassLibrary.RazorAssemblyInfo.cs");
var result = await DotnetMSBuild("Build"); var result = await DotnetMSBuild("Build");
Assert.BuildPassed(result); Assert.BuildPassed(result);
@ -77,18 +53,18 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
Assert.FileExists(result, IntermediateOutputPath, "ClassLibrary.Views.dll"); Assert.FileExists(result, IntermediateOutputPath, "ClassLibrary.Views.dll");
Assert.FileExists(result, IntermediateOutputPath, "ClassLibrary.Views.pdb"); Assert.FileExists(result, IntermediateOutputPath, "ClassLibrary.Views.pdb");
Assert.FileExists(result, IntermediateOutputPath, "ClassLibrary.AssemblyInfo.cs"); Assert.FileExists(result, razorAssemblyInfo);
Assert.FileDoesNotContainLine( Assert.FileDoesNotContainLine(
result, result,
Path.Combine(IntermediateOutputPath, "ClassLibrary.AssemblyInfo.cs"), razorAssemblyInfo,
"[assembly: Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute(\"2.1\")]"); "[assembly: Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute(\"2.1\")]");
Assert.FileDoesNotContainLine( Assert.FileDoesNotContainLine(
result, result,
Path.Combine(IntermediateOutputPath, "ClassLibrary.AssemblyInfo.cs"), razorAssemblyInfo,
"[assembly: Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute(\"MVC-2.1\")]"); "[assembly: Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute(\"MVC-2.1\")]");
Assert.FileDoesNotContainLine( Assert.FileDoesNotContainLine(
result, result,
Path.Combine(IntermediateOutputPath, "ClassLibrary.AssemblyInfo.cs"), razorAssemblyInfo,
"[assembly: Microsoft.AspNetCore.Razor.Hosting.RazorExtensionAssemblyNameAttribute(\"MVC-2.1\", \"Microsoft.AspNetCore.Razor.Extensions\")]"); "[assembly: Microsoft.AspNetCore.Razor.Hosting.RazorExtensionAssemblyNameAttribute(\"MVC-2.1\", \"Microsoft.AspNetCore.Razor.Extensions\")]");
} }
} }