From 5567239a9411aac769a34f2c65b80a523a577ad7 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 6 Oct 2022 11:59:31 -0700 Subject: Run wix.exe out of proc "wix build" will load assemblies to read metadata which can cause the assemblies to get locked in the process. Since MSBuild keeps build processes alive this can cause work done by in-proc MSBuild tasks (like the WixBuild) to get stuck. Moving the "wix build" out of proc avoids any of those issues. Moving out of proc also allows the WiX tasks to be AnyCPU which simplifies the wix.targets (although did need to add code to find the .NET Framework wix.exe). Fixes 6595 --- .../WixBuildTools.TestSupport/MsbuildUtilities.cs | 13 +-- src/internal/internal.cmd | 25 ++++- src/internal/internal_t.proj | 7 ++ src/testresultfilelist.txt | 3 +- .../WixToolset.HeatTasks.csproj | 1 - .../WixToolsetTest.HeatTasks/MsbuildHeatFixture.cs | 8 +- src/wix/Directory.Build.props | 4 + .../MsbuildMessageListener.cs | 68 ------------ src/wix/WixToolset.BuildTasks/ToolsetTask.cs | 121 ++++++++++++--------- .../WixToolset.BuildTasks/ToolsetTask_InProc.cs | 79 -------------- src/wix/WixToolset.BuildTasks/WixExeBaseTask.cs | 2 +- .../WixToolset.BuildTasks/WixExeBaseTask_Inproc.cs | 28 ----- .../WixToolset.BuildTasks.csproj | 11 -- src/wix/WixToolset.Sdk/WixToolset.Sdk.csproj | 2 +- .../tools/WixToolset.Signing.targets | 3 - src/wix/WixToolset.Sdk/tools/wix.targets | 46 ++------ src/wix/publish_t.proj | 37 +++++-- .../WixBuildTaskFixture.cs | 21 +++- .../WixToolsetTest.BuildTasks.csproj | 3 +- src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs | 47 ++++---- src/wix/wix.cmd | 64 ++++++----- 21 files changed, 226 insertions(+), 367 deletions(-) create mode 100644 src/internal/internal_t.proj delete mode 100644 src/wix/WixToolset.BuildTasks/MsbuildMessageListener.cs delete mode 100644 src/wix/WixToolset.BuildTasks/ToolsetTask_InProc.cs delete mode 100644 src/wix/WixToolset.BuildTasks/WixExeBaseTask_Inproc.cs (limited to 'src') diff --git a/src/internal/WixBuildTools.TestSupport/MsbuildUtilities.cs b/src/internal/WixBuildTools.TestSupport/MsbuildUtilities.cs index 32680e5d..3271cc20 100644 --- a/src/internal/WixBuildTools.TestSupport/MsbuildUtilities.cs +++ b/src/internal/WixBuildTools.TestSupport/MsbuildUtilities.cs @@ -17,7 +17,7 @@ namespace WixToolsetTest.Sdk public static class MsbuildUtilities { - public static MsbuildRunnerResult BuildProject(BuildSystem buildSystem, string projectPath, string[] arguments = null, string configuration = "Release", bool? outOfProc = null, string verbosityLevel = "normal", bool suppressValidation = true) + public static MsbuildRunnerResult BuildProject(BuildSystem buildSystem, string projectPath, string[] arguments = null, string configuration = "Release", string verbosityLevel = "normal", bool suppressValidation = true) { var allArgs = new List { @@ -30,11 +30,6 @@ namespace WixToolsetTest.Sdk $"-bl:{Path.ChangeExtension(projectPath, ".binlog")}" }; - if (outOfProc.HasValue) - { - allArgs.Add($"-p:RunWixToolsOutOfProc={outOfProc.Value}"); - } - if (arguments != null) { allArgs.AddRange(arguments); @@ -96,11 +91,9 @@ namespace WixToolsetTest.Sdk } } - public static IEnumerable GetToolCommandLines(MsbuildRunnerResult result, string toolName, string operation, BuildSystem buildSystem, bool? outOfProc = null) + public static IEnumerable GetToolCommandLines(MsbuildRunnerResult result, string toolName, string operation, BuildSystem buildSystem) { - var expectedOutOfProc = buildSystem == BuildSystem.DotNetCoreSdk || outOfProc.HasValue && outOfProc.Value; - var expectedToolExe = !expectedOutOfProc ? $"({toolName}.exe)" : - buildSystem == BuildSystem.DotNetCoreSdk ? $"{toolName}.dll\"" : $"{toolName}.exe"; + var expectedToolExe = buildSystem == BuildSystem.DotNetCoreSdk ? $"{toolName}.dll\"" : $"{toolName}.exe"; var expectedToolCommand = $"{expectedToolExe} {operation}"; return result.Output.Where(line => line.Contains(expectedToolCommand)); } diff --git a/src/internal/internal.cmd b/src/internal/internal.cmd index 8b46e77c..9380ce4e 100644 --- a/src/internal/internal.cmd +++ b/src/internal/internal.cmd @@ -2,10 +2,21 @@ @pushd %~dp0 @set _C=Debug +@set _L=%~dp0..\..\build\logs + :parse_args @if /i "%1"=="release" set _C=Release +@if /i "%1"=="inc" set _INC=1 +@if /i "%1"=="clean" set _CLEAN=1 @if not "%1"=="" shift & goto parse_args +@set _B=%~dp0..\..\build\wix\%_C% + +:: Clean + +@if "%_INC%"=="" call :clean +@if NOT "%_CLEAN%"=="" goto :end + @echo Building internal %_C% :: internal @@ -14,10 +25,18 @@ nuget restore || exit /b :: dotnet pack -c %_C% WixBuildTools.MsgGen\WixBuildTools.MsgGen.csproj || exit /b :: dotnet pack -c %_C% WixBuildTools.XsdGen\WixBuildTools.XsdGen.csproj || exit /b -msbuild -t:Pack WixBuildTools.TestSupport\WixBuildTools.TestSupport.csproj -p:Configuration=%_C% -nologo -m -warnaserror -bl:..\..\build\logs\internal_build.binlog || exit /b +msbuild internal_t.proj -p:Configuration=%_C% -nologo -warnaserror -bl:%_L%\internal_build.binlog || exit /b + +@goto :end -msbuild -t:Build WixBuildTools.TestSupport.Native\WixBuildTools.TestSupport.Native.vcxproj -p:Configuration=%_C%;Platform=x86 -nologo || exit /b -msbuild -t:Build WixBuildTools.TestSupport.Native\WixBuildTools.TestSupport.Native.vcxproj -p:Configuration=%_C%;Platform=x64 -nologo || exit /b +:clean +@rd /s/q "..\..\build\internal" 2> nul +@del "..\..\build\artifacts\WixBuildTools.TestSupport.*.nupkg" 2> nul +@del "..\..\build\artifacts\WixBuildTools.TestSupport.Native.*.nupkg" 2> nul +@rd /s/q "%USERPROFILE%\.nuget\packages\wixbuildtools.testsupport" 2> nul +@rd /s/q "%USERPROFILE%\.nuget\packages\wixbuildtools.testsupport.native" 2> nul +@exit /b +:end @popd @endlocal diff --git a/src/internal/internal_t.proj b/src/internal/internal_t.proj new file mode 100644 index 00000000..fda67786 --- /dev/null +++ b/src/internal/internal_t.proj @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/testresultfilelist.txt b/src/testresultfilelist.txt index 43e5df11..6a2eadcb 100644 --- a/src/testresultfilelist.txt +++ b/src/testresultfilelist.txt @@ -2,8 +2,7 @@ build/logs/TestResults/api.trx build/logs/TestResults/burn.trx build/logs/TestResults/libs.trx build/logs/TestResults/tools.trx -build/logs/TestResults/wix_prepublish.trx -build/logs/TestResults/wix_postpublish.trx +build/logs/TestResults/wix.trx build/logs/TestResults/WixToolsetTest.Bal.trx build/logs/TestResults/WixToolsetTest.BurnE2E.trx build/logs/TestResults/WixToolsetTest.Dnc.HostGenerator.trx diff --git a/src/tools/WixToolset.HeatTasks/WixToolset.HeatTasks.csproj b/src/tools/WixToolset.HeatTasks/WixToolset.HeatTasks.csproj index ddc75c69..21fb419c 100644 --- a/src/tools/WixToolset.HeatTasks/WixToolset.HeatTasks.csproj +++ b/src/tools/WixToolset.HeatTasks/WixToolset.HeatTasks.csproj @@ -7,7 +7,6 @@ WiX Toolset Heat MSBuild Tasks embedded true - AnyCPU diff --git a/src/tools/test/WixToolsetTest.HeatTasks/MsbuildHeatFixture.cs b/src/tools/test/WixToolsetTest.HeatTasks/MsbuildHeatFixture.cs index d54da457..a0a98578 100644 --- a/src/tools/test/WixToolsetTest.HeatTasks/MsbuildHeatFixture.cs +++ b/src/tools/test/WixToolsetTest.HeatTasks/MsbuildHeatFixture.cs @@ -43,7 +43,7 @@ namespace WixToolsetTest.Sdk }); result.AssertSuccess(); - var heatCommandLines = MsbuildUtilities.GetToolCommandLines(result, "heat", "file", buildSystem, true); + var heatCommandLines = MsbuildUtilities.GetToolCommandLines(result, "heat", "file", buildSystem); Assert.Single(heatCommandLines); var warnings = result.Output.Where(line => line.Contains(": warning")).ToArray(); @@ -99,7 +99,7 @@ namespace WixToolsetTest.Sdk }); result.AssertSuccess(); - var heatCommandLines = MsbuildUtilities.GetToolCommandLines(result, "heat", "file", buildSystem, true); + var heatCommandLines = MsbuildUtilities.GetToolCommandLines(result, "heat", "file", buildSystem); Assert.Equal(2, heatCommandLines.Count()); var warnings = result.Output.Where(line => line.Contains(": warning")).ToArray(); @@ -185,7 +185,7 @@ namespace WixToolsetTest.Sdk }); result.AssertSuccess(); - var heatCommandLines = MsbuildUtilities.GetToolCommandLines(result, "heat", "project", buildSystem, true); + var heatCommandLines = MsbuildUtilities.GetToolCommandLines(result, "heat", "project", buildSystem); var heatCommandLine = Assert.Single(heatCommandLines); if (useToolsVersion && buildSystem != BuildSystem.DotNetCoreSdk) @@ -306,7 +306,7 @@ namespace WixToolsetTest.Sdk }); result.AssertSuccess(); - var heatCommandLines = MsbuildUtilities.GetToolCommandLines(result, "heat", "project", buildSystem, true); + var heatCommandLines = MsbuildUtilities.GetToolCommandLines(result, "heat", "project", buildSystem); var heatCommandLine = Assert.Single(heatCommandLines); if (useToolsVersion && buildSystem != BuildSystem.DotNetCoreSdk) diff --git a/src/wix/Directory.Build.props b/src/wix/Directory.Build.props index 2e4d6227..09507ad6 100644 --- a/src/wix/Directory.Build.props +++ b/src/wix/Directory.Build.props @@ -7,4 +7,8 @@ + + + $(OutputPath)publish\ + diff --git a/src/wix/WixToolset.BuildTasks/MsbuildMessageListener.cs b/src/wix/WixToolset.BuildTasks/MsbuildMessageListener.cs deleted file mode 100644 index f186d721..00000000 --- a/src/wix/WixToolset.BuildTasks/MsbuildMessageListener.cs +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. - -#if !NETCOREAPP -namespace WixToolset.BuildTasks -{ - using System; - using Microsoft.Build.Framework; - using Microsoft.Build.Utilities; - using WixToolset.Data; - using WixToolset.Extensibility; - using WixToolset.Extensibility.Services; - - public sealed class MsbuildMessageListener : IMessageListener - { - public MsbuildMessageListener(TaskLoggingHelper logger, string shortName, string longName) - { - this.Logger = logger; - this.ShortAppName = shortName; - this.LongAppName = longName; - } - - public string ShortAppName { get; } - - public string LongAppName { get; } - - private TaskLoggingHelper Logger { get; } - - public void Write(Message message) - { - var code = this.ShortAppName + message.Id.ToString(); - var file = message.SourceLineNumbers?.FileName ?? this.LongAppName; - var lineNumber = message.SourceLineNumbers?.LineNumber ?? 0; - switch (message.Level) - { - case MessageLevel.Error: - this.Logger.LogError(null, code, null, file, lineNumber, 0, 0, 0, message.ResourceNameOrFormat, message.MessageArgs); - break; - - case MessageLevel.Verbose: - this.Logger.LogMessage(null, code, null, file, lineNumber, 0, 0, 0, MessageImportance.Low, message.ResourceNameOrFormat, message.MessageArgs); - break; - - case MessageLevel.Warning: - this.Logger.LogWarning(null, code, null, file, lineNumber, 0, 0, 0, message.ResourceNameOrFormat, message.MessageArgs); - break; - - default: - if (message.Id > 0) - { - this.Logger.LogMessage(null, code, null, file, lineNumber, 0, 0, 0, MessageImportance.Normal, message.ResourceNameOrFormat, message.MessageArgs); - } - else - { - this.Logger.LogMessage(MessageImportance.Normal, message.ResourceNameOrFormat, message.MessageArgs); - } - break; - } - } - - public void Write(string message) - { - this.Logger.LogMessage(MessageImportance.Low, message); - } - - public MessageLevel CalculateMessageLevel(IMessaging messaging, Message message, MessageLevel defaultMessageLevel) => defaultMessageLevel; - } -} -#endif diff --git a/src/wix/WixToolset.BuildTasks/ToolsetTask.cs b/src/wix/WixToolset.BuildTasks/ToolsetTask.cs index 7d4a7687..3eee7625 100644 --- a/src/wix/WixToolset.BuildTasks/ToolsetTask.cs +++ b/src/wix/WixToolset.BuildTasks/ToolsetTask.cs @@ -7,15 +7,8 @@ namespace WixToolset.BuildTasks using System.Runtime.InteropServices; using Microsoft.Build.Utilities; - public abstract partial class ToolsetTask : ToolTask + public abstract class ToolsetTask : ToolTask { -#if NETCOREAPP - private static readonly string DotnetFullPath = Environment.GetEnvironmentVariable("DOTNET_HOST_PATH") ?? "dotnet"; - private static readonly string ThisDllPath = typeof(ToolsetTask).Assembly.Location; -#else - private static readonly string ThisDllPath = new Uri(typeof(ToolsetTask).Assembly.CodeBase).AbsolutePath; -#endif - /// /// Gets or sets additional options that are appended the the tool command-line. /// @@ -30,12 +23,6 @@ namespace WixToolset.BuildTasks /// public bool NoLogo { get; set; } - /// - /// Gets or sets a flag indicating whether the task - /// should be run as separate process or in-proc. - /// - public virtual bool RunAsSeparateProcess { get; set; } - /// /// Gets or sets whether all warnings should be suppressed. /// @@ -61,20 +48,6 @@ namespace WixToolset.BuildTasks /// public bool VerboseOutput { get; set; } - private string DefaultToolFullPath => Path.Combine(Path.GetDirectoryName(ThisDllPath), this.ToolExe); - - private string ToolFullPath - { - get - { - if (String.IsNullOrEmpty(this.ToolPath)) - { - return this.DefaultToolFullPath; - } - return Path.Combine(this.ToolPath, this.ToolExe); - } - } - /// /// Get the path to the executable. /// @@ -85,29 +58,22 @@ namespace WixToolset.BuildTasks /// protected sealed override string GenerateFullPathToTool() { + var defaultToolFullPath = this.GetDefaultToolFullPath(); + #if NETCOREAPP - if (IsSelfExecutable(this.DefaultToolFullPath, out var toolFullPath)) + // If we're pointing at an executable use that. + if (IsSelfExecutable(defaultToolFullPath, out var finalToolFullPath)) { - return toolFullPath; + return finalToolFullPath; } - return DotnetFullPath; + + // Otherwise, use "dotnet.exe" to run an assembly dll. + return Environment.GetEnvironmentVariable("DOTNET_HOST_PATH") ?? "dotnet"; #else - if (!this.RunAsSeparateProcess) - { - // We need to return a path that exists, so if we're not actually going to run the tool then just return this dll path. - return ThisDllPath; - } - return this.DefaultToolFullPath; + return defaultToolFullPath; #endif } - protected sealed override string GenerateResponseFileCommands() - { - var commandLineBuilder = new WixCommandLineBuilder(); - this.BuildCommandLine(commandLineBuilder); - return commandLineBuilder.ToString(); - } - /// /// Builds a command line from options in this and derivative tasks. /// @@ -124,33 +90,88 @@ namespace WixToolset.BuildTasks commandLineBuilder.AppendIfTrue("-wx", this.TreatWarningsAsErrors); } + protected sealed override string GenerateResponseFileCommands() + { + var commandLineBuilder = new WixCommandLineBuilder(); + this.BuildCommandLine(commandLineBuilder); + return commandLineBuilder.ToString(); + } + #if NETCOREAPP protected override string GenerateCommandLineCommands() { - if (IsSelfExecutable(this.ToolFullPath, out var toolFullPath)) + // If the target tool path is an executable, we don't need to add anything to the command-line. + var toolFullPath = this.GetToolFullPath(); + + if (IsSelfExecutable(toolFullPath, out var finalToolFullPath)) { return null; } - else + else // we're using "dotnet.exe" to run the assembly so add "exec" plus path to the command-line. { - return $"exec \"{toolFullPath}\""; + return $"exec \"{finalToolFullPath}\""; } } - private static bool IsSelfExecutable(string proposedToolFullPath, out string toolFullPath) + private static bool IsSelfExecutable(string proposedToolFullPath, out string finalToolFullPath) { var toolFullPathWithoutExtension = Path.Combine(Path.GetDirectoryName(proposedToolFullPath), Path.GetFileNameWithoutExtension(proposedToolFullPath)); var exeExtension = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : String.Empty; var exeToolFullPath = $"{toolFullPathWithoutExtension}{exeExtension}"; if (File.Exists(exeToolFullPath)) { - toolFullPath = exeToolFullPath; + finalToolFullPath = exeToolFullPath; return true; } - toolFullPath = $"{toolFullPathWithoutExtension}.dll"; + finalToolFullPath = $"{toolFullPathWithoutExtension}.dll"; return false; } +#else + private static string GetArchitectureFolder(string baseFolder) + { + // First try to find a folder that matches this task's architecture. + var folder = RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant(); + + if (Directory.Exists(Path.Combine(baseFolder, folder))) + { + return folder; + } + + // Try to fallback to "x86" folder. + if (folder != "x86" && Directory.Exists(Path.Combine(baseFolder, "x86"))) + { + return "x86"; + } + + // Return empty, even though this isn't likely to be useful. + return String.Empty; + } +#endif + + private string GetDefaultToolFullPath() + { +#if NETCOREAPP + var thisTaskFolder = Path.GetDirectoryName(typeof(ToolsetTask).Assembly.Location); + + return Path.Combine(thisTaskFolder, this.ToolExe); +#else + var thisTaskFolder = Path.GetDirectoryName(new Uri(typeof(ToolsetTask).Assembly.CodeBase).AbsolutePath); + + var archFolder = GetArchitectureFolder(thisTaskFolder); + + return Path.Combine(thisTaskFolder, archFolder, this.ToolExe); #endif + } + + private string GetToolFullPath() + { + if (String.IsNullOrEmpty(this.ToolPath)) + { + return this.GetDefaultToolFullPath(); + } + + return Path.Combine(this.ToolPath, this.ToolExe); + } } } diff --git a/src/wix/WixToolset.BuildTasks/ToolsetTask_InProc.cs b/src/wix/WixToolset.BuildTasks/ToolsetTask_InProc.cs deleted file mode 100644 index eff117da..00000000 --- a/src/wix/WixToolset.BuildTasks/ToolsetTask_InProc.cs +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. - -#if !NETCOREAPP -namespace WixToolset.BuildTasks -{ - using System; - using System.Runtime.InteropServices; - using System.Threading; - using System.Threading.Tasks; - using Microsoft.Build.Framework; - using WixToolset.Core; - using WixToolset.Data; - using WixToolset.Extensibility; - using WixToolset.Extensibility.Services; - - public partial class ToolsetTask - { - protected override int ExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands) - { - if (this.RunAsSeparateProcess) - { - return base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands); - } - - return this.ExecuteInProc($"{commandLineCommands} {responseFileCommands}"); - } - - private int ExecuteInProc(string commandLineString) - { - this.Log.LogMessage(MessageImportance.Normal, $"({this.ToolName}){commandLineString}"); - - var listener = new MsbuildMessageListener(this.Log, this.TaskShortName, this.BuildEngine.ProjectFileOfTaskNode); - var exitCode = -1; - - try - { - var coreProvider = WixToolsetServiceProviderFactory.CreateServiceProvider(); - - var messaging = coreProvider.GetService(); - messaging.SetListener(listener); - - exitCode = this.ExecuteCoreAsync(coreProvider, commandLineString, CancellationToken.None).GetAwaiter().GetResult(); - } - catch (WixException e) - { - listener.Write(e.Error); - } - catch (Exception e) - { - this.Log.LogErrorFromException(e, showStackTrace: true, showDetail: true, null); - - if (e is NullReferenceException || e is SEHException) - { - throw; - } - } - - if (exitCode == 0 && this.Log.HasLoggedErrors) - { - exitCode = -1; - } - return exitCode; - } - - protected sealed override void LogToolCommand(string message) - { - // Only log this if we're actually going to do it. - if (this.RunAsSeparateProcess) - { - base.LogToolCommand(message); - } - } - - protected abstract Task ExecuteCoreAsync(IWixToolsetCoreServiceProvider coreProvider, string commandLineString, CancellationToken cancellationToken); - - protected abstract string TaskShortName { get; } - } -} -#endif diff --git a/src/wix/WixToolset.BuildTasks/WixExeBaseTask.cs b/src/wix/WixToolset.BuildTasks/WixExeBaseTask.cs index c1904213..5583f64e 100644 --- a/src/wix/WixToolset.BuildTasks/WixExeBaseTask.cs +++ b/src/wix/WixToolset.BuildTasks/WixExeBaseTask.cs @@ -5,7 +5,7 @@ namespace WixToolset.BuildTasks /// /// An MSBuild task to run WiX to update cabinet signatures in a MSI. /// - public abstract partial class WixExeBaseTask : ToolsetTask + public abstract class WixExeBaseTask : ToolsetTask { protected override string ToolName => "wix.exe"; } diff --git a/src/wix/WixToolset.BuildTasks/WixExeBaseTask_Inproc.cs b/src/wix/WixToolset.BuildTasks/WixExeBaseTask_Inproc.cs deleted file mode 100644 index cda5f57f..00000000 --- a/src/wix/WixToolset.BuildTasks/WixExeBaseTask_Inproc.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. - -#if !NETCOREAPP -namespace WixToolset.BuildTasks -{ - using System; - using System.Threading; - using System.Threading.Tasks; - using WixToolset.Core.Burn; - using WixToolset.Core.WindowsInstaller; - using WixToolset.Extensibility.Services; - - public abstract partial class WixExeBaseTask - { - protected override string TaskShortName => "WIX"; - - protected override Task ExecuteCoreAsync(IWixToolsetCoreServiceProvider coreProvider, string commandLineString, CancellationToken cancellationToken) - { - coreProvider.AddWindowsInstallerBackend() - .AddBundleBackend(); - - var commandLine = coreProvider.GetService(); - var command = commandLine.CreateCommand(commandLineString); - return command?.ExecuteAsync(cancellationToken) ?? Task.FromResult(1); - } - } -} -#endif diff --git a/src/wix/WixToolset.BuildTasks/WixToolset.BuildTasks.csproj b/src/wix/WixToolset.BuildTasks/WixToolset.BuildTasks.csproj index 1fce528e..92651ed2 100644 --- a/src/wix/WixToolset.BuildTasks/WixToolset.BuildTasks.csproj +++ b/src/wix/WixToolset.BuildTasks/WixToolset.BuildTasks.csproj @@ -8,8 +8,6 @@ WiX Toolset MSBuild Tasks embedded true - win-x86;win-x64 - AnyCPU @@ -17,13 +15,4 @@ - - - - - - - - - diff --git a/src/wix/WixToolset.Sdk/WixToolset.Sdk.csproj b/src/wix/WixToolset.Sdk/WixToolset.Sdk.csproj index 550ba9da..8c2d866c 100644 --- a/src/wix/WixToolset.Sdk/WixToolset.Sdk.csproj +++ b/src/wix/WixToolset.Sdk/WixToolset.Sdk.csproj @@ -5,7 +5,7 @@ net6.0 WiX Toolset MSBuild integration - $(OutputPath)publish\WixToolset.Sdk\ + $(PublishRoot)WixToolset.Sdk\ $(MSBuildThisFileName).nuspec $(PublishDir) diff --git a/src/wix/WixToolset.Sdk/tools/WixToolset.Signing.targets b/src/wix/WixToolset.Sdk/tools/WixToolset.Signing.targets index abf25177..a575181a 100644 --- a/src/wix/WixToolset.Sdk/tools/WixToolset.Signing.targets +++ b/src/wix/WixToolset.Sdk/tools/WixToolset.Signing.targets @@ -213,7 +213,6 @@ VerboseOutput="$(InscribeVerboseOutput)" AdditionalOptions="$(InscribeAdditionalOptions)" - RunAsSeparateProcess="$(RunWixToolsOutOfProc)" ToolExe="$(WixToolExe)" ToolPath="$(WixToolDir)" /> @@ -255,7 +254,6 @@ VerboseOutput="$(InscribeVerboseOutput)" AdditionalOptions="$(InscribeAdditionalOptions)" - RunAsSeparateProcess="$(RunWixToolsOutOfProc)" ToolExe="$(WixToolExe)" ToolPath="$(WixToolDir)"> @@ -304,7 +302,6 @@ VerboseOutput="$(InscribeVerboseOutput)" AdditionalOptions="$(InscribeAdditionalOptions)" - RunAsSeparateProcess="$(RunWixToolsOutOfProc)" ToolExe="$(WixToolExe)" ToolPath="$(WixToolDir)"> diff --git a/src/wix/WixToolset.Sdk/tools/wix.targets b/src/wix/WixToolset.Sdk/tools/wix.targets index 752c7490..340fb91f 100644 --- a/src/wix/WixToolset.Sdk/tools/wix.targets +++ b/src/wix/WixToolset.Sdk/tools/wix.targets @@ -27,10 +27,8 @@ $(MSBuildThisFileDirectory)net6.0\ - $(MSBuildThisFileDirectory)net472\x86\ - $(MSBuildThisFileDirectory)net472\x64\ + $(MSBuildThisFileDirectory)net472\ $(WixBinDir)WixToolset.BuildTasks.dll - $(WixBinDir64)WixToolset.BuildTasks.dll @@ -147,39 +145,14 @@ *********************************************************************************************** --> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + - - + + + + + - - - + + diff --git a/src/wix/test/WixToolsetTest.BuildTasks/WixBuildTaskFixture.cs b/src/wix/test/WixToolsetTest.BuildTasks/WixBuildTaskFixture.cs index f158e3f2..5271c1bb 100644 --- a/src/wix/test/WixToolsetTest.BuildTasks/WixBuildTaskFixture.cs +++ b/src/wix/test/WixToolsetTest.BuildTasks/WixBuildTaskFixture.cs @@ -2,8 +2,10 @@ namespace WixToolsetTest.BuildTasks { + using System; using System.IO; using System.Linq; + using System.Runtime.InteropServices; using Microsoft.Build.Utilities; using WixBuildTools.TestSupport; using WixToolset.BuildTasks; @@ -13,16 +15,22 @@ namespace WixToolsetTest.BuildTasks public class WixBuildTaskFixture { + public static readonly string PublishedWixSdkToolsFolder = Path.Combine(Path.GetDirectoryName(new Uri(typeof(WixBuildTaskFixture).Assembly.CodeBase).AbsolutePath), "..", "..", "..", "publish", "WixToolset.Sdk", "tools"); + + // This line replicates what happens in WixBuild task when hosted in the PublishedWixSdkToolsFolder. However, WixBuild task is hosted inproc to this test assembly so the + // root folder is relative to the test assembly's folder which does not have wix.exe local. So, we have to find wix.exe relative to PublishedWixSdkToolsFolder. + public static readonly string PublishedWixExeFolder = Path.Combine(PublishedWixSdkToolsFolder, "net472", RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant()); + [Fact] public void CanBuildSimpleMsiPackage() { - var folder = TestData.Get(@"TestData\SimpleMsiPackage\MsiPackage"); + var folder = TestData.Get("TestData", "SimpleMsiPackage", "MsiPackage"); using (var fs = new DisposableFileSystem()) { var baseFolder = fs.GetFolder(); var intermediateFolder = Path.Combine(baseFolder, "obj"); - var pdbPath = Path.Combine(baseFolder, @"bin\testpackage.wixpdb"); + var pdbPath = Path.Combine(baseFolder, "bin", "testpackage.wixpdb"); var engine = new FakeBuildEngine(); var task = new WixBuild @@ -42,24 +50,25 @@ namespace WixToolsetTest.BuildTasks new TaskItem(Path.Combine(folder, "data")), }, IntermediateDirectory = new TaskItem(intermediateFolder), - OutputFile = new TaskItem(Path.Combine(baseFolder, @"bin\test.msi")), + OutputFile = new TaskItem(Path.Combine(baseFolder, "bin", "test.msi")), PdbType = "Full", PdbFile = new TaskItem(pdbPath), DefaultCompressionLevel = "nOnE", + ToolPath = PublishedWixExeFolder }; var result = task.Execute(); Assert.True(result, $"MSBuild task failed unexpectedly. Output:\r\n{engine.Output}"); - Assert.True(File.Exists(Path.Combine(baseFolder, @"bin\test.msi"))); + Assert.True(File.Exists(Path.Combine(baseFolder, "bin", "test.msi"))); Assert.True(File.Exists(pdbPath)); - Assert.True(File.Exists(Path.Combine(baseFolder, @"bin\cab1.cab"))); + Assert.True(File.Exists(Path.Combine(baseFolder, "bin", "cab1.cab"))); var intermediate = Intermediate.Load(pdbPath); var section = intermediate.Sections.Single(); var fileSymbol = section.Symbols.OfType().Single(); - WixAssert.StringEqual(Path.Combine(folder, @"data\test.txt"), fileSymbol[FileSymbolFields.Source].AsPath().Path); + WixAssert.StringEqual(Path.Combine(folder, "data", "test.txt"), fileSymbol[FileSymbolFields.Source].AsPath().Path); WixAssert.StringEqual(@"test.txt", fileSymbol[FileSymbolFields.Source].PreviousValue.AsPath().Path); } } diff --git a/src/wix/test/WixToolsetTest.BuildTasks/WixToolsetTest.BuildTasks.csproj b/src/wix/test/WixToolsetTest.BuildTasks/WixToolsetTest.BuildTasks.csproj index f8bb4438..d53dbe02 100644 --- a/src/wix/test/WixToolsetTest.BuildTasks/WixToolsetTest.BuildTasks.csproj +++ b/src/wix/test/WixToolsetTest.BuildTasks/WixToolsetTest.BuildTasks.csproj @@ -4,7 +4,6 @@ net472 - win-x64 true true @@ -18,11 +17,11 @@ - + diff --git a/src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs b/src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs index bd6f70bc..1201620b 100644 --- a/src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs +++ b/src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs @@ -20,7 +20,7 @@ namespace WixToolsetTest.Sdk [InlineData(BuildSystem.MSBuild64)] public void CanBuildSimpleBundle(BuildSystem buildSystem) { - var sourceFolder = TestData.Get(@"TestData\SimpleMsiPackage"); + var sourceFolder = TestData.Get(@"TestData", "SimpleMsiPackage"); using (var fs = new TestDataFolderFileSystem()) { @@ -430,13 +430,10 @@ namespace WixToolsetTest.Sdk } [Theory] - [InlineData(BuildSystem.DotNetCoreSdk, null)] - [InlineData(BuildSystem.DotNetCoreSdk, true)] - [InlineData(BuildSystem.MSBuild, null)] - [InlineData(BuildSystem.MSBuild, true)] - [InlineData(BuildSystem.MSBuild64, null)] - [InlineData(BuildSystem.MSBuild64, true)] - public void CanBuildSimpleMsiPackageAsWixipl(BuildSystem buildSystem, bool? outOfProc) + [InlineData(BuildSystem.DotNetCoreSdk)] + [InlineData(BuildSystem.MSBuild)] + [InlineData(BuildSystem.MSBuild64)] + public void CanBuildSimpleMsiPackageAsWixipl(BuildSystem buildSystem) { var sourceFolder = TestData.Get(@"TestData\SimpleMsiPackage\MsiPackage"); @@ -451,10 +448,10 @@ namespace WixToolsetTest.Sdk { MsbuildUtilities.GetQuotedPropertySwitch(buildSystem, "WixMSBuildProps", MsbuildFixture.WixPropsPath), "-p:OutputType=IntermediatePostLink", - }, outOfProc: outOfProc); + }); result.AssertSuccess(); - var wixBuildCommands = MsbuildUtilities.GetToolCommandLines(result, "wix", "build", buildSystem, outOfProc); + var wixBuildCommands = MsbuildUtilities.GetToolCommandLines(result, "wix", "build", buildSystem); Assert.Single(wixBuildCommands); var path = Directory.EnumerateFiles(binFolder, @"*.*", SearchOption.AllDirectories) @@ -465,13 +462,10 @@ namespace WixToolsetTest.Sdk } [Theory] - [InlineData(BuildSystem.DotNetCoreSdk, null)] - [InlineData(BuildSystem.DotNetCoreSdk, true)] - [InlineData(BuildSystem.MSBuild, null)] - [InlineData(BuildSystem.MSBuild, true)] - [InlineData(BuildSystem.MSBuild64, null)] - [InlineData(BuildSystem.MSBuild64, true)] - public void CanBuildSimpleWixlib(BuildSystem buildSystem, bool? outOfProc) + [InlineData(BuildSystem.DotNetCoreSdk)] + [InlineData(BuildSystem.MSBuild)] + [InlineData(BuildSystem.MSBuild64)] + public void CanBuildSimpleWixlib(BuildSystem buildSystem) { var sourceFolder = TestData.Get(@"TestData", "Wixlib", "SimpleWixlib"); @@ -485,10 +479,10 @@ namespace WixToolsetTest.Sdk var result = MsbuildUtilities.BuildProject(buildSystem, projectPath, new[] { MsbuildUtilities.GetQuotedPropertySwitch(buildSystem, "WixMSBuildProps", MsbuildFixture.WixPropsPath), - }, outOfProc: outOfProc); + }); result.AssertSuccess(); - var wixBuildCommands = MsbuildUtilities.GetToolCommandLines(result, "wix", "build", buildSystem, outOfProc); + var wixBuildCommands = MsbuildUtilities.GetToolCommandLines(result, "wix", "build", buildSystem); Assert.Single(wixBuildCommands); var path = Directory.EnumerateFiles(binFolder, @"*.*", SearchOption.AllDirectories) @@ -499,13 +493,10 @@ namespace WixToolsetTest.Sdk } [Theory] - [InlineData(BuildSystem.DotNetCoreSdk, null)] - [InlineData(BuildSystem.DotNetCoreSdk, true)] - [InlineData(BuildSystem.MSBuild, null)] - [InlineData(BuildSystem.MSBuild, true)] - [InlineData(BuildSystem.MSBuild64, null)] - [InlineData(BuildSystem.MSBuild64, true)] - public void CanBuildPackageIncludingSimpleWixlib(BuildSystem buildSystem, bool? outOfProc) + [InlineData(BuildSystem.DotNetCoreSdk)] + [InlineData(BuildSystem.MSBuild)] + [InlineData(BuildSystem.MSBuild64)] + public void CanBuildPackageIncludingSimpleWixlib(BuildSystem buildSystem) { var sourceFolder = TestData.Get(@"TestData", "Wixlib"); @@ -519,7 +510,7 @@ namespace WixToolsetTest.Sdk var result = MsbuildUtilities.BuildProject(buildSystem, projectPath, new[] { MsbuildUtilities.GetQuotedPropertySwitch(buildSystem, "WixMSBuildProps", MsbuildFixture.WixPropsPath), - }, outOfProc: outOfProc); + }); result.AssertSuccess(); var paths = Directory.EnumerateFiles(binFolder, @"*.*", SearchOption.AllDirectories) @@ -612,7 +603,7 @@ namespace WixToolsetTest.Sdk var result = MsbuildUtilities.BuildProject(buildSystem, projectPath, new[] { MsbuildUtilities.GetQuotedPropertySwitch(buildSystem, "WixToolDir", Path.Combine(MsbuildFixture.WixMsbuildPath, "broken", "net461")), - }, outOfProc: true); + }); Assert.Equal(1, result.ExitCode); var expectedMessage = "System.PlatformNotSupportedException: Could not find platform specific 'wixnative.exe' ---> System.IO.FileNotFoundException: Could not find internal piece of WiX Toolset from"; diff --git a/src/wix/wix.cmd b/src/wix/wix.cmd index e1bfe384..c0a1c384 100644 --- a/src/wix/wix.cmd +++ b/src/wix/wix.cmd @@ -3,14 +3,19 @@ @set _C=Debug @set _L=%~dp0..\..\build\logs + :parse_args @if /i "%1"=="release" set _C=Release +@if /i "%1"=="inc" set _INC=1 +@if /i "%1"=="clean" set _CLEAN=1 @if not "%1"=="" shift & goto parse_args @set _B=%~dp0..\..\build\wix\%_C% -@set _P_OBJ=%~dp0..\..\build\wix\obj\publish_t\%_C%\ -@set _P=%~dp0..\..\build\wix\%_C%\publish\ -@set _RCO=/S /R:1 /W:1 /NP /XO /NS /NC /NFL /NDL /NJH /NJS + +:: Clean + +@if "%_INC%"=="" call :clean +@if NOT "%_CLEAN%"=="" goto :end @echo Building wix %_C% @@ -23,29 +28,8 @@ msbuild wixnative\wixnative_t.proj -p:Configuration=%_C% -nologo -m -warnaserror msbuild wix.sln -p:Configuration=%_C% -nologo -m -warnaserror -bl:%_L%\wix_build.binlog || exit /b - -:: Pre-Publish Test -dotnet test ^ - %_B%\test\WixToolsetTest.Converters\net6.0\WixToolsetTest.Converters.dll ^ - %_B%\test\WixToolsetTest.Converters.Symbolizer\net472\WixToolsetTest.Converters.Symbolizer.dll ^ - %_B%\test\WixToolsetTest.Core\net6.0\WixToolsetTest.Core.dll ^ - %_B%\test\WixToolsetTest.Core.Native\net6.0\win-x64\WixToolsetTest.Core.Native.dll ^ - %_B%\test\WixToolsetTest.CoreIntegration\net6.0\WixToolsetTest.CoreIntegration.dll ^ - --nologo -l "trx;LogFileName=%_L%\TestResults\wix_prepublish.trx" || exit /b - - -:: Publish msbuild publish_t.proj -p:Configuration=%_C% -nologo -warnaserror -bl:%_L%\wix_publish.binlog || exit /b -robocopy %_P_OBJ%\WixToolset.Sdk\separate\net472\x86\buildtasks %_P%\WixToolset.Sdk\tools\net472\x86 %_RCO% /XF Microsoft.Build.*.dll -robocopy %_P_OBJ%\WixToolset.Sdk\separate\net472\x86\wix %_P%\WixToolset.Sdk\tools\net472\x86 %_RCO% - -robocopy %_P_OBJ%\WixToolset.Sdk\separate\net472\x64\buildtasks %_P%\WixToolset.Sdk\tools\net472\x64 %_RCO% /XF Microsoft.Build.*.dll -robocopy %_P_OBJ%\WixToolset.Sdk\separate\net472\x64\wix %_P%\WixToolset.Sdk\tools\net472\x64 %_RCO% - -robocopy %_P_OBJ%\WixToolset.Sdk\separate\net6.0\buildtasks %_P%\WixToolset.Sdk\tools\net6.0 %_RCO% /XF Microsoft.Build.*.dll -robocopy %_P_OBJ%\WixToolset.Sdk\separate\net6.0\wix %_P%\WixToolset.Sdk\tools\net6.0 %_RCO% - msbuild -t:Publish -p:Configuration=%_C% -nologo -warnaserror WixToolset.Sdk\WixToolset.Sdk.csproj -bl:%_L%\wix_sdk_publish.binlog || exit /b :: TODO - used by MsbuildFixture.ReportsInnerExceptionForUnexpectedExceptions test @@ -54,13 +38,41 @@ msbuild -t:Publish -p:Configuration=%_C% -nologo -warnaserror WixToolset.Sdk\Wix :: Test dotnet test ^ - %_B%\test\WixToolsetTest.BuildTasks\net472\win-x64\WixToolsetTest.BuildTasks.dll ^ + %_B%\test\WixToolsetTest.Converters\net6.0\WixToolsetTest.Converters.dll ^ + %_B%\test\WixToolsetTest.Converters.Symbolizer\net472\WixToolsetTest.Converters.Symbolizer.dll ^ + %_B%\test\WixToolsetTest.Core\net6.0\WixToolsetTest.Core.dll ^ + %_B%\test\WixToolsetTest.Core.Native\net6.0\win-x64\WixToolsetTest.Core.Native.dll ^ + %_B%\test\WixToolsetTest.CoreIntegration\net6.0\WixToolsetTest.CoreIntegration.dll ^ + %_B%\test\WixToolsetTest.BuildTasks\net472\WixToolsetTest.BuildTasks.dll ^ %_B%\test\WixToolsetTest.Sdk\net472\WixToolsetTest.Sdk.dll ^ - --nologo -l "trx;LogFileName=%_L%\TestResults\wix_postpublish.trx" || exit /b + --nologo -l "trx;LogFileName=%_L%\TestResults\wix.trx" || exit /b :: Pack msbuild pack_t.proj -p:Configuration=%_C% -nologo -m -warnaserror -bl:%_L%\wix_pack.binlog || exit /b +@goto :end + +:clean +@rd /s/q "..\..\build\wix" 2> nul +@del "..\..\build\artifacts\wix.*.nupkg" 2> nul +@del "..\..\build\artifacts\WixToolset.BuildTasks.*.nupkg" 2> nul +@del "..\..\build\artifacts\WixToolset.Converters.*.nupkg" 2> nul +@del "..\..\build\artifacts\WixToolset.Core.*.nupkg" 2> nul +@del "..\..\build\artifacts\WixToolset.Sdk.*.nupkg" 2> nul +@del "%_L%\TestResults\wix.trx" 2> nul +@rd /s/q "%USERPROFILE%\.nuget\packages\wix" 2> nul +@rd /s/q "%USERPROFILE%\.nuget\packages\wixtoolset.buildtasks" 2> nul +@rd /s/q "%USERPROFILE%\.nuget\packages\wixtoolset.converters" 2> nul +@rd /s/q "%USERPROFILE%\.nuget\packages\wixtoolset.converters.symbolizer" 2> nul +@rd /s/q "%USERPROFILE%\.nuget\packages\wixtoolset.core" 2> nul +@rd /s/q "%USERPROFILE%\.nuget\packages\wixtoolset.core.burn" 2> nul +@rd /s/q "%USERPROFILE%\.nuget\packages\wixtoolset.core.native" 2> nul +@rd /s/q "%USERPROFILE%\.nuget\packages\wixtoolset.core.windowsinstaller" 2> nul +@rd /s/q "%USERPROFILE%\.nuget\packages\wixtoolset.core.testpackage" 2> nul +@rd /s/q "%USERPROFILE%\.nuget\packages\wixtoolset.sdk" 2> nul +@exit /b + +:end @popd @endlocal -- cgit v1.2.3-55-g6feb