From 311c52b12efa92f46e19529f0335b8150a28ede3 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 25 Sep 2017 09:17:54 -0700 Subject: [PATCH] Honor CopyBuildOutputToPublishDirectory and CopyOutputSymbolsToPublishDirectory switches Fixes #204 --- ...pNetCore.Mvc.Razor.ViewCompilation.targets | 8 ++- ...ildOutputToPublishDirectoryTest_Desktop.cs | 63 +++++++++++++++++++ ...pyBuildOutputToPublishDirectory_CoreCLR.cs | 60 ++++++++++++++++++ ...utSymbolsToPublishDirectoryTest_CoreCLR.cs | 60 ++++++++++++++++++ ...utSymbolsToPublishDirectoryTest_Desktop.cs | 63 +++++++++++++++++++ .../Infrastructure/ApplicationTestFixture.cs | 12 +++- .../Infrastructure/PublishOnlyDeployer.cs | 47 ++++++++++++++ .../ViewCompilationOptionsTest_CoreCLR.cs | 5 ++ .../ViewCompilationOptionsTest_Desktop.cs | 5 ++ 9 files changed, 320 insertions(+), 3 deletions(-) create mode 100644 test/FunctionalTests/CopyBuildOutputToPublishDirectoryTest_Desktop.cs create mode 100644 test/FunctionalTests/CopyBuildOutputToPublishDirectory_CoreCLR.cs create mode 100644 test/FunctionalTests/CopyOutputSymbolsToPublishDirectoryTest_CoreCLR.cs create mode 100644 test/FunctionalTests/CopyOutputSymbolsToPublishDirectoryTest_Desktop.cs create mode 100644 test/FunctionalTests/Infrastructure/PublishOnlyDeployer.cs diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/netstandard2.0/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/netstandard2.0/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets index a67c93c946..dfe3bf81f2 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/netstandard2.0/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/build/netstandard2.0/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets @@ -170,11 +170,15 @@ Remove="%(MvcRazorFilesToCompile.FullPath)" Condition="'$(MvcRazorExcludeViewFilesFromPublish)'=='true'" /> - + $([System.IO.Path]::GetFileName('$(_MvcRazorOutputFullPath)')) - + $([System.IO.Path]::GetFileName('$(_MvcRazorOutputPdbFullPath)')) diff --git a/test/FunctionalTests/CopyBuildOutputToPublishDirectoryTest_Desktop.cs b/test/FunctionalTests/CopyBuildOutputToPublishDirectoryTest_Desktop.cs new file mode 100644 index 0000000000..51d01d603f --- /dev/null +++ b/test/FunctionalTests/CopyBuildOutputToPublishDirectoryTest_Desktop.cs @@ -0,0 +1,63 @@ +// 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 System.Threading.Tasks; +using Microsoft.AspNetCore.Server.IntegrationTesting; +using Microsoft.AspNetCore.Testing.xunit; +using Microsoft.Extensions.Logging.Testing; +using Xunit; +using Xunit.Abstractions; + +namespace FunctionalTests +{ + [OSSkipCondition(OperatingSystems.Linux)] + [OSSkipCondition(OperatingSystems.MacOSX)] + public class CopyBuildOutputToPublishDirectoryTest_Desktop : + LoggedTest, IClassFixture + { + public CopyBuildOutputToPublishDirectoryTest_Desktop( + TestFixture fixture, + ITestOutputHelper output) + : base(output) + { + Fixture = fixture; + } + + public ApplicationTestFixture Fixture { get; } + + [ConditionalFact] + public async Task PublishingWithOption_SkipsPublishingPrecompiledDll() + { + using (StartLog(out var loggerFactory)) + { + // Arrange + var deployment = await Fixture.CreateDeploymentAsync(loggerFactory); + + // Act & Assert + var dllFile = Path.Combine(deployment.ContentRoot, "SimpleApp.PrecompiledViews.dll"); + var pdbFile = Path.ChangeExtension(dllFile, ".pdb"); + Assert.False(File.Exists(dllFile), $"{dllFile} exists at deployment."); + Assert.True(File.Exists(pdbFile), $"{pdbFile} does not exist at deployment."); + } + } + + public class TestFixture : DesktopApplicationTestFixture + { + public TestFixture() + { + PublishOnly = true; + } + + protected override DeploymentParameters GetDeploymentParameters() + { + var deploymentParameters = base.GetDeploymentParameters(); + deploymentParameters.PublishEnvironmentVariables.Add( + new KeyValuePair("CopyBuildOutputToPublishDirectory", "false")); + + return deploymentParameters; + } + } + } +} diff --git a/test/FunctionalTests/CopyBuildOutputToPublishDirectory_CoreCLR.cs b/test/FunctionalTests/CopyBuildOutputToPublishDirectory_CoreCLR.cs new file mode 100644 index 0000000000..f5177af268 --- /dev/null +++ b/test/FunctionalTests/CopyBuildOutputToPublishDirectory_CoreCLR.cs @@ -0,0 +1,60 @@ +// 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 System.Threading.Tasks; +using Microsoft.AspNetCore.Server.IntegrationTesting; +using Microsoft.Extensions.Logging.Testing; +using Xunit; +using Xunit.Abstractions; + +namespace FunctionalTests +{ + public class CopyBuildOutputToPublishDirectory_CoreCLR : + LoggedTest, IClassFixture + { + public CopyBuildOutputToPublishDirectory_CoreCLR( + TestFixture fixture, + ITestOutputHelper output) + : base(output) + { + Fixture = fixture; + } + + public ApplicationTestFixture Fixture { get; } + + [Fact] + public async Task PublishingWithOption_SkipsPublishingPrecompiledDll() + { + using (StartLog(out var loggerFactory)) + { + // Arrange + var deployment = await Fixture.CreateDeploymentAsync(loggerFactory); + + // Act & Assert + var dllFile = Path.Combine(deployment.ContentRoot, "SimpleApp.PrecompiledViews.dll"); + var pdbFile = Path.ChangeExtension(dllFile, ".pdb"); + Assert.False(File.Exists(dllFile), $"{dllFile} exists at deployment."); + Assert.True(File.Exists(pdbFile), $"{pdbFile} does not exist at deployment."); + } + } + + public class TestFixture : CoreCLRApplicationTestFixture + { + public TestFixture() + { + PublishOnly = true; + } + + protected override DeploymentParameters GetDeploymentParameters() + { + var deploymentParameters = base.GetDeploymentParameters(); + deploymentParameters.PublishEnvironmentVariables.Add( + new KeyValuePair("CopyBuildOutputToPublishDirectory", "false")); + + return deploymentParameters; + } + } + } +} diff --git a/test/FunctionalTests/CopyOutputSymbolsToPublishDirectoryTest_CoreCLR.cs b/test/FunctionalTests/CopyOutputSymbolsToPublishDirectoryTest_CoreCLR.cs new file mode 100644 index 0000000000..bb55c6e838 --- /dev/null +++ b/test/FunctionalTests/CopyOutputSymbolsToPublishDirectoryTest_CoreCLR.cs @@ -0,0 +1,60 @@ +// 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 System.Threading.Tasks; +using Microsoft.AspNetCore.Server.IntegrationTesting; +using Microsoft.Extensions.Logging.Testing; +using Xunit; +using Xunit.Abstractions; + +namespace FunctionalTests +{ + public class CopyOutputSymbolsToPublishDirectoryTest_CoreCLR : + LoggedTest, IClassFixture + { + public CopyOutputSymbolsToPublishDirectoryTest_CoreCLR( + TestFixture fixture, + ITestOutputHelper output) + : base(output) + { + Fixture = fixture; + } + + public ApplicationTestFixture Fixture { get; } + + [Fact] + public async Task PublishingWithOption_SkipsPublishingPdb() + { + using (StartLog(out var loggerFactory)) + { + // Arrange + var deployment = await Fixture.CreateDeploymentAsync(loggerFactory); + + // Act & Assert + var dllFile = Path.Combine(deployment.ContentRoot, "SimpleApp.PrecompiledViews.dll"); + var pdbFile = Path.ChangeExtension(dllFile, ".pdb"); + Assert.True(File.Exists(dllFile), $"{dllFile} does not exist at deployment."); + Assert.False(File.Exists(pdbFile), $"{pdbFile} exists at deployment."); + } + } + + public class TestFixture : CoreCLRApplicationTestFixture + { + public TestFixture() + { + PublishOnly = true; + } + + protected override DeploymentParameters GetDeploymentParameters() + { + var deploymentParameters = base.GetDeploymentParameters(); + deploymentParameters.PublishEnvironmentVariables.Add( + new KeyValuePair("CopyOutputSymbolsToPublishDirectory", "false")); + + return deploymentParameters; + } + } + } +} diff --git a/test/FunctionalTests/CopyOutputSymbolsToPublishDirectoryTest_Desktop.cs b/test/FunctionalTests/CopyOutputSymbolsToPublishDirectoryTest_Desktop.cs new file mode 100644 index 0000000000..1152834603 --- /dev/null +++ b/test/FunctionalTests/CopyOutputSymbolsToPublishDirectoryTest_Desktop.cs @@ -0,0 +1,63 @@ +// 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 System.Threading.Tasks; +using Microsoft.AspNetCore.Server.IntegrationTesting; +using Microsoft.AspNetCore.Testing.xunit; +using Microsoft.Extensions.Logging.Testing; +using Xunit; +using Xunit.Abstractions; + +namespace FunctionalTests +{ + [OSSkipCondition(OperatingSystems.Linux)] + [OSSkipCondition(OperatingSystems.MacOSX)] + public class CopyOutputSymbolsToPublishDirectoryTest_Desktop : + LoggedTest, IClassFixture + { + public CopyOutputSymbolsToPublishDirectoryTest_Desktop( + TestFixture fixture, + ITestOutputHelper output) + : base(output) + { + Fixture = fixture; + } + + public ApplicationTestFixture Fixture { get; } + + [ConditionalFact] + public async Task PublishingWithOption_SkipsPublishingPdb() + { + using (StartLog(out var loggerFactory)) + { + // Arrange + var deployment = await Fixture.CreateDeploymentAsync(loggerFactory); + + // Act & Assert + var dllFile = Path.Combine(deployment.ContentRoot, "SimpleApp.PrecompiledViews.dll"); + var pdbFile = Path.ChangeExtension(dllFile, ".pdb"); + Assert.True(File.Exists(dllFile), $"{dllFile} does not exist at deployment."); + Assert.False(File.Exists(pdbFile), $"{pdbFile} exists at deployment."); + } + } + + public class TestFixture : DesktopApplicationTestFixture + { + public TestFixture() + { + PublishOnly = true; + } + + protected override DeploymentParameters GetDeploymentParameters() + { + var deploymentParameters = base.GetDeploymentParameters(); + deploymentParameters.PublishEnvironmentVariables.Add( + new KeyValuePair("CopyOutputSymbolsToPublishDirectory", "false")); + + return deploymentParameters; + } + } + } +} diff --git a/test/FunctionalTests/Infrastructure/ApplicationTestFixture.cs b/test/FunctionalTests/Infrastructure/ApplicationTestFixture.cs index 7ad4ea355f..051f4cf2b6 100644 --- a/test/FunctionalTests/Infrastructure/ApplicationTestFixture.cs +++ b/test/FunctionalTests/Infrastructure/ApplicationTestFixture.cs @@ -26,6 +26,8 @@ namespace FunctionalTests public string ApplicationPath { get; } + public bool PublishOnly { get; set; } + protected abstract DeploymentParameters GetDeploymentParameters(); protected DeploymentParameters GetDeploymentParameters(RuntimeFlavor flavor) @@ -77,7 +79,15 @@ namespace FunctionalTests if (_deploymentTask == null) { var deploymentParameters = GetDeploymentParameters(); - _deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory); + if (PublishOnly) + { + _deployer = new PublishOnlyDeployer(deploymentParameters, loggerFactory); + } + else + { + _deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory); + } + _deploymentTask = _deployer.DeployAsync(); } } diff --git a/test/FunctionalTests/Infrastructure/PublishOnlyDeployer.cs b/test/FunctionalTests/Infrastructure/PublishOnlyDeployer.cs new file mode 100644 index 0000000000..82a84209eb --- /dev/null +++ b/test/FunctionalTests/Infrastructure/PublishOnlyDeployer.cs @@ -0,0 +1,47 @@ +// 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; +using System.Diagnostics; +using System.IO; +using System.Runtime.InteropServices; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.IntegrationTesting.Common; +using Microsoft.AspNetCore.Testing; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Server.IntegrationTesting +{ + public class PublishOnlyDeployer : SelfHostDeployer + { + public PublishOnlyDeployer(DeploymentParameters deploymentParameters, ILoggerFactory loggerFactory) + : base(deploymentParameters, loggerFactory) + { + } + + public override Task DeployAsync() + { + using (Logger.BeginScope("SelfHost.Deploy")) + { + // Start timer + StartTimer(); + + if (DeploymentParameters.PublishApplicationBeforeDeployment) + { + DotnetPublish(); + } + + var result = new DeploymentResult( + LoggerFactory, + DeploymentParameters, + applicationBaseUri: "http://localhost", + contentRoot: DeploymentParameters.PublishApplicationBeforeDeployment ? DeploymentParameters.PublishedApplicationRootPath : DeploymentParameters.ApplicationPath, + hostShutdownToken: default(CancellationToken)); + + return Task.FromResult(result); + } + } + } +} diff --git a/test/FunctionalTests/ViewCompilationOptionsTest_CoreCLR.cs b/test/FunctionalTests/ViewCompilationOptionsTest_CoreCLR.cs index d4fc86f303..6b80eca31d 100644 --- a/test/FunctionalTests/ViewCompilationOptionsTest_CoreCLR.cs +++ b/test/FunctionalTests/ViewCompilationOptionsTest_CoreCLR.cs @@ -39,6 +39,11 @@ namespace FunctionalTests public class TestFixture : CoreCLRApplicationTestFixture { + public TestFixture() + { + PublishOnly = true; + } + protected override DeploymentParameters GetDeploymentParameters() { var deploymentParameters = base.GetDeploymentParameters(); diff --git a/test/FunctionalTests/ViewCompilationOptionsTest_Desktop.cs b/test/FunctionalTests/ViewCompilationOptionsTest_Desktop.cs index abd3371446..053b7456a9 100644 --- a/test/FunctionalTests/ViewCompilationOptionsTest_Desktop.cs +++ b/test/FunctionalTests/ViewCompilationOptionsTest_Desktop.cs @@ -42,6 +42,11 @@ namespace FunctionalTests public class TestFixture : DesktopApplicationTestFixture { + public TestFixture() + { + PublishOnly = true; + } + protected override DeploymentParameters GetDeploymentParameters() { var deploymentParameters = base.GetDeploymentParameters();