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 0bd06d102f..a67c93c946 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 @@ -1,9 +1,8 @@ - <_MvcRazorOutputPath Condition="'$(MvcRazorOutputPath)'!=''">$([MSBuild]::EnsureTrailingSlash('$(MvcRazorOutputPath)')) - <_MvcRazorOutputPath Condition="'$(_MvcRazorOutputPath)'==''">$(IntermediateOutputPath) - <_MvcRazorOutputFullPath>$(_MvcRazorOutputPath)$(AssemblyName).PrecompiledViews.dll + $(IntermediateOutputPath) + <_MvcRazorOutputFullPath Condition="'$(_MvcRazorOutputFullPath)'==''">$([MSBuild]::EnsureTrailingSlash('$(MvcRazorOutputPath)'))$(AssemblyName).PrecompiledViews.dll <_MvcRazorResponseFilePath>$(IntermediateOutputPath)microsoft.aspnetcore.mvc.razor.viewcompilation.rsp $(MSBuildProjectDirectory) @@ -25,7 +24,7 @@ - + <_MvcViewCompilationTasksPath Condition="'$(_MvcViewCompilationTasksPath)'==''">$(MSBuildThisFileDirectory)$(MSBuildThisFileName).Tasks.dll @@ -60,6 +59,22 @@ + + + + <_RazorCompilationProject Include="$(MSBuildProjectFullPath)"> + RuntimeIdentifier=;MvcRazorOutputPath=$(MvcRazorOutputPath) + + + + + + <_ResponseFileLines Include=" $(MSBuildProjectDirectory); - --output-path=$(_MvcRazorOutputPath); + --output-path=$(MvcRazorOutputPath); --application-name=$(AssemblyName); --content-root=$(MvcRazorContentRoot);" /> @@ -144,7 +159,7 @@ + Condition="'$(MvcRazorCompileOnPublish)'=='true'"> <_MvcRazorOutputPdbFullPath>$([System.IO.Path]::ChangeExtension('$(_MvcRazorOutputFullPath)', '.pdb')) diff --git a/test/FunctionalTests/Infrastructure/ApplicationTestFixture.cs b/test/FunctionalTests/Infrastructure/ApplicationTestFixture.cs index fa8631ce02..7ad4ea355f 100644 --- a/test/FunctionalTests/Infrastructure/ApplicationTestFixture.cs +++ b/test/FunctionalTests/Infrastructure/ApplicationTestFixture.cs @@ -29,18 +29,21 @@ namespace FunctionalTests protected abstract DeploymentParameters GetDeploymentParameters(); protected DeploymentParameters GetDeploymentParameters(RuntimeFlavor flavor) + => GetDeploymentParameters(ApplicationPath, ApplicationName, flavor); + + public static DeploymentParameters GetDeploymentParameters(string applicationPath, string applicationName, RuntimeFlavor flavor) { var telemetryOptOut = new KeyValuePair( DotnetCLITelemetryOptOut, "1"); var deploymentParameters = new DeploymentParameters( - ApplicationPath, + applicationPath, ServerType.Kestrel, flavor, RuntimeArchitecture.x64) { - ApplicationName = ApplicationName, + ApplicationName = applicationName, PublishApplicationBeforeDeployment = true, TargetFramework = flavor == RuntimeFlavor.Clr ? "net461" : "netcoreapp2.0", Configuration = "Release", diff --git a/test/FunctionalTests/PublishForRidTest_CoreCLR.cs b/test/FunctionalTests/PublishForRidTest_CoreCLR.cs new file mode 100644 index 0000000000..fdbdcc96cd --- /dev/null +++ b/test/FunctionalTests/PublishForRidTest_CoreCLR.cs @@ -0,0 +1,72 @@ +// 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.IO; +using System.Runtime.InteropServices; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.IntegrationTesting; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Testing; +using Xunit; +using Xunit.Abstractions; + +namespace FunctionalTests +{ + public class PublishWithRidTest_CoreCLR : LoggedTest + { + public PublishWithRidTest_CoreCLR(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void CrossPublishingWorks() + { + using (StartLog(out var loggerFactory)) + { + // Arrange + var applicationName = nameof(SimpleApp); + var applicationPath = ApplicationPaths.GetTestAppDirectory(applicationName); + var deploymentParameters = ApplicationTestFixture.GetDeploymentParameters( + applicationPath, + applicationName, + RuntimeFlavor.CoreClr); + + // Deploy for a rid that does not exist on the current platform. + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + deploymentParameters.AdditionalPublishParameters = "-r debian-x64"; + } + else + { + deploymentParameters.AdditionalPublishParameters = "-r win7-x86"; + } + var deployer = new DotNetPublishDeployer(deploymentParameters, loggerFactory); + + // Act + deployer.DotnetPublish(); + + // Act + var expectedFile = Path.Combine( + deploymentParameters.PublishedApplicationRootPath, + $"{applicationName}.PrecompiledViews.dll"); + Assert.True(File.Exists(expectedFile), $"Expected precompiled file {expectedFile} does not exist."); + } + } + + private class DotNetPublishDeployer : ApplicationDeployer + { + public DotNetPublishDeployer(DeploymentParameters deploymentParameters, ILoggerFactory loggerFactory) + : base(deploymentParameters, loggerFactory) + { + } + + public void DotnetPublish() => base.DotnetPublish(); + + public override void Dispose() => CleanPublishedOutput(); + + public override Task DeployAsync() => throw new NotSupportedException(); + } + } +}