-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix regression in selecting default RuntimeIdentifier #3543
Merged
dsplaisted
merged 3 commits into
dotnet:release/3.0.1xx
from
dsplaisted:3495-automatic-x86
Aug 19, 2019
Merged
Changes from all commits
Commits
Show all changes
3 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
68 changes: 68 additions & 0 deletions
68
src/Tasks/Microsoft.NET.Build.Tasks/GetDefaultPlatformTargetForNetFramework.cs
This file contains 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,68 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Microsoft.Build.Framework; | ||
|
||
namespace Microsoft.NET.Build.Tasks | ||
{ | ||
public class GetDefaultPlatformTargetForNetFramework : TaskBase | ||
{ | ||
public ITaskItem[] PackageDependencies { get; set; } | ||
|
||
public ITaskItem[] NativeCopyLocalItems { get; set; } | ||
|
||
[Output] | ||
public string DefaultPlatformTarget { get; private set; } | ||
|
||
private const string X86 = "x86"; | ||
private const string AnyCPU = "AnyCPU"; | ||
|
||
protected override void ExecuteCore() | ||
{ | ||
// For .NET Framework projects, the SDK will select a default RuntimeIdentifier and PlatformTarget. If no | ||
// native assets are found from NuGet packages, then the PlatformTarget will be reset to AnyCPU. See the | ||
// comments in Microsoft.NET.RuntimeIdentifierInference.targets for details. | ||
// | ||
// Prior to the .NET Core 3.0 SDK, .NET Framework projects would only have a RuntimeIdentifier graph if the | ||
// Microsoft.NETCore.Platforms package was (transitively) referenced. This meant that native assets would | ||
// only be selected if the platforms package was referenced or if the RuntimeIdentifier matched exactly. | ||
// | ||
// Now that the RuntimeIdentifier graph is provided in the SDK, the logic in this task preserves the PlatformTarget | ||
// behavior from earlier SDKs, even though with the RuntimeIdentifier graph supplied, there may be native | ||
// assets selected where in prior SDKs there would not have been. | ||
|
||
if (NativeCopyLocalItems == null || NativeCopyLocalItems.Length == 0) | ||
{ | ||
DefaultPlatformTarget = AnyCPU; | ||
return; | ||
} | ||
|
||
foreach (var packageDependency in PackageDependencies ?? Enumerable.Empty<ITaskItem>()) | ||
{ | ||
// If the Platforms package is in the dependencies, then any native assets imply an X86 default PlatformTarget | ||
if (packageDependency.ItemSpec.Equals("Microsoft.NETCore.Platforms", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
DefaultPlatformTarget = X86; | ||
return; | ||
} | ||
} | ||
|
||
foreach (var nativeItem in NativeCopyLocalItems) | ||
{ | ||
// If the Platforms package was not referenced, but there are native assets for the exact RID win7-x86, | ||
// then the default PlatformTarget should be x86. | ||
string pathInPackage = nativeItem.GetMetadata(MetadataKeys.PathInPackage); | ||
if (pathInPackage.StartsWith("runtimes/win7-x86/", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
DefaultPlatformTarget = X86; | ||
return; | ||
} | ||
} | ||
|
||
// Otherwise, there would have been no native assets selected on pre-3.0 SDKs, so use AnyCPU as the | ||
// default PlatformTarget | ||
DefaultPlatformTarget = AnyCPU; | ||
} | ||
} | ||
} |
This file contains 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 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 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bump format version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nguerrera I've bumped it, can you re-approve?