-
-
Notifications
You must be signed in to change notification settings - Fork 503
RuntimeIdentifier based fixes #673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 3 additions & 7 deletions
10
...ackageCsprojWebApplicationNetCore.wixproj → ...re/WixprojPackageCsprojWpfNetCore.wixproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,13 @@ | ||
| <!-- 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. --> | ||
| <Project Sdk='WixToolset.Sdk'> | ||
| <!-- <Project> --> | ||
| <!-- <Import Sdk="WixToolset.Sdk" Project='D:\src\wix4\build\wix\Debug\net8.0\Sdk\Sdk.props' /> --> | ||
|
|
||
| <PropertyGroup> | ||
| <!-- <WixBinDir>D:\src\wix4\build\wix\Debug\net472\</WixBinDir> --> | ||
| <!-- <WixBinDir64>D:\src\wix4\build\wix\Debug\publish\WixToolset.Sdk\tools\net472\x64\</WixBinDir64> --> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Remove="abc\Bad.wxs" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <!-- SkipPublish="true" BindPath="$(MSBuildProjectDirectory)\does\not\exist" BindName="Xxx" Publish="true" --> | ||
| <ProjectReference Include="..\CsprojWpfNetCore\CsprojWpfNetCore.csproj" Publish="true" /> | ||
| </ItemGroup> | ||
|
|
||
| <!-- <Import Sdk="WixToolset.Sdk" Project='D:\src\wix4\build\wix\Debug\net8.0\Sdk\Sdk.targets' /> --> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // 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. | ||
|
|
||
| namespace WixToolset.BuildTasks | ||
| { | ||
| public interface ILogger | ||
| { | ||
| bool HasLoggedErrors { get; } | ||
|
|
||
| void LogError(string message); | ||
|
|
||
| void LogWarning(string message); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // 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. | ||
|
|
||
| namespace WixToolset.BuildTasks | ||
| { | ||
| using Microsoft.Build.Utilities; | ||
|
|
||
| internal class MSBuildLoggerAdapter : ILogger | ||
| { | ||
| private readonly TaskLoggingHelper log; | ||
|
|
||
| public MSBuildLoggerAdapter(TaskLoggingHelper log) | ||
| { | ||
| this.log = log; | ||
| } | ||
|
|
||
| public bool HasLoggedErrors => this.log.HasLoggedErrors; | ||
|
|
||
| public void LogError(string message) | ||
| { | ||
| this.log.LogError(message); | ||
| } | ||
|
|
||
| public void LogWarning(string message) | ||
| { | ||
| this.log.LogWarning(message); | ||
| } | ||
| } | ||
| } |
174 changes: 174 additions & 0 deletions
174
src/wix/WixToolset.BuildTasks/ResolveInstallerPlatform.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| // 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. | ||
|
|
||
| namespace WixToolset.BuildTasks | ||
| { | ||
| using System; | ||
| using System.Linq; | ||
| using Microsoft.Build.Framework; | ||
| using Microsoft.Build.Utilities; | ||
|
|
||
| /// <summary> | ||
| /// This task calculates the InstallerPlatform from the RuntimeIdentifier, | ||
| /// InitialInstallerPlatform and Platform properties. | ||
| /// </summary> | ||
| public class ResolveInstallerPlatform : Task | ||
| { | ||
| private readonly ILogger logger; | ||
|
|
||
| /// <summary> | ||
| /// Default constructor. | ||
| /// </summary> | ||
| public ResolveInstallerPlatform() | ||
| { | ||
| this.logger = new MSBuildLoggerAdapter(this.Log); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Constructor for dependency injection of logger used by unit tests. | ||
| /// </summary> | ||
| public ResolveInstallerPlatform(ILogger logger) | ||
| { | ||
| this.logger = logger; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The optional RuntimeIdentifier property. | ||
| /// </summary> | ||
| public string RuntimeIdentifier { private get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The optional InitialInstallerPlatform property. | ||
| /// </summary> | ||
| public string InitialInstallerPlatform { private get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The InstallerPlatform property. | ||
| /// </summary> | ||
| public string InstallerPlatform { private get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The optional Platform property. | ||
| /// </summary> | ||
| public string Platform { private get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The resolved InstallerPlatform. | ||
| /// </summary> | ||
| [Output] | ||
| public string ResolvedInstallerPlatform { get; private set; } | ||
|
|
||
| /// <summary> | ||
| /// The optionally resolved Platform. | ||
| /// </summary> | ||
| [Output] | ||
| public string ResolvedPlatform { get; private set; } | ||
|
|
||
| /// <summary> | ||
| /// Convert the input properties into output items. | ||
| /// </summary> | ||
| /// <returns>True upon completion of the task execution.</returns> | ||
| public override bool Execute() | ||
| { | ||
| if (String.IsNullOrEmpty(this.RuntimeIdentifier)) | ||
| { | ||
| this.ResolvedInstallerPlatform = this.InstallerPlatform; | ||
| } | ||
| else if (this.ValidateWindowsRuntimeIdentifier(this.RuntimeIdentifier, out var platform)) | ||
| { | ||
| if (!String.IsNullOrEmpty(this.InitialInstallerPlatform) && !String.Equals(this.InitialInstallerPlatform, platform, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| this.logger.LogError($"The RuntimeIdentifier '{this.RuntimeIdentifier}' resolves to platform '{platform}', which conflicts with the provided InstallerPlatform '{this.InitialInstallerPlatform}'."); | ||
| } | ||
| else | ||
| { | ||
| this.ResolvedInstallerPlatform = platform; | ||
| } | ||
| } | ||
|
|
||
| // If Platform was a generic value, resolve it to the resolved installer platform. | ||
| if (String.IsNullOrEmpty(this.Platform) | ||
| || this.Platform.Equals("AnyCPU", StringComparison.OrdinalIgnoreCase) | ||
| || this.Platform.Equals("Any CPU", StringComparison.OrdinalIgnoreCase) | ||
| || this.Platform.Equals("Win32", StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| this.ResolvedPlatform = this.ResolvedInstallerPlatform; | ||
| } | ||
| else if (!this.Platform.Equals(this.ResolvedInstallerPlatform, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| this.logger.LogWarning($"The provided Platform '{this.Platform}' does not match the resolved InstallerPlatform '{this.ResolvedInstallerPlatform}'. The output will be built using '{this.ResolvedInstallerPlatform}'."); | ||
| } | ||
|
|
||
| return !this.logger.HasLoggedErrors; | ||
| } | ||
|
|
||
| private bool ValidateWindowsRuntimeIdentifier(string runtimeIdentifier, out string platform) | ||
| { | ||
| platform = null; | ||
|
|
||
| var ridParts = runtimeIdentifier.Split('-'); | ||
| if (ridParts.Length < 2) | ||
| { | ||
| this.logger.LogError($"The RuntimeIdentifier '{runtimeIdentifier}' is not valid."); | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| var os = ridParts[0]; | ||
|
|
||
| if (!os.StartsWith("win", StringComparison.OrdinalIgnoreCase) || (os.Length > 3 && !Int32.TryParse(os.Substring(3), out var _))) | ||
| { | ||
| this.logger.LogError($"The RuntimeIdentifier '{runtimeIdentifier}' is not a valid Windows RuntimeIdentifier."); | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| // Ensure there is only one platform specified in the RID. | ||
| foreach (var part in ridParts.Skip(1)) | ||
| { | ||
| string platformPart; | ||
| switch (part.ToLowerInvariant()) | ||
| { | ||
| case "x86": | ||
| case "win32": | ||
| platformPart = "x86"; | ||
| break; | ||
|
|
||
| case "x64": | ||
| case "amd64": | ||
| platformPart = "x64"; | ||
| break; | ||
|
|
||
| case "arm": | ||
| case "arm32": | ||
| platformPart = "arm"; | ||
| break; | ||
|
|
||
| case "arm64": | ||
| platformPart = "arm64"; | ||
| break; | ||
|
|
||
| default: | ||
| continue; | ||
| } | ||
|
|
||
| if (String.IsNullOrEmpty(platform)) | ||
| { | ||
| platform = platformPart; | ||
| } | ||
| else // there can be only one platform in the RID. | ||
| { | ||
| this.logger.LogError($"The RuntimeIdentifier '{runtimeIdentifier}' specifies multiple platforms which is not supported."); | ||
| } | ||
| } | ||
|
|
||
| if (String.IsNullOrEmpty(platform)) | ||
| { | ||
| this.logger.LogError($"The RuntimeIdentifier '{runtimeIdentifier}' does not specify a valid platform."); | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.