diff options
Diffstat (limited to 'src')
13 files changed, 499 insertions, 16 deletions
diff --git a/src/internal/WixInternal.MSTestSupport/MsbuildUtilities.cs b/src/internal/WixInternal.MSTestSupport/MsbuildUtilities.cs index 8f3fecd9..516143dd 100644 --- a/src/internal/WixInternal.MSTestSupport/MsbuildUtilities.cs +++ b/src/internal/WixInternal.MSTestSupport/MsbuildUtilities.cs | |||
| @@ -30,7 +30,8 @@ namespace WixInternal.MSTestSupport | |||
| 30 | 30 | ||
| 31 | if (binlog) | 31 | if (binlog) |
| 32 | { | 32 | { |
| 33 | MsbuildUtilities.GetQuotedSwitch(buildSystem, "bl", Path.ChangeExtension(projectPath, ".binlog")); | 33 | var binlogSwitch = MsbuildUtilities.GetQuotedSwitch(buildSystem, "bl", Path.ChangeExtension(projectPath, ".binlog")); |
| 34 | allArgs.Add(binlogSwitch); | ||
| 34 | } | 35 | } |
| 35 | 36 | ||
| 36 | if (arguments != null) | 37 | if (arguments != null) |
diff --git a/src/test/wix/TestData/CsprojWpfNetCore/CsprojWpfNetCore.csproj b/src/test/wix/TestData/CsprojWpfNetCore/CsprojWpfNetCore.csproj index e7061e74..b1bf8781 100644 --- a/src/test/wix/TestData/CsprojWpfNetCore/CsprojWpfNetCore.csproj +++ b/src/test/wix/TestData/CsprojWpfNetCore/CsprojWpfNetCore.csproj | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | <PropertyGroup> | 3 | <PropertyGroup> |
| 4 | <OutputType>WinExe</OutputType> | 4 | <OutputType>WinExe</OutputType> |
| 5 | <TargetFramework>net5.0-windows7.0</TargetFramework> | 5 | <TargetFramework>net8.0-windows7.0</TargetFramework> |
| 6 | <Nullable>enable</Nullable> | 6 | <Nullable>enable</Nullable> |
| 7 | <UseWPF>true</UseWPF> | 7 | <UseWPF>true</UseWPF> |
| 8 | </PropertyGroup> | 8 | </PropertyGroup> |
diff --git a/src/test/wix/TestData/WixprojPackageCsprojWpfNetCore/Package.wxs b/src/test/wix/TestData/WixprojPackageCsprojWpfNetCore/Package.wxs index 8bd191d8..3671c0ca 100644 --- a/src/test/wix/TestData/WixprojPackageCsprojWpfNetCore/Package.wxs +++ b/src/test/wix/TestData/WixprojPackageCsprojWpfNetCore/Package.wxs | |||
| @@ -7,9 +7,9 @@ | |||
| 7 | </StandardDirectory> | 7 | </StandardDirectory> |
| 8 | 8 | ||
| 9 | <Feature Id='Main' Title='WpfApp'> | 9 | <Feature Id='Main' Title='WpfApp'> |
| 10 | <Component Directory='ApplicationFolder'> | 10 | <Files Directory='ApplicationFolder' Include='!(bindpath.CsprojWpfNetCore)\**'> |
| 11 | <File Source='CsprojWpfNetCore.exe' /> | 11 | <Exclude Files="**\*.pdb" /> |
| 12 | </Component> | 12 | </Files> |
| 13 | </Feature> | 13 | </Feature> |
| 14 | </Package> | 14 | </Package> |
| 15 | </Wix> | 15 | </Wix> |
diff --git a/src/test/wix/TestData/WixprojPackageCsprojWpfNetCore/WixprojPackageCsprojWebApplicationNetCore.wixproj b/src/test/wix/TestData/WixprojPackageCsprojWpfNetCore/WixprojPackageCsprojWpfNetCore.wixproj index 686092b6..df333242 100644 --- a/src/test/wix/TestData/WixprojPackageCsprojWpfNetCore/WixprojPackageCsprojWebApplicationNetCore.wixproj +++ b/src/test/wix/TestData/WixprojPackageCsprojWpfNetCore/WixprojPackageCsprojWpfNetCore.wixproj | |||
| @@ -1,17 +1,13 @@ | |||
| 1 | <!-- 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. --> | 1 | <!-- 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. --> |
| 2 | <Project Sdk='WixToolset.Sdk'> | 2 | <Project Sdk='WixToolset.Sdk'> |
| 3 | <!-- <Project> --> | ||
| 4 | <!-- <Import Sdk="WixToolset.Sdk" Project='D:\src\wix4\build\wix\Debug\net8.0\Sdk\Sdk.props' /> --> | ||
| 5 | 3 | ||
| 6 | <PropertyGroup> | 4 | <ItemGroup> |
| 7 | <!-- <WixBinDir>D:\src\wix4\build\wix\Debug\net472\</WixBinDir> --> | 5 | <Compile Remove="abc\Bad.wxs" /> |
| 8 | <!-- <WixBinDir64>D:\src\wix4\build\wix\Debug\publish\WixToolset.Sdk\tools\net472\x64\</WixBinDir64> --> | 6 | </ItemGroup> |
| 9 | </PropertyGroup> | ||
| 10 | 7 | ||
| 11 | <ItemGroup> | 8 | <ItemGroup> |
| 12 | <!-- SkipPublish="true" BindPath="$(MSBuildProjectDirectory)\does\not\exist" BindName="Xxx" Publish="true" --> | 9 | <!-- SkipPublish="true" BindPath="$(MSBuildProjectDirectory)\does\not\exist" BindName="Xxx" Publish="true" --> |
| 13 | <ProjectReference Include="..\CsprojWpfNetCore\CsprojWpfNetCore.csproj" Publish="true" /> | 10 | <ProjectReference Include="..\CsprojWpfNetCore\CsprojWpfNetCore.csproj" Publish="true" /> |
| 14 | </ItemGroup> | 11 | </ItemGroup> |
| 15 | 12 | ||
| 16 | <!-- <Import Sdk="WixToolset.Sdk" Project='D:\src\wix4\build\wix\Debug\net8.0\Sdk\Sdk.targets' /> --> | ||
| 17 | </Project> | 13 | </Project> |
diff --git a/src/wix/WixToolset.BuildTasks/ILogger.cs b/src/wix/WixToolset.BuildTasks/ILogger.cs new file mode 100644 index 00000000..16db691e --- /dev/null +++ b/src/wix/WixToolset.BuildTasks/ILogger.cs | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | // 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. | ||
| 2 | |||
| 3 | namespace WixToolset.BuildTasks | ||
| 4 | { | ||
| 5 | public interface ILogger | ||
| 6 | { | ||
| 7 | bool HasLoggedErrors { get; } | ||
| 8 | |||
| 9 | void LogError(string message); | ||
| 10 | |||
| 11 | void LogWarning(string message); | ||
| 12 | } | ||
| 13 | } | ||
diff --git a/src/wix/WixToolset.BuildTasks/MSBuildLoggerAdapter.cs b/src/wix/WixToolset.BuildTasks/MSBuildLoggerAdapter.cs new file mode 100644 index 00000000..5382254c --- /dev/null +++ b/src/wix/WixToolset.BuildTasks/MSBuildLoggerAdapter.cs | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | // 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. | ||
| 2 | |||
| 3 | namespace WixToolset.BuildTasks | ||
| 4 | { | ||
| 5 | using Microsoft.Build.Utilities; | ||
| 6 | |||
| 7 | internal class MSBuildLoggerAdapter : ILogger | ||
| 8 | { | ||
| 9 | private readonly TaskLoggingHelper log; | ||
| 10 | |||
| 11 | public MSBuildLoggerAdapter(TaskLoggingHelper log) | ||
| 12 | { | ||
| 13 | this.log = log; | ||
| 14 | } | ||
| 15 | |||
| 16 | public bool HasLoggedErrors => this.log.HasLoggedErrors; | ||
| 17 | |||
| 18 | public void LogError(string message) | ||
| 19 | { | ||
| 20 | this.log.LogError(message); | ||
| 21 | } | ||
| 22 | |||
| 23 | public void LogWarning(string message) | ||
| 24 | { | ||
| 25 | this.log.LogWarning(message); | ||
| 26 | } | ||
| 27 | } | ||
| 28 | } | ||
diff --git a/src/wix/WixToolset.BuildTasks/ResolveInstallerPlatform.cs b/src/wix/WixToolset.BuildTasks/ResolveInstallerPlatform.cs new file mode 100644 index 00000000..5e551d7b --- /dev/null +++ b/src/wix/WixToolset.BuildTasks/ResolveInstallerPlatform.cs | |||
| @@ -0,0 +1,174 @@ | |||
| 1 | // 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. | ||
| 2 | |||
| 3 | namespace WixToolset.BuildTasks | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.Linq; | ||
| 7 | using Microsoft.Build.Framework; | ||
| 8 | using Microsoft.Build.Utilities; | ||
| 9 | |||
| 10 | /// <summary> | ||
| 11 | /// This task calculates the InstallerPlatform from the RuntimeIdentifier, | ||
| 12 | /// InitialInstallerPlatform and Platform properties. | ||
| 13 | /// </summary> | ||
| 14 | public class ResolveInstallerPlatform : Task | ||
| 15 | { | ||
| 16 | private readonly ILogger logger; | ||
| 17 | |||
| 18 | /// <summary> | ||
| 19 | /// Default constructor. | ||
| 20 | /// </summary> | ||
| 21 | public ResolveInstallerPlatform() | ||
| 22 | { | ||
| 23 | this.logger = new MSBuildLoggerAdapter(this.Log); | ||
| 24 | } | ||
| 25 | |||
| 26 | /// <summary> | ||
| 27 | /// Constructor for dependency injection of logger used by unit tests. | ||
| 28 | /// </summary> | ||
| 29 | public ResolveInstallerPlatform(ILogger logger) | ||
| 30 | { | ||
| 31 | this.logger = logger; | ||
| 32 | } | ||
| 33 | |||
| 34 | /// <summary> | ||
| 35 | /// The optional RuntimeIdentifier property. | ||
| 36 | /// </summary> | ||
| 37 | public string RuntimeIdentifier { private get; set; } | ||
| 38 | |||
| 39 | /// <summary> | ||
| 40 | /// The optional InitialInstallerPlatform property. | ||
| 41 | /// </summary> | ||
| 42 | public string InitialInstallerPlatform { private get; set; } | ||
| 43 | |||
| 44 | /// <summary> | ||
| 45 | /// The InstallerPlatform property. | ||
| 46 | /// </summary> | ||
| 47 | public string InstallerPlatform { private get; set; } | ||
| 48 | |||
| 49 | /// <summary> | ||
| 50 | /// The optional Platform property. | ||
| 51 | /// </summary> | ||
| 52 | public string Platform { private get; set; } | ||
| 53 | |||
| 54 | /// <summary> | ||
| 55 | /// The resolved InstallerPlatform. | ||
| 56 | /// </summary> | ||
| 57 | [Output] | ||
| 58 | public string ResolvedInstallerPlatform { get; private set; } | ||
| 59 | |||
| 60 | /// <summary> | ||
| 61 | /// The optionally resolved Platform. | ||
| 62 | /// </summary> | ||
| 63 | [Output] | ||
| 64 | public string ResolvedPlatform { get; private set; } | ||
| 65 | |||
| 66 | /// <summary> | ||
| 67 | /// Convert the input properties into output items. | ||
| 68 | /// </summary> | ||
| 69 | /// <returns>True upon completion of the task execution.</returns> | ||
| 70 | public override bool Execute() | ||
| 71 | { | ||
| 72 | if (String.IsNullOrEmpty(this.RuntimeIdentifier)) | ||
| 73 | { | ||
| 74 | this.ResolvedInstallerPlatform = this.InstallerPlatform; | ||
| 75 | } | ||
| 76 | else if (this.ValidateWindowsRuntimeIdentifier(this.RuntimeIdentifier, out var platform)) | ||
| 77 | { | ||
| 78 | if (!String.IsNullOrEmpty(this.InitialInstallerPlatform) && !String.Equals(this.InitialInstallerPlatform, platform, StringComparison.OrdinalIgnoreCase)) | ||
| 79 | { | ||
| 80 | this.logger.LogError($"The RuntimeIdentifier '{this.RuntimeIdentifier}' resolves to platform '{platform}', which conflicts with the provided InstallerPlatform '{this.InitialInstallerPlatform}'."); | ||
| 81 | } | ||
| 82 | else | ||
| 83 | { | ||
| 84 | this.ResolvedInstallerPlatform = platform; | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | // If Platform was a generic value, resolve it to the resolved installer platform. | ||
| 89 | if (String.IsNullOrEmpty(this.Platform) | ||
| 90 | || this.Platform.Equals("AnyCPU", StringComparison.OrdinalIgnoreCase) | ||
| 91 | || this.Platform.Equals("Any CPU", StringComparison.OrdinalIgnoreCase) | ||
| 92 | || this.Platform.Equals("Win32", StringComparison.OrdinalIgnoreCase)) | ||
| 93 | { | ||
| 94 | this.ResolvedPlatform = this.ResolvedInstallerPlatform; | ||
| 95 | } | ||
| 96 | else if (!this.Platform.Equals(this.ResolvedInstallerPlatform, StringComparison.OrdinalIgnoreCase)) | ||
| 97 | { | ||
| 98 | this.logger.LogWarning($"The provided Platform '{this.Platform}' does not match the resolved InstallerPlatform '{this.ResolvedInstallerPlatform}'. The output will be built using '{this.ResolvedInstallerPlatform}'."); | ||
| 99 | } | ||
| 100 | |||
| 101 | return !this.logger.HasLoggedErrors; | ||
| 102 | } | ||
| 103 | |||
| 104 | private bool ValidateWindowsRuntimeIdentifier(string runtimeIdentifier, out string platform) | ||
| 105 | { | ||
| 106 | platform = null; | ||
| 107 | |||
| 108 | var ridParts = runtimeIdentifier.Split('-'); | ||
| 109 | if (ridParts.Length < 2) | ||
| 110 | { | ||
| 111 | this.logger.LogError($"The RuntimeIdentifier '{runtimeIdentifier}' is not valid."); | ||
| 112 | |||
| 113 | return false; | ||
| 114 | } | ||
| 115 | |||
| 116 | var os = ridParts[0]; | ||
| 117 | |||
| 118 | if (!os.StartsWith("win", StringComparison.OrdinalIgnoreCase) || (os.Length > 3 && !Int32.TryParse(os.Substring(3), out var _))) | ||
| 119 | { | ||
| 120 | this.logger.LogError($"The RuntimeIdentifier '{runtimeIdentifier}' is not a valid Windows RuntimeIdentifier."); | ||
| 121 | |||
| 122 | return false; | ||
| 123 | } | ||
| 124 | |||
| 125 | // Ensure there is only one platform specified in the RID. | ||
| 126 | foreach (var part in ridParts.Skip(1)) | ||
| 127 | { | ||
| 128 | string platformPart; | ||
| 129 | switch (part.ToLowerInvariant()) | ||
| 130 | { | ||
| 131 | case "x86": | ||
| 132 | case "win32": | ||
| 133 | platformPart = "x86"; | ||
| 134 | break; | ||
| 135 | |||
| 136 | case "x64": | ||
| 137 | case "amd64": | ||
| 138 | platformPart = "x64"; | ||
| 139 | break; | ||
| 140 | |||
| 141 | case "arm": | ||
| 142 | case "arm32": | ||
| 143 | platformPart = "arm"; | ||
| 144 | break; | ||
| 145 | |||
| 146 | case "arm64": | ||
| 147 | platformPart = "arm64"; | ||
| 148 | break; | ||
| 149 | |||
| 150 | default: | ||
| 151 | continue; | ||
| 152 | } | ||
| 153 | |||
| 154 | if (String.IsNullOrEmpty(platform)) | ||
| 155 | { | ||
| 156 | platform = platformPart; | ||
| 157 | } | ||
| 158 | else // there can be only one platform in the RID. | ||
| 159 | { | ||
| 160 | this.logger.LogError($"The RuntimeIdentifier '{runtimeIdentifier}' specifies multiple platforms which is not supported."); | ||
| 161 | } | ||
| 162 | } | ||
| 163 | |||
| 164 | if (String.IsNullOrEmpty(platform)) | ||
| 165 | { | ||
| 166 | this.logger.LogError($"The RuntimeIdentifier '{runtimeIdentifier}' does not specify a valid platform."); | ||
| 167 | |||
| 168 | return false; | ||
| 169 | } | ||
| 170 | |||
| 171 | return true; | ||
| 172 | } | ||
| 173 | } | ||
| 174 | } | ||
diff --git a/src/wix/WixToolset.Sdk/tools/wix.targets b/src/wix/WixToolset.Sdk/tools/wix.targets index ddc83052..bf0fdaca 100644 --- a/src/wix/WixToolset.Sdk/tools/wix.targets +++ b/src/wix/WixToolset.Sdk/tools/wix.targets | |||
| @@ -40,6 +40,7 @@ | |||
| 40 | <UsingTask TaskName="CreateProjectReferenceDefineConstantsAndBindPaths" AssemblyFile="$(WixTasksPath)" /> | 40 | <UsingTask TaskName="CreateProjectReferenceDefineConstantsAndBindPaths" AssemblyFile="$(WixTasksPath)" /> |
| 41 | <UsingTask TaskName="WixAssignCulture" AssemblyFile="$(WixTasksPath)" /> | 41 | <UsingTask TaskName="WixAssignCulture" AssemblyFile="$(WixTasksPath)" /> |
| 42 | <UsingTask TaskName="ReadTracking" AssemblyFile="$(WixTasksPath)" /> | 42 | <UsingTask TaskName="ReadTracking" AssemblyFile="$(WixTasksPath)" /> |
| 43 | <UsingTask TaskName="ResolveInstallerPlatform" AssemblyFile="$(WixTasksPath)" /> | ||
| 43 | <UsingTask TaskName="ResolveWixReferences" AssemblyFile="$(WixTasksPath)" /> | 44 | <UsingTask TaskName="ResolveWixReferences" AssemblyFile="$(WixTasksPath)" /> |
| 44 | <UsingTask TaskName="WixBuild" AssemblyFile="$(WixTasksPath)" /> | 45 | <UsingTask TaskName="WixBuild" AssemblyFile="$(WixTasksPath)" /> |
| 45 | <UsingTask TaskName="WindowsInstallerValidation" AssemblyFile="$(WixTasksPath)" /> | 46 | <UsingTask TaskName="WindowsInstallerValidation" AssemblyFile="$(WixTasksPath)" /> |
| @@ -165,6 +166,7 @@ | |||
| 165 | 166 | ||
| 166 | <!-- Default Compiler properties. --> | 167 | <!-- Default Compiler properties. --> |
| 167 | <PropertyGroup> | 168 | <PropertyGroup> |
| 169 | <_InitialInstallerPlatform>$(InstallerPlatform)</_InitialInstallerPlatform> | ||
| 168 | <InstallerPlatform Condition=" '$(InstallerPlatform)' == '' and ('$(Platform)' == '' or '$(Platform)' == 'Win32' or '$(Platform)' == 'AnyCPU' or '$(Platform)' == 'Any CPU') ">x86</InstallerPlatform> | 170 | <InstallerPlatform Condition=" '$(InstallerPlatform)' == '' and ('$(Platform)' == '' or '$(Platform)' == 'Win32' or '$(Platform)' == 'AnyCPU' or '$(Platform)' == 'Any CPU') ">x86</InstallerPlatform> |
| 169 | <InstallerPlatform Condition=" '$(InstallerPlatform)' == '' ">$(Platform)</InstallerPlatform> | 171 | <InstallerPlatform Condition=" '$(InstallerPlatform)' == '' ">$(Platform)</InstallerPlatform> |
| 170 | </PropertyGroup> | 172 | </PropertyGroup> |
| @@ -207,6 +209,60 @@ | |||
| 207 | <!-- | 209 | <!-- |
| 208 | *********************************************************************************************** | 210 | *********************************************************************************************** |
| 209 | *********************************************************************************************** | 211 | *********************************************************************************************** |
| 212 | Prepare For Build Section | ||
| 213 | *********************************************************************************************** | ||
| 214 | *********************************************************************************************** | ||
| 215 | --> | ||
| 216 | <PropertyGroup> | ||
| 217 | <PrepareForBuildDependsOn> | ||
| 218 | ResolveInstallerPlatform; | ||
| 219 | $(PrepareForBuildDependsOn) | ||
| 220 | </PrepareForBuildDependsOn> | ||
| 221 | </PropertyGroup> | ||
| 222 | |||
| 223 | <!-- | ||
| 224 | ================================================================================================ | ||
| 225 | ResolveInstallerPlatform | ||
| 226 | |||
| 227 | Uses the RuntimeIdentifier to validate and update the InstallerPlatform. If the RuntimeIdentifier is | ||
| 228 | not provided, the InstallerPlatform will continue to mirror the Platform. | ||
| 229 | |||
| 230 | [IN] | ||
| 231 | $(_InitialInstallerPlatform) - Set if InstallerPlatform was explcitly defined in project. | ||
| 232 | $(InstallerPlatform) - InstallerPlatform calculated from initial value of Platform. | ||
| 233 | $(RuntimeIdentfier) - Optional runtime identifier for output. | ||
| 234 | $(Platform) - Optional platform for output. | ||
| 235 | |||
| 236 | [OUT] | ||
| 237 | $(InstallerPlatform) - InstallerPlatform resolved based on the inputs. | ||
| 238 | $(PlatformName) - Potentially updates Platform name if Platform is generic and the RuntimeIdentifier | ||
| 239 | changes the InstallerPlatform. | ||
| 240 | ================================================================================================ | ||
| 241 | --> | ||
| 242 | <Target | ||
| 243 | Name="ResolveInstallerPlatform" | ||
| 244 | Returns="$(InstallerPlatform)"> | ||
| 245 | |||
| 246 | <ResolveInstallerPlatform | ||
| 247 | RuntimeIdentifier="$(RuntimeIdentifier)" | ||
| 248 | InitialInstallerPlatform="$(_InitialInstallerPlatform)" | ||
| 249 | InstallerPlatform="$(InstallerPlatform)" | ||
| 250 | Platform="$(Platform)"> | ||
| 251 | <Output TaskParameter="ResolvedInstallerPlatform" | ||
| 252 | PropertyName="_ResolvedInstallerPlatform" /> | ||
| 253 | <Output TaskParameter="ResolvedPlatform" | ||
| 254 | PropertyName="_ResolvedPlatform" /> | ||
| 255 | </ResolveInstallerPlatform> | ||
| 256 | |||
| 257 | <PropertyGroup> | ||
| 258 | <InstallerPlatform>$(_ResolvedInstallerPlatform)</InstallerPlatform> | ||
| 259 | <PlatformName Condition=" '$(_ResolvedPlatform)' != '' and '$(PlatformName)' == '$(Platform)' ">$(_ResolvedPlatform)</PlatformName> | ||
| 260 | </PropertyGroup> | ||
| 261 | </Target> | ||
| 262 | |||
| 263 | <!-- | ||
| 264 | *********************************************************************************************** | ||
| 265 | *********************************************************************************************** | ||
| 210 | Resolve References Section | 266 | Resolve References Section |
| 211 | *********************************************************************************************** | 267 | *********************************************************************************************** |
| 212 | *********************************************************************************************** | 268 | *********************************************************************************************** |
diff --git a/src/wix/test/WixToolsetTest.BuildTasks/FakeMsbuildLogger.cs b/src/wix/test/WixToolsetTest.BuildTasks/FakeMsbuildLogger.cs new file mode 100644 index 00000000..8bfb6145 --- /dev/null +++ b/src/wix/test/WixToolsetTest.BuildTasks/FakeMsbuildLogger.cs | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | // 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. | ||
| 2 | |||
| 3 | namespace WixToolsetTest.BuildTasks | ||
| 4 | { | ||
| 5 | using System.Collections.Generic; | ||
| 6 | using WixToolset.BuildTasks; | ||
| 7 | |||
| 8 | public class FakeMsbuildLogger : ILogger | ||
| 9 | { | ||
| 10 | public List<string> Messages { get; } = new List<string>(); | ||
| 11 | |||
| 12 | public bool HasLoggedErrors { get; private set; } | ||
| 13 | |||
| 14 | public void LogError(string message) | ||
| 15 | { | ||
| 16 | this.HasLoggedErrors = true; | ||
| 17 | |||
| 18 | this.Messages.Add("Error: " + message); | ||
| 19 | } | ||
| 20 | |||
| 21 | public void LogWarning(string message) | ||
| 22 | { | ||
| 23 | this.Messages.Add("Warning: " + message); | ||
| 24 | } | ||
| 25 | } | ||
| 26 | } | ||
diff --git a/src/wix/test/WixToolsetTest.BuildTasks/ResolveInstallerPlatformTaskFixture.cs b/src/wix/test/WixToolsetTest.BuildTasks/ResolveInstallerPlatformTaskFixture.cs new file mode 100644 index 00000000..0da2e146 --- /dev/null +++ b/src/wix/test/WixToolsetTest.BuildTasks/ResolveInstallerPlatformTaskFixture.cs | |||
| @@ -0,0 +1,148 @@ | |||
| 1 | // 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. | ||
| 2 | |||
| 3 | namespace WixToolsetTest.BuildTasks | ||
| 4 | { | ||
| 5 | using WixInternal.TestSupport; | ||
| 6 | using WixToolset.BuildTasks; | ||
| 7 | using Xunit; | ||
| 8 | |||
| 9 | public class ResolveInstallerPlatformTaskFixture | ||
| 10 | { | ||
| 11 | |||
| 12 | [Fact] | ||
| 13 | public void Execute_WithOnlyInstallerPlatform_ResolvesCorrectly() | ||
| 14 | { | ||
| 15 | var logger = new FakeMsbuildLogger(); | ||
| 16 | |||
| 17 | var task = new ResolveInstallerPlatform(logger) | ||
| 18 | { | ||
| 19 | InstallerPlatform = "x64", | ||
| 20 | Platform = "", | ||
| 21 | }; | ||
| 22 | |||
| 23 | Assert.True(task.Execute()); | ||
| 24 | |||
| 25 | Assert.Empty(logger.Messages); | ||
| 26 | Assert.Equal("x64", task.ResolvedInstallerPlatform); | ||
| 27 | Assert.Equal("x64", task.ResolvedPlatform); | ||
| 28 | } | ||
| 29 | |||
| 30 | [Fact] | ||
| 31 | public void Execute_WithInvalidRuntimeIdentifier_LogsErrorAndReturnsFalse() | ||
| 32 | { | ||
| 33 | var logger = new FakeMsbuildLogger(); | ||
| 34 | |||
| 35 | var task = new ResolveInstallerPlatform(logger) | ||
| 36 | { | ||
| 37 | RuntimeIdentifier = "win10", | ||
| 38 | }; | ||
| 39 | |||
| 40 | Assert.False(task.Execute()); | ||
| 41 | |||
| 42 | WixAssert.CompareLineByLine( | ||
| 43 | new[] { "Error: The RuntimeIdentifier 'win10' is not valid." }, | ||
| 44 | logger.Messages.ToArray()); | ||
| 45 | } | ||
| 46 | |||
| 47 | [Fact] | ||
| 48 | public void Execute_WithNonWindowsRuntimeIdentifier_LogsErrorAndReturnsFalse() | ||
| 49 | { | ||
| 50 | var logger = new FakeMsbuildLogger(); | ||
| 51 | |||
| 52 | var task = new ResolveInstallerPlatform(logger) | ||
| 53 | { | ||
| 54 | RuntimeIdentifier = "linux-x64", | ||
| 55 | }; | ||
| 56 | |||
| 57 | Assert.False(task.Execute()); | ||
| 58 | |||
| 59 | WixAssert.CompareLineByLine( | ||
| 60 | new[] { "Error: The RuntimeIdentifier 'linux-x64' is not a valid Windows RuntimeIdentifier." }, | ||
| 61 | logger.Messages.ToArray()); | ||
| 62 | } | ||
| 63 | |||
| 64 | [Fact] | ||
| 65 | public void Execute_WithRuntimeIdentifierSpecifyingMultiplePlatforms_LogsErrorAndReturnsFalse() | ||
| 66 | { | ||
| 67 | var logger = new FakeMsbuildLogger(); | ||
| 68 | |||
| 69 | var task = new ResolveInstallerPlatform(logger) | ||
| 70 | { | ||
| 71 | RuntimeIdentifier = "win10-x64-arm64", | ||
| 72 | Platform = "", | ||
| 73 | }; | ||
| 74 | |||
| 75 | Assert.False(task.Execute()); | ||
| 76 | |||
| 77 | WixAssert.CompareLineByLine( | ||
| 78 | new[] { "Error: The RuntimeIdentifier 'win10-x64-arm64' specifies multiple platforms which is not supported." }, | ||
| 79 | logger.Messages.ToArray()); | ||
| 80 | |||
| 81 | // Despite the logged error the platform resolver sets the first platform it finds. | ||
| 82 | Assert.Equal("x64", task.ResolvedInstallerPlatform); | ||
| 83 | Assert.Equal("x64", task.ResolvedPlatform); | ||
| 84 | } | ||
| 85 | |||
| 86 | [Fact] | ||
| 87 | public void Execute_WithRuntimeIdentifierAndInitialInstallerPlatformMismatch_LogsErrorAndReturnsFalse() | ||
| 88 | { | ||
| 89 | var logger = new FakeMsbuildLogger(); | ||
| 90 | |||
| 91 | var task = new ResolveInstallerPlatform(logger) | ||
| 92 | { | ||
| 93 | RuntimeIdentifier = "win10-x64", | ||
| 94 | InitialInstallerPlatform = "x86", | ||
| 95 | Platform = "", | ||
| 96 | }; | ||
| 97 | |||
| 98 | Assert.False(task.Execute()); | ||
| 99 | |||
| 100 | WixAssert.CompareLineByLine( | ||
| 101 | new[] { "Error: The RuntimeIdentifier 'win10-x64' resolves to platform 'x64', which conflicts with the provided InstallerPlatform 'x86'." }, | ||
| 102 | logger.Messages.ToArray()); | ||
| 103 | |||
| 104 | Assert.Null(task.ResolvedInstallerPlatform); | ||
| 105 | Assert.Null(task.ResolvedPlatform); | ||
| 106 | } | ||
| 107 | |||
| 108 | [Fact] | ||
| 109 | public void Execute_WithRuntimeIdentifierAndInitialInstallerPlatformMatches_ResolvesToPlatform() | ||
| 110 | { | ||
| 111 | var logger = new FakeMsbuildLogger(); | ||
| 112 | |||
| 113 | var task = new ResolveInstallerPlatform(logger) | ||
| 114 | { | ||
| 115 | RuntimeIdentifier = "win10-x64", | ||
| 116 | InitialInstallerPlatform = "x64", | ||
| 117 | Platform = "", | ||
| 118 | }; | ||
| 119 | |||
| 120 | Assert.True(task.Execute()); | ||
| 121 | |||
| 122 | Assert.Empty(logger.Messages); | ||
| 123 | Assert.Equal("x64", task.ResolvedInstallerPlatform); | ||
| 124 | Assert.Equal("x64", task.ResolvedPlatform); | ||
| 125 | } | ||
| 126 | |||
| 127 | [Fact] | ||
| 128 | public void Execute_WithMismatchedPlatformProperty_LogsWarningButReturnsTrue() | ||
| 129 | { | ||
| 130 | var logger = new FakeMsbuildLogger(); | ||
| 131 | |||
| 132 | var task = new ResolveInstallerPlatform(logger) | ||
| 133 | { | ||
| 134 | RuntimeIdentifier = "win10-x64", | ||
| 135 | Platform = "x86", | ||
| 136 | }; | ||
| 137 | |||
| 138 | Assert.True(task.Execute()); | ||
| 139 | |||
| 140 | WixAssert.CompareLineByLine( | ||
| 141 | new[] { "Warning: The provided Platform 'x86' does not match the resolved InstallerPlatform 'x64'. The output will be built using 'x64'." }, | ||
| 142 | logger.Messages.ToArray()); | ||
| 143 | |||
| 144 | Assert.Equal("x64", task.ResolvedInstallerPlatform); | ||
| 145 | Assert.Null(task.ResolvedPlatform); | ||
| 146 | } | ||
| 147 | } | ||
| 148 | } | ||
diff --git a/src/wix/test/WixToolsetTest.BuildTasks/WixToolsetTest.BuildTasks.v3.ncrunchproject b/src/wix/test/WixToolsetTest.BuildTasks/WixToolsetTest.BuildTasks.v3.ncrunchproject index f1d03cd7..78596c6c 100644 --- a/src/wix/test/WixToolsetTest.BuildTasks/WixToolsetTest.BuildTasks.v3.ncrunchproject +++ b/src/wix/test/WixToolsetTest.BuildTasks/WixToolsetTest.BuildTasks.v3.ncrunchproject | |||
| @@ -2,7 +2,9 @@ | |||
| 2 | <Settings> | 2 | <Settings> |
| 3 | <HiddenComponentWarnings /> | 3 | <HiddenComponentWarnings /> |
| 4 | <IgnoredTests> | 4 | <IgnoredTests> |
| 5 | <AllTestsSelector /> | 5 | <FixtureTestSelector> |
| 6 | <FixtureName>WixToolsetTest.BuildTasks.WixBuildTaskFixture</FixtureName> | ||
| 7 | </FixtureTestSelector> | ||
| 6 | </IgnoredTests> | 8 | </IgnoredTests> |
| 7 | </Settings> | 9 | </Settings> |
| 8 | </ProjectConfiguration> \ No newline at end of file | 10 | </ProjectConfiguration> \ No newline at end of file |
diff --git a/src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs b/src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs index 22cb0a75..78166e00 100644 --- a/src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs +++ b/src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs | |||
| @@ -12,6 +12,9 @@ namespace WixToolsetTest.Sdk | |||
| 12 | using System.Linq; | 12 | using System.Linq; |
| 13 | using Microsoft.VisualStudio.TestTools.UnitTesting; | 13 | using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 14 | using WixInternal.MSTestSupport; | 14 | using WixInternal.MSTestSupport; |
| 15 | using WixToolset.Data; | ||
| 16 | using WixToolset.Data.Symbols; | ||
| 17 | using WixToolset.Data.WindowsInstaller.Rows; | ||
| 15 | 18 | ||
| 16 | [TestClass] | 19 | [TestClass] |
| 17 | public class MsbuildFixture | 20 | public class MsbuildFixture |
| @@ -648,6 +651,42 @@ namespace WixToolsetTest.Sdk | |||
| 648 | [DataRow(BuildSystem.DotNetCoreSdk)] | 651 | [DataRow(BuildSystem.DotNetCoreSdk)] |
| 649 | [DataRow(BuildSystem.MSBuild)] | 652 | [DataRow(BuildSystem.MSBuild)] |
| 650 | [DataRow(BuildSystem.MSBuild64)] | 653 | [DataRow(BuildSystem.MSBuild64)] |
| 654 | public void CanBuildWixlibWithRid(BuildSystem buildSystem) | ||
| 655 | { | ||
| 656 | var sourceFolder = TestData.Get(@"TestData", "Wixlib", "WithBadFiles"); | ||
| 657 | |||
| 658 | using (var fs = new TestDataFolderFileSystem()) | ||
| 659 | { | ||
| 660 | fs.Initialize(sourceFolder); | ||
| 661 | var baseFolder = fs.BaseFolder; | ||
| 662 | var binFolder = Path.Combine(baseFolder, @"bin\"); | ||
| 663 | var projectPath = Path.Combine(baseFolder, "SkipBadFiles.wixproj"); | ||
| 664 | |||
| 665 | var result = MsbuildUtilities.BuildProject(buildSystem, projectPath, new[] | ||
| 666 | { | ||
| 667 | MsbuildUtilities.GetQuotedPropertySwitch(buildSystem, "WixMSBuildProps", MsbuildFixture.WixPropsPath), | ||
| 668 | "-p:RuntimeIdentifier=win-arm64", | ||
| 669 | }); | ||
| 670 | result.AssertSuccess(); | ||
| 671 | |||
| 672 | var wixBuildCommands = MsbuildUtilities.GetToolCommandLines(result, "wix", "build", buildSystem); | ||
| 673 | WixAssert.Single(wixBuildCommands); | ||
| 674 | |||
| 675 | var wixlib = Intermediate.Load(Path.Combine(binFolder, "Release", "SkipBadFiles.wixlib")); | ||
| 676 | var properties = wixlib.Sections.SelectMany(s => s.Symbols).OfType<PropertySymbol>().ToList(); | ||
| 677 | WixAssert.CompareLineByLine( | ||
| 678 | [ | ||
| 679 | "Property sysBUILDARCH=arm64", | ||
| 680 | "Property Platform=arm64", | ||
| 681 | "Property InstallerPlatform=arm64" | ||
| 682 | ], [.. properties.Select(p => $"Property {p.Id.Id}={p.Value}")]); | ||
| 683 | } | ||
| 684 | } | ||
| 685 | |||
| 686 | [TestMethod] | ||
| 687 | [DataRow(BuildSystem.DotNetCoreSdk)] | ||
| 688 | [DataRow(BuildSystem.MSBuild)] | ||
| 689 | [DataRow(BuildSystem.MSBuild64)] | ||
| 651 | public void CanBuildPackageIncludingSimpleWixlib(BuildSystem buildSystem) | 690 | public void CanBuildPackageIncludingSimpleWixlib(BuildSystem buildSystem) |
| 652 | { | 691 | { |
| 653 | var sourceFolder = TestData.Get(@"TestData", "Wixlib"); | 692 | var sourceFolder = TestData.Get(@"TestData", "Wixlib"); |
diff --git a/src/wix/test/WixToolsetTest.Sdk/TestData/Wixlib/WithBadFiles/Library.wxs b/src/wix/test/WixToolsetTest.Sdk/TestData/Wixlib/WithBadFiles/Library.wxs index bcf79a1f..f946fcc6 100644 --- a/src/wix/test/WixToolsetTest.Sdk/TestData/Wixlib/WithBadFiles/Library.wxs +++ b/src/wix/test/WixToolsetTest.Sdk/TestData/Wixlib/WithBadFiles/Library.wxs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | <Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"> | 1 | <Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"> |
| 2 | <Fragment> | 2 | <Fragment> |
| 3 | <StandardDirectory Id="ProgramFilesFolder"> | 3 | <Property Id="sysBUILDARCH" Value="$(sys.BUILDARCH)" /> |
| 4 | <Directory Id="WixLibFolder" /> | 4 | <Property Id="Platform" Value="$(Platform)" /> |
| 5 | </StandardDirectory> | 5 | <Property Id="InstallerPlatform" Value="$(InstallerPlatform)" /> |
| 6 | </Fragment> | 6 | </Fragment> |
| 7 | </Wix> | 7 | </Wix> |
