Honor CopyBuildOutputToPublishDirectory and CopyOutputSymbolsToPublishDirectory switches

Fixes #204
This commit is contained in:
Pranav K 2017-09-25 09:17:54 -07:00
parent 05d077da43
commit 311c52b12e
9 changed files with 320 additions and 3 deletions

View File

@ -170,11 +170,15 @@
Remove="%(MvcRazorFilesToCompile.FullPath)"
Condition="'$(MvcRazorExcludeViewFilesFromPublish)'=='true'" />
<ResolvedFileToPublish Include="$(_MvcRazorOutputFullPath)" CopyToPublishDirectory="Always" Condition="Exists('$(_MvcRazorOutputFullPath)')">
<ResolvedFileToPublish Include="$(_MvcRazorOutputFullPath)"
CopyToPublishDirectory="Always"
Condition="'$(CopyBuildOutputToPublishDirectory)'=='true' AND Exists('$(_MvcRazorOutputFullPath)')">
<RelativePath>$([System.IO.Path]::GetFileName('$(_MvcRazorOutputFullPath)'))</RelativePath>
</ResolvedFileToPublish>
<ResolvedFileToPublish Include="$(_MvcRazorOutputPdbFullPath)" CopyToPublishDirectory="Always" Condition="Exists('$(_MvcRazorOutputPdbFullPath)')">
<ResolvedFileToPublish Include="$(_MvcRazorOutputPdbFullPath)"
CopyToPublishDirectory="Always"
Condition="'$(CopyOutputSymbolsToPublishDirectory)'=='true'AND Exists('$(_MvcRazorOutputPdbFullPath)')">
<RelativePath>$([System.IO.Path]::GetFileName('$(_MvcRazorOutputPdbFullPath)'))</RelativePath>
</ResolvedFileToPublish>
</ItemGroup>

View File

@ -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<CopyBuildOutputToPublishDirectoryTest_Desktop.TestFixture>
{
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<SimpleApp.Startup>
{
public TestFixture()
{
PublishOnly = true;
}
protected override DeploymentParameters GetDeploymentParameters()
{
var deploymentParameters = base.GetDeploymentParameters();
deploymentParameters.PublishEnvironmentVariables.Add(
new KeyValuePair<string, string>("CopyBuildOutputToPublishDirectory", "false"));
return deploymentParameters;
}
}
}
}

View File

@ -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<CopyBuildOutputToPublishDirectory_CoreCLR.TestFixture>
{
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<SimpleApp.Startup>
{
public TestFixture()
{
PublishOnly = true;
}
protected override DeploymentParameters GetDeploymentParameters()
{
var deploymentParameters = base.GetDeploymentParameters();
deploymentParameters.PublishEnvironmentVariables.Add(
new KeyValuePair<string, string>("CopyBuildOutputToPublishDirectory", "false"));
return deploymentParameters;
}
}
}
}

View File

@ -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<CopyOutputSymbolsToPublishDirectoryTest_CoreCLR.TestFixture>
{
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<SimpleApp.Startup>
{
public TestFixture()
{
PublishOnly = true;
}
protected override DeploymentParameters GetDeploymentParameters()
{
var deploymentParameters = base.GetDeploymentParameters();
deploymentParameters.PublishEnvironmentVariables.Add(
new KeyValuePair<string, string>("CopyOutputSymbolsToPublishDirectory", "false"));
return deploymentParameters;
}
}
}
}

View File

@ -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<CopyOutputSymbolsToPublishDirectoryTest_Desktop.TestFixture>
{
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<SimpleApp.Startup>
{
public TestFixture()
{
PublishOnly = true;
}
protected override DeploymentParameters GetDeploymentParameters()
{
var deploymentParameters = base.GetDeploymentParameters();
deploymentParameters.PublishEnvironmentVariables.Add(
new KeyValuePair<string, string>("CopyOutputSymbolsToPublishDirectory", "false"));
return deploymentParameters;
}
}
}
}

View File

@ -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();
}
}

View File

@ -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<DeploymentResult> 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);
}
}
}
}

View File

@ -39,6 +39,11 @@ namespace FunctionalTests
public class TestFixture : CoreCLRApplicationTestFixture<SimpleApp.Startup>
{
public TestFixture()
{
PublishOnly = true;
}
protected override DeploymentParameters GetDeploymentParameters()
{
var deploymentParameters = base.GetDeploymentParameters();

View File

@ -42,6 +42,11 @@ namespace FunctionalTests
public class TestFixture : DesktopApplicationTestFixture<SimpleApp.Startup>
{
public TestFixture()
{
PublishOnly = true;
}
protected override DeploymentParameters GetDeploymentParameters()
{
var deploymentParameters = base.GetDeploymentParameters();