diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/common.targets b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/common.targets
index 7df1e2a00a..55d6dbace1 100644
--- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/common.targets
+++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/common.targets
@@ -8,6 +8,7 @@
$(MSBuildProjectDirectory)
true
+ true
@@ -53,7 +54,7 @@
Condition="'$(MvcRazorCompileOnPublish)'=='true'" />
@@ -65,6 +66,12 @@
$([System.IO.Path]::GetFileName('$(_MvcRazorOutputFullPath)'))
+
+
+
+
diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Infrastructure/ApplicationTestFixture.cs b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Infrastructure/ApplicationTestFixture.cs
index d805ddc687..1c7c7adeac 100644
--- a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Infrastructure/ApplicationTestFixture.cs
+++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Infrastructure/ApplicationTestFixture.cs
@@ -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(
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)
diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/ViewCompilationOptionsTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/ViewCompilationOptionsTest.cs
new file mode 100644
index 0000000000..adafc8785d
--- /dev/null
+++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/ViewCompilationOptionsTest.cs
@@ -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
+ {
+ 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("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")
+ {
+ }
+ }
+ }
+}