From ad724f6b0a63685b6d56150f3a698121de349ba3 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Tue, 27 Mar 2018 12:27:46 -0700 Subject: [PATCH] Use x64 binaries when project's targeting AnyCPU (#255) * Use x64 binaries when project's targeting AnyCPU Fixes https://github.com/aspnet/MvcPrecompilation/issues/240 --- ...pNetCore.Mvc.Razor.ViewCompilation.targets | 14 +++-- .../PublishWithDebugTest_Desktop.cs | 3 +- .../SimpleAppTest_WithAnyCPU_Desktop.cs | 58 +++++++++++++++++++ test/FunctionalTests/FunctionalTests.csproj | 4 +- 4 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 test/FunctionalTests/DesktopTests/SimpleAppTest_WithAnyCPU_Desktop.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 a004fb4821..35c2d5d47b 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 @@ -85,8 +85,10 @@ Condition="'$(MvcRazorCompileOnPublish)'=='true' AND '$(_MvcViewCompilationAddDesktopReferences)'!='false' AND '$(TargetFrameworkIdentifier)'=='.NETFramework'"> - <_MvcViewCompilationBinaryPath Condition="'$(PlatformTarget)'=='x64'">$(MSBuildThisFileDirectory)$(MSBuildThisFileName)-x64.exe <_MvcViewCompilationBinaryPath Condition="'$(PlatformTarget)'=='x86'">$(MSBuildThisFileDirectory)$(MSBuildThisFileName)-x86.exe + + + <_MvcViewCompilationBinaryPath Condition="'$(_MvcViewCompilationBinaryPath)'==''">$(MSBuildThisFileDirectory)$(MSBuildThisFileName)-x64.exe @@ -99,18 +101,22 @@ DependsOnTargets="_AddDesktopReferences;_CreateResponseFileForMvcRazorPrecompile" Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework'"> + + <_MvcViewCompilationBinaryName>$([System.IO.Path]::GetFileName('$(_MvcViewCompilationBinaryPath)')) + + <_PreCompilationFilesToCopy Include="$(OutputPath)$(AssemblyName).exe.config" - Destination="$(OutputPath)$(MSBuildThisFileName)-$(PlatformTarget).exe.config" /> + Destination="$(OutputPath)$(_MvcViewCompilationBinaryName).config" /> <_PreCompilationFilesToCopy Include="$(_MvcViewCompilationBinaryPath)" - Destination="$(OutputPath)$(MSBuildThisFileName)-$(PlatformTarget).exe" /> + Destination="$(OutputPath)$(_MvcViewCompilationBinaryName)" /> - $(OutputPath)$(MSBuildThisFileName)-$(PlatformTarget).exe + $(OutputPath)$(_MvcViewCompilationBinaryName) + public class TestFixture : DesktopApplicationTestFixture { public TestFixture() { diff --git a/test/FunctionalTests/DesktopTests/SimpleAppTest_WithAnyCPU_Desktop.cs b/test/FunctionalTests/DesktopTests/SimpleAppTest_WithAnyCPU_Desktop.cs new file mode 100644 index 0000000000..4e114ff218 --- /dev/null +++ b/test/FunctionalTests/DesktopTests/SimpleAppTest_WithAnyCPU_Desktop.cs @@ -0,0 +1,58 @@ +// 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.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 | OperatingSystems.MacOSX)] + public class SimpleAppTest_WithAnyCPU_Desktop : + LoggedTest, IClassFixture + { + public SimpleAppTest_WithAnyCPU_Desktop( + TestFixture fixture, + ITestOutputHelper output) + : base(output) + { + Fixture = fixture; + } + + public ApplicationTestFixture Fixture { get; } + + [ConditionalFact] + public async Task Precompilation_WorksForSimpleApps_BuiltWithPlatformTargetAnyCPU() + { + using (StartLog(out var loggerFactory)) + { + // Arrange + var deployment = await Fixture.CreateDeploymentAsync(loggerFactory); + + // Act & Assert + var dllFile = Path.Combine(deployment.ContentRoot, "SimpleApp.PrecompiledViews.dll"); + Assert.True(File.Exists(dllFile), $"{dllFile} exists at deployment."); + } + } + + public class TestFixture : DesktopApplicationTestFixture + { + public TestFixture() + { + PublishOnly = true; + } + + protected override DeploymentParameters GetDeploymentParameters() + { + var deploymentParameters = base.GetDeploymentParameters(); + deploymentParameters.AdditionalPublishParameters = "/p:PlatformTarget=AnyCPU"; + + return deploymentParameters; + } + } + } +} diff --git a/test/FunctionalTests/FunctionalTests.csproj b/test/FunctionalTests/FunctionalTests.csproj index b904adea49..93409efa46 100644 --- a/test/FunctionalTests/FunctionalTests.csproj +++ b/test/FunctionalTests/FunctionalTests.csproj @@ -1,8 +1,7 @@  - netcoreapp2.1 - $(TargetFrameworks);netcoreapp2.0 + $(StandardTestTfms) $(DefineConstants);__remove_this_to__GENERATE_BASELINES $(DefineConstants);GENERATE_BASELINES @@ -33,7 +32,6 @@ -