diff --git a/build/repo.targets b/build/repo.targets index 4841052ed6..2e234b2b72 100644 --- a/build/repo.targets +++ b/build/repo.targets @@ -7,4 +7,27 @@ Configuration=$(Configuration)NoVSIX + + + $(PrepareDependsOn);GenerateMSBuildLocationFile + $(RepositoryRoot)test\Microsoft.AspNetCore.Razor.Design.Test\ + $(RazorDesignTestProject)BuildVariables.cs.template + $(RazorDesignTestProject)obj\BuildVariables.generated.cs + + + + + + MSBuildLocation=$(VisualStudioMSBuildx86Path) + + + + + diff --git a/test/Microsoft.AspNetCore.Razor.Design.Test/BuildVariables.cs b/test/Microsoft.AspNetCore.Razor.Design.Test/BuildVariables.cs new file mode 100644 index 0000000000..6efdf63efc --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Design.Test/BuildVariables.cs @@ -0,0 +1,21 @@ +// 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. + +namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests +{ + internal static partial class BuildVariables + { + private static string _msBuildPath = ""; + + static partial void InitializeVariables(); + + public static string MSBuildPath + { + get + { + InitializeVariables(); + return _msBuildPath; + } + } + } +} diff --git a/test/Microsoft.AspNetCore.Razor.Design.Test/BuildVariables.cs.template b/test/Microsoft.AspNetCore.Razor.Design.Test/BuildVariables.cs.template new file mode 100644 index 0000000000..e31b16adc7 --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Design.Test/BuildVariables.cs.template @@ -0,0 +1,13 @@ +// 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. + +namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests +{ + internal static partial class BuildVariables + { + static partial void InitializeVariables() + { + _msBuildPath = @"${MSBuildLocation}"; + } + } +} diff --git a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/BuildIntegrationTest.cs b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/BuildIntegrationTest.cs index b838503e58..7b82f60110 100644 --- a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/BuildIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/BuildIntegrationTest.cs @@ -3,6 +3,7 @@ using System.IO; using System.Threading.Tasks; +using Microsoft.AspNetCore.Testing.xunit; using Microsoft.DotNet.PlatformAbstractions; using Xunit; @@ -12,9 +13,19 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests { [Fact] [InitializeTestProject("SimpleMvc")] - public async Task Build_SimpleMvc_CanBuildSuccessfully() + public Task Build_SimpleMvc_UsingDotnetMSBuild_CanBuildSuccessfully() + => Build_SimpleMvc_CanBuildSuccessfully(MSBuildProcessKind.Dotnet); + + [ConditionalFact] + [OSSkipCondition(OperatingSystems.Linux)] + [OSSkipCondition(OperatingSystems.MacOSX)] + [InitializeTestProject("SimpleMvc")] + public Task Build_SimpleMvc_UsingDesktopMSBuild_CanBuildSuccessfully() + => Build_SimpleMvc_CanBuildSuccessfully(MSBuildProcessKind.Desktop); + + private async Task Build_SimpleMvc_CanBuildSuccessfully(MSBuildProcessKind msBuildProcessKind) { - var result = await DotnetMSBuild("Build", "/p:RazorCompileOnBuild=true"); + var result = await DotnetMSBuild("Build", "/p:RazorCompileOnBuild=true", msBuildProcessKind: msBuildProcessKind); Assert.BuildPassed(result); Assert.FileExists(result, OutputPath, "SimpleMvc.dll"); diff --git a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/MSBuildIntegrationTestBase.cs b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/MSBuildIntegrationTestBase.cs index dd051029b3..cbc17d1bbc 100644 --- a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/MSBuildIntegrationTestBase.cs +++ b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/MSBuildIntegrationTestBase.cs @@ -42,12 +42,21 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests protected string TargetFramework { get; set; } = "netcoreapp2.0"; - internal Task DotnetMSBuild(string target, string args = null, bool suppressRestore = false, bool suppressTimeout = false) + internal Task DotnetMSBuild( + string target, + string args = null, + bool suppressRestore = false, + bool suppressTimeout = false, + MSBuildProcessKind msBuildProcessKind = MSBuildProcessKind.Dotnet) { var timeout = suppressTimeout ? (TimeSpan?)Timeout.InfiniteTimeSpan : null; var restoreArgument = suppressRestore ? "" : "/restore"; - return MSBuildProcessManager.RunProcessAsync(Project, $"{restoreArgument} /t:{target} /p:Configuration={Configuration} {args}", timeout); + return MSBuildProcessManager.RunProcessAsync( + Project, + $"{restoreArgument} /t:{target} /p:Configuration={Configuration} {args}", + timeout, + msBuildProcessKind); } internal void ReplaceContent(string content, params string[] paths) diff --git a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/MSBuildProcessKind.cs b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/MSBuildProcessKind.cs new file mode 100644 index 0000000000..dab7e73fee --- /dev/null +++ b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/MSBuildProcessKind.cs @@ -0,0 +1,20 @@ +// 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.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests +{ + internal enum MSBuildProcessKind + { + /// dotnet msbuild + Dotnet, + + /// msbuild.exe + Desktop, + } +} diff --git a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/MSBuildProcessManager.cs b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/MSBuildProcessManager.cs index 634d9c6e77..70b43448e4 100644 --- a/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/MSBuildProcessManager.cs +++ b/test/Microsoft.AspNetCore.Razor.Design.Test/IntegrationTests/MSBuildProcessManager.cs @@ -11,21 +11,41 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests { internal static class MSBuildProcessManager { - public static Task RunProcessAsync(ProjectDirectory project, string arguments, TimeSpan? timeout = null) + public static Task RunProcessAsync( + ProjectDirectory project, + string arguments, + TimeSpan? timeout = null, + MSBuildProcessKind msBuildProcessKind = MSBuildProcessKind.Dotnet) { timeout = timeout ?? TimeSpan.FromSeconds(30); + var processStartInfo = new ProcessStartInfo() + { + WorkingDirectory = project.DirectoryPath, + UseShellExecute = false, + RedirectStandardError = true, + RedirectStandardOutput = true, + }; + + if (msBuildProcessKind == MSBuildProcessKind.Desktop) + { + if (string.IsNullOrEmpty(BuildVariables.MSBuildPath)) + { + throw new ArgumentException("Unable to locate MSBuild.exe to run desktop tests."); + } + + processStartInfo.FileName = BuildVariables.MSBuildPath; + processStartInfo.Arguments = arguments; + } + else + { + processStartInfo.FileName = "dotnet"; + processStartInfo.Arguments = $"msbuild {arguments}"; + } + var process = new Process() { - StartInfo = new ProcessStartInfo() - { - FileName = "dotnet", - Arguments = "msbuild " + arguments, - WorkingDirectory = project.DirectoryPath, - UseShellExecute = false, - RedirectStandardError = true, - RedirectStandardOutput = true, - }, + StartInfo = processStartInfo, EnableRaisingEvents = true, }; diff --git a/test/Microsoft.AspNetCore.Razor.Design.Test/Microsoft.AspNetCore.Razor.Design.Test.csproj b/test/Microsoft.AspNetCore.Razor.Design.Test/Microsoft.AspNetCore.Razor.Design.Test.csproj index 4377052fc5..2707dc5013 100644 --- a/test/Microsoft.AspNetCore.Razor.Design.Test/Microsoft.AspNetCore.Razor.Design.Test.csproj +++ b/test/Microsoft.AspNetCore.Razor.Design.Test/Microsoft.AspNetCore.Razor.Design.Test.csproj @@ -12,10 +12,13 @@ $(DefineConstants);PRESERVE_WORKING_DIRECTORY true + $(MSBuildProjectDirectory)\obj\BuildVariables.generated.cs + EnsureBuildVariablesGeneratedFile;$(CompileDependsOn) + @@ -40,5 +43,11 @@ false + + + +