Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

Commit

Permalink
Add support for cross-publishing
Browse files Browse the repository at this point in the history
Fixes #102
  • Loading branch information
pranavkm committed Aug 25, 2017
1 parent efa82ce commit e27c6f6
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="_ResolveInputArguments">
<PropertyGroup>
<_MvcRazorOutputPath Condition="'$(MvcRazorOutputPath)'!=''">$([MSBuild]::EnsureTrailingSlash('$(MvcRazorOutputPath)'))</_MvcRazorOutputPath>
<_MvcRazorOutputPath Condition="'$(_MvcRazorOutputPath)'==''">$(IntermediateOutputPath)</_MvcRazorOutputPath>
<_MvcRazorOutputFullPath>$(_MvcRazorOutputPath)$(AssemblyName).PrecompiledViews.dll</_MvcRazorOutputFullPath>
<MvcRazorOutputPath Condition="'$(MvcRazorOutputPath)'==''">$(IntermediateOutputPath)</MvcRazorOutputPath>
<_MvcRazorOutputFullPath Condition="'$(_MvcRazorOutputFullPath)'==''">$([MSBuild]::EnsureTrailingSlash('$(MvcRazorOutputPath)'))$(AssemblyName).PrecompiledViews.dll</_MvcRazorOutputFullPath>
<_MvcRazorResponseFilePath>$(IntermediateOutputPath)microsoft.aspnetcore.mvc.razor.viewcompilation.rsp</_MvcRazorResponseFilePath>

<MvcRazorContentRoot Condition="'$(MvcRazorContentRoot)'==''">$(MSBuildProjectDirectory)</MvcRazorContentRoot>
Expand All @@ -25,7 +24,7 @@
<CallTarget Targets="_MvcRazorPrecompile" />
</Target>

<Target Name="_MvcRazorPrecompile" DependsOnTargets="_RunForCore;_RunForDesktop" />
<Target Name="_MvcRazorPrecompile" DependsOnTargets="_RunForCore;_RunForCoreWithRID;_RunForDesktop" />

<PropertyGroup>
<_MvcViewCompilationTasksPath Condition="'$(_MvcViewCompilationTasksPath)'==''">$(MSBuildThisFileDirectory)$(MSBuildThisFileName).Tasks.dll</_MvcViewCompilationTasksPath>
Expand Down Expand Up @@ -60,6 +59,22 @@
<Exec Command="$(ExecArgs)" WorkingDirectory="$(MSBuildProjectDirectory)" />
</Target>

<Target
Name="_RunForCoreWithRID"
DependsOnTargets="_ResolveInputArguments;_CreateResponseFileForMvcRazorPrecompile"
Condition="'$(TargetFrameworkIdentifier)'=='.NETCoreApp' And '$(RuntimeIdentifier)'!=''">

<ItemGroup>
<_RazorCompilationProject Include="$(MSBuildProjectFullPath)">
<AdditionalProperties>RuntimeIdentifier=;MvcRazorOutputPath=$(MvcRazorOutputPath)</AdditionalProperties>
</_RazorCompilationProject>
</ItemGroup>

<MSBuild
Projects="@(_RazorCompilationProject)"
Targets="Build;MvcRazorPrecompile" />
</Target>

<Target
Name="_AddDesktopReferences"
AfterTargets="ResolveLockFileReferences"
Expand Down Expand Up @@ -109,7 +124,7 @@
<ItemGroup>
<_ResponseFileLines Include="
$(MSBuildProjectDirectory);
--output-path=$(_MvcRazorOutputPath);
--output-path=$(MvcRazorOutputPath);
--application-name=$(AssemblyName);
--content-root=$(MvcRazorContentRoot);" />

Expand Down Expand Up @@ -144,7 +159,7 @@

<Target Name="_MvcRazorResolveFilesToCompute"
AfterTargets="ComputeRefAssembliesToPublish"
Condition="'$(MvcRazorCompileOnPublish)'=='true' AND ('$(TargetFrameworkIdentifier)'!='.NETCoreApp' OR '$(RuntimeIdentifier)'=='')">
Condition="'$(MvcRazorCompileOnPublish)'=='true'">

<PropertyGroup>
<_MvcRazorOutputPdbFullPath>$([System.IO.Path]::ChangeExtension('$(_MvcRazorOutputFullPath)', '.pdb'))</_MvcRazorOutputPdbFullPath>
Expand Down
7 changes: 5 additions & 2 deletions test/FunctionalTests/Infrastructure/ApplicationTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,21 @@ protected ApplicationTestFixture(string applicationName, string applicationPath)
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<string, string>(
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",
Expand Down
72 changes: 72 additions & 0 deletions test/FunctionalTests/PublishForRidTest_CoreCLR.cs
Original file line number Diff line number Diff line change
@@ -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<DeploymentResult> DeployAsync() => throw new NotSupportedException();
}
}
}

0 comments on commit e27c6f6

Please sign in to comment.