From be9b04d2272ef9a9e811d2d5486593b628a68993 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Wed, 3 Jun 2020 12:31:23 +1000 Subject: Never run in-proc on .NET Core. --- src/WixToolset.BuildTasks/HeatTask_InProc.cs | 2 + .../MsbuildMessageListener.cs | 2 + src/WixToolset.BuildTasks/ToolsetTask.cs | 49 ++++++++++++++++++++-- src/WixToolset.BuildTasks/ToolsetTask_InProc.cs | 2 + src/WixToolset.BuildTasks/WixBuild_InProc.cs | 2 + .../WixToolset.BuildTasks.csproj | 11 +++-- 6 files changed, 59 insertions(+), 9 deletions(-) (limited to 'src/WixToolset.BuildTasks') diff --git a/src/WixToolset.BuildTasks/HeatTask_InProc.cs b/src/WixToolset.BuildTasks/HeatTask_InProc.cs index 8190d9e2..eb6feafc 100644 --- a/src/WixToolset.BuildTasks/HeatTask_InProc.cs +++ b/src/WixToolset.BuildTasks/HeatTask_InProc.cs @@ -1,5 +1,6 @@ // 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 WixToolset.Extensibility; @@ -25,3 +26,4 @@ namespace WixToolset.BuildTasks } } } +#endif diff --git a/src/WixToolset.BuildTasks/MsbuildMessageListener.cs b/src/WixToolset.BuildTasks/MsbuildMessageListener.cs index 47399a41..f186d721 100644 --- a/src/WixToolset.BuildTasks/MsbuildMessageListener.cs +++ b/src/WixToolset.BuildTasks/MsbuildMessageListener.cs @@ -1,5 +1,6 @@ // 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; @@ -64,3 +65,4 @@ namespace WixToolset.BuildTasks public MessageLevel CalculateMessageLevel(IMessaging messaging, Message message, MessageLevel defaultMessageLevel) => defaultMessageLevel; } } +#endif diff --git a/src/WixToolset.BuildTasks/ToolsetTask.cs b/src/WixToolset.BuildTasks/ToolsetTask.cs index 4fd7af3f..94d007f0 100644 --- a/src/WixToolset.BuildTasks/ToolsetTask.cs +++ b/src/WixToolset.BuildTasks/ToolsetTask.cs @@ -4,10 +4,13 @@ namespace WixToolset.BuildTasks { using System; using System.IO; + using System.Runtime.InteropServices; using Microsoft.Build.Utilities; public abstract partial class ToolsetTask : ToolTask { + private static readonly string ThisDllPath = new Uri(typeof(ToolsetTask).Assembly.CodeBase).AbsolutePath; + /// /// Gets or sets additional options that are appended the the tool command-line. /// @@ -53,6 +56,8 @@ namespace WixToolset.BuildTasks /// public bool VerboseOutput { get; set; } + private string ToolFullPath => Path.Combine(Path.GetDirectoryName(ThisDllPath), this.ToolExe); + /// /// Get the path to the executable. /// @@ -63,13 +68,20 @@ namespace WixToolset.BuildTasks /// protected sealed override string GenerateFullPathToTool() { - var thisDllPath = new Uri(typeof(ToolsetTask).Assembly.CodeBase).AbsolutePath; +#if !NETCOREAPP 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 ThisDllPath; } - return Path.Combine(Path.GetDirectoryName(thisDllPath), this.ToolExe); + return this.ToolFullPath; +#else + if (IsSelfExecutable(this.ToolFullPath, out var toolFullPath)) + { + return toolFullPath; + } + return DotnetFullPath; +#endif } protected sealed override string GenerateResponseFileCommands() @@ -94,5 +106,36 @@ namespace WixToolset.BuildTasks commandLineBuilder.AppendArrayIfNotNull("-wx ", this.TreatSpecificWarningsAsErrors); commandLineBuilder.AppendIfTrue("-wx", this.TreatWarningsAsErrors); } + +#if NETCOREAPP + private static readonly string DotnetFullPath = Environment.GetEnvironmentVariable("DOTNET_HOST_PATH") ?? "dotnet"; + + protected override string GenerateCommandLineCommands() + { + if (IsSelfExecutable(this.ToolFullPath, out var toolFullPath)) + { + return null; + } + else + { + return $"exec \"{toolFullPath}\""; + } + } + + private static bool IsSelfExecutable(string proposedToolFullPath, out string toolFullPath) + { + 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; + return true; + } + + toolFullPath = $"{toolFullPathWithoutExtension}.dll"; + return false; + } +#endif } } diff --git a/src/WixToolset.BuildTasks/ToolsetTask_InProc.cs b/src/WixToolset.BuildTasks/ToolsetTask_InProc.cs index 4b365b2a..a3290e60 100644 --- a/src/WixToolset.BuildTasks/ToolsetTask_InProc.cs +++ b/src/WixToolset.BuildTasks/ToolsetTask_InProc.cs @@ -1,5 +1,6 @@ // 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; @@ -69,3 +70,4 @@ namespace WixToolset.BuildTasks protected abstract string TaskShortName { get; } } } +#endif diff --git a/src/WixToolset.BuildTasks/WixBuild_InProc.cs b/src/WixToolset.BuildTasks/WixBuild_InProc.cs index 8e9f2fec..49148c8a 100644 --- a/src/WixToolset.BuildTasks/WixBuild_InProc.cs +++ b/src/WixToolset.BuildTasks/WixBuild_InProc.cs @@ -1,5 +1,6 @@ // 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 WixToolset.Data; @@ -51,3 +52,4 @@ namespace WixToolset.BuildTasks } } } +#endif diff --git a/src/WixToolset.BuildTasks/WixToolset.BuildTasks.csproj b/src/WixToolset.BuildTasks/WixToolset.BuildTasks.csproj index 221478ed..6709949e 100644 --- a/src/WixToolset.BuildTasks/WixToolset.BuildTasks.csproj +++ b/src/WixToolset.BuildTasks/WixToolset.BuildTasks.csproj @@ -18,19 +18,18 @@ - + - + + - - - - + + -- cgit v1.2.3-55-g6feb