Avoid generating RelatedAssemblyAttribute when RazorSdk isn't in play

This commit is contained in:
Pranav K 2018-03-13 11:12:17 -07:00
parent 9fc6b8fcf5
commit 425724ce28
2 changed files with 47 additions and 2 deletions

View File

@ -12,7 +12,7 @@
<RazorTargetNameSuffix Condition="'$(RazorTargetNameSuffix)'==''">.Views</RazorTargetNameSuffix>
</PropertyGroup>
<ItemGroup Condition="'$(GenerateRazorAssemblyInfo)'=='true'">
<ItemGroup Condition="'$(GenerateRazorAssemblyInfo)'=='true' AND '$(ResolvedRazorCompileToolset)'=='RazorSdk' AND ('$(RazorCompileOnBuild)' == 'true' OR '$(RazorCompileOnPublish)' == 'true')">
<AssemblyAttribute Include="Microsoft.AspNetCore.Mvc.ApplicationParts.RelatedAssemblyAttribute">
<_Parameter1>$(RazorTargetName)</_Parameter1>
</AssemblyAttribute>

View File

@ -352,7 +352,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
Assert.FileContains(result, razorAssemblyInfoPath, "[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ProvideApplicationPartFactoryAttribute(\"Microsoft.AspNetCore.Mvc.ApplicationParts.CompiledRazorAssemblyApplicationPartFac\"");
}
[Fact]
[Fact]
[InitializeTestProject("SimpleMvc")]
public async Task Build_AddsApplicationPartAttributes_WhenEnableDefaultRazorTargetAssemblyInfoAttributes_IsFalse()
{
@ -367,6 +367,51 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests
Assert.FileContains(result, razorAssemblyInfoPath, "[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.ProvideApplicationPartFactoryAttribute(\"Microsoft.AspNetCore.Mvc.ApplicationParts.CompiledRazorAssemblyApplicationPartFac\"");
}
[Fact]
[InitializeTestProject("SimpleMvc")]
public async Task Build_DoesNotAddRelatedAssemblyPart_IfToolSetIsNotRazorSdk()
{
var assemblyInfo = Path.Combine(IntermediateOutputPath, "SimpleMvc.AssemblyInfo.cs");
var result = await DotnetMSBuild("Build", "/p:RazorCompileToolSet=MvcPrecompilation");
Assert.BuildPassed(result);
Assert.FileExists(result, assemblyInfo);
Assert.FileDoesNotContain(result, assemblyInfo, "RelatedAssemblyAttribute");
Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.RazorAssemblyInfo.cs");
}
[Fact]
[InitializeTestProject("SimpleMvc")]
public async Task Build_DoesNotAddRelatedAssemblyPart_IfViewCompilationIsDisabled()
{
var assemblyInfo = Path.Combine(IntermediateOutputPath, "SimpleMvc.AssemblyInfo.cs");
var result = await DotnetMSBuild("Build", "/p:RazorCompileOnBuild=false /p:RazorCompileOnPublish=false");
Assert.BuildPassed(result);
Assert.FileExists(result, assemblyInfo);
Assert.FileDoesNotContain(result, assemblyInfo, "RelatedAssemblyAttribute");
Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.RazorAssemblyInfo.cs");
}
[Fact]
[InitializeTestProject("SimpleMvc")]
public async Task Build_AddsRelatedAssemblyPart_IfCompileOnPublishIsAllowed()
{
var assemblyInfo = Path.Combine(IntermediateOutputPath, "SimpleMvc.AssemblyInfo.cs");
var result = await DotnetMSBuild("Build", "/p:RazorCompileOnBuild=false");
Assert.BuildPassed(result);
Assert.FileExists(result, assemblyInfo);
Assert.FileContains(result, assemblyInfo, "[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.RelatedAssemblyAttribute(\"SimpleMvc.Views\")]");
Assert.FileDoesNotExist(result, IntermediateOutputPath, "SimpleMvc.RazorAssemblyInfo.cs");
}
private static DependencyContext ReadDependencyContext(string depsFilePath)
{
var reader = new DependencyContextJsonReader();