Add an option to disable publishing "refs" assemblies if compilation of views is enabled
Fixes #76
This commit is contained in:
parent
01366e5855
commit
64d4b1da0c
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
<MvcRazorContentRoot Condition="'$(MvcRazorContentRoot)'==''">$(MSBuildProjectDirectory)</MvcRazorContentRoot>
|
||||
<MvcRazorExcludeViewFilesFromPublish Condition="'$(MvcRazorExcludeViewFilesFromPublish)'==''">true</MvcRazorExcludeViewFilesFromPublish>
|
||||
<MvcRazorExcludeRefAssembliesFromPublish Condition="'$(MvcRazorExcludeRefAssembliesFromPublish)'==''">true</MvcRazorExcludeRefAssembliesFromPublish>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'@(MvcRazorFilesToCompile)' == ''">
|
||||
|
|
@ -53,7 +54,7 @@
|
|||
Condition="'$(MvcRazorCompileOnPublish)'=='true'" />
|
||||
|
||||
<Target Name="_MvcRazorResolveFilesToCompute"
|
||||
AfterTargets="ComputeFilesToPublish"
|
||||
AfterTargets="ComputeRefAssembliesToPublish"
|
||||
Condition="'$(MvcRazorCompileOnPublish)'=='true'">
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -65,6 +66,12 @@
|
|||
<RelativePath>$([System.IO.Path]::GetFileName('$(_MvcRazorOutputFullPath)'))</RelativePath>
|
||||
</ResolvedFileToPublish>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(MvcRazorExcludeRefAssembliesFromPublish)'=='true'">
|
||||
<ResolvedFileToPublish
|
||||
Remove="%(ResolvedFileToPublish.Identity)"
|
||||
Condition="'%(ResolvedFileToPublish.RelativePath)'=='$(RefAssembliesFolderName)\%(Filename)%(Extension)'" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
</Project>
|
||||
|
||||
|
|
|
|||
|
|
@ -38,6 +38,13 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
|
|||
public ILogger Logger { get; private set; }
|
||||
|
||||
public IApplicationDeployer CreateDeployment(RuntimeFlavor flavor)
|
||||
{
|
||||
PrepareForDeployment(flavor);
|
||||
var deploymentParameters = GetDeploymentParameters(flavor);
|
||||
return ApplicationDeployerFactory.Create(deploymentParameters, Logger);
|
||||
}
|
||||
|
||||
public virtual void PrepareForDeployment(RuntimeFlavor flavor)
|
||||
{
|
||||
Logger = CreateLogger(flavor);
|
||||
|
||||
|
|
@ -46,7 +53,10 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
|
|||
Restore();
|
||||
_isRestored = true;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual DeploymentParameters GetDeploymentParameters(RuntimeFlavor flavor)
|
||||
{
|
||||
var tempRestoreDirectoryEnvironment = new KeyValuePair<string, string>(
|
||||
NuGetPackagesEnvironmentKey,
|
||||
TempRestoreDirectory);
|
||||
|
|
@ -82,7 +92,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
|
|||
},
|
||||
};
|
||||
|
||||
return ApplicationDeployerFactory.Create(deploymentParameters, Logger);
|
||||
return deploymentParameters;
|
||||
}
|
||||
|
||||
protected virtual ILogger CreateLogger(RuntimeFlavor flavor)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,65 @@
|
|||
// 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.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.AspNetCore.Server.IntegrationTesting;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
|
||||
{
|
||||
public class ViewCompilationOptionsTest : IClassFixture<ViewCompilationOptionsTest.TestFixture>
|
||||
{
|
||||
public ViewCompilationOptionsTest(TestFixture fixture)
|
||||
{
|
||||
Fixture = fixture;
|
||||
}
|
||||
|
||||
public ApplicationTestFixture Fixture { get; }
|
||||
|
||||
public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData;
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(SupportedFlavorsTheoryData))]
|
||||
public void Precompilation_PreventsRefAssembliesFromBeingPublished(RuntimeFlavor flavor)
|
||||
{
|
||||
// Arrange
|
||||
using (var deployer = Fixture.CreateDeployment(flavor))
|
||||
{
|
||||
// Act
|
||||
var deploymentResult = deployer.Deploy();
|
||||
|
||||
// Assert
|
||||
Assert.False(Directory.Exists(Path.Combine(deploymentResult.ContentRoot, "refs")));
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(SupportedFlavorsTheoryData))]
|
||||
public void PublishingWithOption_AllowsPublishingRefAssemblies(RuntimeFlavor flavor)
|
||||
{
|
||||
// Arrange
|
||||
Fixture.PrepareForDeployment(flavor);
|
||||
var deploymentParameters = Fixture.GetDeploymentParameters(flavor);
|
||||
deploymentParameters.PublishEnvironmentVariables.Add(
|
||||
new KeyValuePair<string, string>("MvcRazorExcludeRefAssembliesFromPublish", "false"));
|
||||
|
||||
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, Fixture.Logger))
|
||||
{
|
||||
// Act
|
||||
var deploymentResult = deployer.Deploy();
|
||||
|
||||
// Assert
|
||||
Assert.True(Directory.Exists(Path.Combine(deploymentResult.ContentRoot, "refs")));
|
||||
}
|
||||
}
|
||||
|
||||
public class TestFixture : ApplicationTestFixture
|
||||
{
|
||||
public TestFixture()
|
||||
: base("SimpleApp")
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue