diff options
Diffstat (limited to 'src/WixToolset.BuildTasks/ToolsetTask.cs')
| -rw-r--r-- | src/WixToolset.BuildTasks/ToolsetTask.cs | 49 |
1 files changed, 46 insertions, 3 deletions
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 | |||
| 4 | { | 4 | { |
| 5 | using System; | 5 | using System; |
| 6 | using System.IO; | 6 | using System.IO; |
| 7 | using System.Runtime.InteropServices; | ||
| 7 | using Microsoft.Build.Utilities; | 8 | using Microsoft.Build.Utilities; |
| 8 | 9 | ||
| 9 | public abstract partial class ToolsetTask : ToolTask | 10 | public abstract partial class ToolsetTask : ToolTask |
| 10 | { | 11 | { |
| 12 | private static readonly string ThisDllPath = new Uri(typeof(ToolsetTask).Assembly.CodeBase).AbsolutePath; | ||
| 13 | |||
| 11 | /// <summary> | 14 | /// <summary> |
| 12 | /// Gets or sets additional options that are appended the the tool command-line. | 15 | /// Gets or sets additional options that are appended the the tool command-line. |
| 13 | /// </summary> | 16 | /// </summary> |
| @@ -53,6 +56,8 @@ namespace WixToolset.BuildTasks | |||
| 53 | /// </summary> | 56 | /// </summary> |
| 54 | public bool VerboseOutput { get; set; } | 57 | public bool VerboseOutput { get; set; } |
| 55 | 58 | ||
| 59 | private string ToolFullPath => Path.Combine(Path.GetDirectoryName(ThisDllPath), this.ToolExe); | ||
| 60 | |||
| 56 | /// <summary> | 61 | /// <summary> |
| 57 | /// Get the path to the executable. | 62 | /// Get the path to the executable. |
| 58 | /// </summary> | 63 | /// </summary> |
| @@ -63,13 +68,20 @@ namespace WixToolset.BuildTasks | |||
| 63 | /// </remarks> | 68 | /// </remarks> |
| 64 | protected sealed override string GenerateFullPathToTool() | 69 | protected sealed override string GenerateFullPathToTool() |
| 65 | { | 70 | { |
| 66 | var thisDllPath = new Uri(typeof(ToolsetTask).Assembly.CodeBase).AbsolutePath; | 71 | #if !NETCOREAPP |
| 67 | if (!this.RunAsSeparateProcess) | 72 | if (!this.RunAsSeparateProcess) |
| 68 | { | 73 | { |
| 69 | // 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. | 74 | // 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. |
| 70 | return thisDllPath; | 75 | return ThisDllPath; |
| 71 | } | 76 | } |
| 72 | return Path.Combine(Path.GetDirectoryName(thisDllPath), this.ToolExe); | 77 | return this.ToolFullPath; |
| 78 | #else | ||
| 79 | if (IsSelfExecutable(this.ToolFullPath, out var toolFullPath)) | ||
| 80 | { | ||
| 81 | return toolFullPath; | ||
| 82 | } | ||
| 83 | return DotnetFullPath; | ||
| 84 | #endif | ||
| 73 | } | 85 | } |
| 74 | 86 | ||
| 75 | protected sealed override string GenerateResponseFileCommands() | 87 | protected sealed override string GenerateResponseFileCommands() |
| @@ -94,5 +106,36 @@ namespace WixToolset.BuildTasks | |||
| 94 | commandLineBuilder.AppendArrayIfNotNull("-wx ", this.TreatSpecificWarningsAsErrors); | 106 | commandLineBuilder.AppendArrayIfNotNull("-wx ", this.TreatSpecificWarningsAsErrors); |
| 95 | commandLineBuilder.AppendIfTrue("-wx", this.TreatWarningsAsErrors); | 107 | commandLineBuilder.AppendIfTrue("-wx", this.TreatWarningsAsErrors); |
| 96 | } | 108 | } |
| 109 | |||
| 110 | #if NETCOREAPP | ||
| 111 | private static readonly string DotnetFullPath = Environment.GetEnvironmentVariable("DOTNET_HOST_PATH") ?? "dotnet"; | ||
| 112 | |||
| 113 | protected override string GenerateCommandLineCommands() | ||
| 114 | { | ||
| 115 | if (IsSelfExecutable(this.ToolFullPath, out var toolFullPath)) | ||
| 116 | { | ||
| 117 | return null; | ||
| 118 | } | ||
| 119 | else | ||
| 120 | { | ||
| 121 | return $"exec \"{toolFullPath}\""; | ||
| 122 | } | ||
| 123 | } | ||
| 124 | |||
| 125 | private static bool IsSelfExecutable(string proposedToolFullPath, out string toolFullPath) | ||
| 126 | { | ||
| 127 | var toolFullPathWithoutExtension = Path.Combine(Path.GetDirectoryName(proposedToolFullPath), Path.GetFileNameWithoutExtension(proposedToolFullPath)); | ||
| 128 | var exeExtension = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : String.Empty; | ||
| 129 | var exeToolFullPath = $"{toolFullPathWithoutExtension}{exeExtension}"; | ||
| 130 | if (File.Exists(exeToolFullPath)) | ||
| 131 | { | ||
| 132 | toolFullPath = exeToolFullPath; | ||
| 133 | return true; | ||
| 134 | } | ||
| 135 | |||
| 136 | toolFullPath = $"{toolFullPathWithoutExtension}.dll"; | ||
| 137 | return false; | ||
| 138 | } | ||
| 139 | #endif | ||
| 97 | } | 140 | } |
| 98 | } | 141 | } |
