diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/build/netstandard2.0/Microsoft.AspNetCore.Mvc.Razor.Extensions.props b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/build/netstandard2.0/Microsoft.AspNetCore.Mvc.Razor.Extensions.props
index ef8766cdf2..bf2a6f9c88 100644
--- a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/build/netstandard2.0/Microsoft.AspNetCore.Mvc.Razor.Extensions.props
+++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/build/netstandard2.0/Microsoft.AspNetCore.Mvc.Razor.Extensions.props
@@ -11,6 +11,12 @@
-->
MVC-2.1
+
+ true
+
<_MvcExtensionAssemblyPath Condition="'$(_MvcExtensionAssemblyPath)'==''">$(MSBuildThisFileDirectory)..\..\lib\netstandard2.0\Microsoft.AspNetCore.Mvc.Razor.Extensions.dll
@@ -32,4 +38,4 @@
$(_MvcExtensionAssemblyPath)
-
\ No newline at end of file
+
diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/build/netstandard2.0/Microsoft.AspNetCore.Mvc.Razor.Extensions.targets b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/build/netstandard2.0/Microsoft.AspNetCore.Mvc.Razor.Extensions.targets
index 5fb7dab0e3..a1fd205e62 100644
--- a/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/build/netstandard2.0/Microsoft.AspNetCore.Mvc.Razor.Extensions.targets
+++ b/src/Microsoft.AspNetCore.Mvc.Razor.Extensions/build/netstandard2.0/Microsoft.AspNetCore.Mvc.Razor.Extensions.targets
@@ -4,7 +4,9 @@
- true
+ true
+
+ $(GenerateRazorAssemblyInfo)
diff --git a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/BuildIntegrationTest.cs b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/BuildIntegrationTest.cs
index 4dbd856543..cce650efc1 100644
--- a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/BuildIntegrationTest.cs
+++ b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/BuildIntegrationTest.cs
@@ -367,6 +367,32 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
Assert.FileContains(result, razorAssemblyInfoPath, "[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ProvideApplicationPartFactoryAttribute(\"Microsoft.AspNetCore.Mvc.ApplicationParts.CompiledRazorAssemblyApplicationPartFac\"");
}
+ [Fact]
+ [InitializeTestProject("ClassLibrary")]
+ public async Task Build_UsesSpecifiedApplicationPartFactoryTypeName()
+ {
+ var razorAssemblyInfo = Path.Combine(IntermediateOutputPath, "ClassLibrary.RazorAssemblyInfo.cs");
+ var result = await DotnetMSBuild("Build", "/p:ProvideApplicationPartFactoryAttributeTypeName=CustomFactory");
+
+ Assert.BuildPassed(result);
+
+ Assert.FileExists(result, razorAssemblyInfo);
+ Assert.FileContains(result, razorAssemblyInfo, "[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ProvideApplicationPartFactoryAttribute(\"CustomFactory\"");
+ }
+
+ [Fact]
+ [InitializeTestProject("ClassLibrary")]
+ public async Task Build_UsesNullFactory_IfEnableDefaultCompiledViewAssemblyLoadBehaviorIsSetToFalse()
+ {
+ var razorAssemblyInfo = Path.Combine(IntermediateOutputPath, "ClassLibrary.RazorAssemblyInfo.cs");
+ var result = await DotnetMSBuild("Build", "/p:EnableDefaultCompiledViewAssemblyLoadBehavior=false");
+
+ Assert.BuildPassed(result);
+
+ Assert.FileExists(result, razorAssemblyInfo);
+ Assert.FileContains(result, razorAssemblyInfo, "[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ProvideApplicationPartFactoryAttribute(\"Microsoft.AspNetCore.Mvc.ApplicationParts.NullApplicationPartFactory");
+ }
+
[Fact]
[InitializeTestProject("SimpleMvc")]
public async Task Build_DoesNotAddRelatedAssemblyPart_IfToolSetIsNotRazorSdk()
@@ -412,6 +438,50 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.RazorAssemblyInfo.cs");
}
+ [Fact]
+ [InitializeTestProject("SimpleMvc")]
+ public async Task Build_WithGenerateRazorHostingAssemblyInfoFalse_DoesNotGenerateHostingAttributes()
+ {
+ var assemblyInfo = Path.Combine(IntermediateOutputPath, "SimpleMvc.AssemblyInfo.cs");
+ var result = await DotnetMSBuild("Build", "/p:GenerateRazorHostingAssemblyInfo=false");
+
+ Assert.BuildPassed(result);
+
+ Assert.FileExists(result, assemblyInfo);
+ Assert.FileDoesNotContain(result, assemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute");
+ Assert.FileDoesNotContain(result, assemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute");
+ Assert.FileDoesNotContain(result, assemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorExtensionAssemblyNameAttribute");
+ }
+
+ [Fact]
+ [InitializeTestProject("ClassLibrary")]
+ public async Task Build_DoesNotGenerateHostingAttributes_InClassLibraryProjects()
+ {
+ var assemblyInfo = Path.Combine(IntermediateOutputPath, "ClassLibrary.AssemblyInfo.cs");
+ var result = await DotnetMSBuild("Build");
+
+ Assert.BuildPassed(result);
+
+ Assert.FileExists(result, assemblyInfo);
+ Assert.FileDoesNotContain(result, assemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute");
+ Assert.FileDoesNotContain(result, assemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute");
+ Assert.FileDoesNotContain(result, assemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorExtensionAssemblyNameAttribute");
+ }
+
+ [Fact]
+ [InitializeTestProject("SimpleMvc")]
+ public async Task Build_GeneratesHostingAttributesByDefault()
+ {
+ var assemblyInfo = Path.Combine(IntermediateOutputPath, "SimpleMvc.AssemblyInfo.cs");
+ var result = await DotnetMSBuild("Build", "/p:GenerateRazorHostingAssemblyInfo=false");
+
+ Assert.BuildPassed(result);
+
+ Assert.FileExists(result, assemblyInfo);
+ Assert.FileDoesNotContain(result, assemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute(\"2.1\")");
+ Assert.FileDoesNotContain(result, assemblyInfo, "Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute(\"MVC-2-1\")");
+ }
+
private static DependencyContext ReadDependencyContext(string depsFilePath)
{
var reader = new DependencyContextJsonReader();