-
Notifications
You must be signed in to change notification settings - Fork 748
Add NU1703 warning for packages using deprecated MonoAndroid framework #7229
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
Open
sbomer
wants to merge
8
commits into
NuGet:dev
Choose a base branch
from
sbomer:monoandroid-warning
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5d9755a
Add NU1704 warning for packages using deprecated MonoAndroid framework
sbomer e4cb623
Merge remote-tracking branch 'origin/dev' into monoandroid-warning
sbomer 2995ad0
Merge remote-tracking branch 'origin/dev' into monoandroid-warning
sbomer f1ae34f
Reuse NU1703 instead of introducing NU1704 for MonoAndroid deprecatio…
sbomer a7d4667
Use resolved asset frameworks from content model instead of re-parsin…
sbomer e2c1ce2
Merge remote-tracking branch 'origin/dev' into monoandroid-warning
sbomer a553bef
Use separate dedup set for NU1703 so it is not suppressed by NU1701
sbomer 3483f40
Address PR feedback: per-framework dedup set and streamlined tests
sbomer 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
58 changes: 58 additions & 0 deletions
58
src/NuGet.Core/NuGet.Commands/RestoreCommand/MonoAndroidDeprecation.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,58 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
| using NuGet.Frameworks; | ||
| using NuGet.ProjectModel; | ||
|
|
||
| namespace NuGet.Commands | ||
| { | ||
| /// <summary> | ||
| /// Detects when a package uses the deprecated MonoAndroid framework instead of net6.0-android or later. | ||
| /// This warning is gated on .NET 11 SDK (SdkAnalysisLevel >= 11.0.100) and targeting net11.0-android or later. | ||
| /// </summary> | ||
| internal static class MonoAndroidDeprecation | ||
| { | ||
| /// <summary> | ||
| /// Determines whether the MonoAndroid deprecation check should be performed for the given project and target framework. | ||
| /// </summary> | ||
| /// <param name="project">The package spec containing restore metadata.</param> | ||
| /// <param name="framework">The target framework of the current graph.</param> | ||
| /// <returns>True if the deprecation check should be performed.</returns> | ||
| internal static bool ShouldCheck(PackageSpec project, NuGetFramework framework) | ||
| { | ||
| if (project.RestoreMetadata == null) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| // Gate on SDK analysis level >= 11.0.100 | ||
| if (!SdkAnalysisLevelMinimums.IsEnabled( | ||
| project.RestoreMetadata.SdkAnalysisLevel, | ||
| project.RestoreMetadata.UsingMicrosoftNETSdk, | ||
| SdkAnalysisLevelMinimums.V11_0_100)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| // Only check for .NETCoreApp frameworks targeting android with version >= 11.0 | ||
| return StringComparer.OrdinalIgnoreCase.Equals(framework.Framework, FrameworkConstants.FrameworkIdentifiers.NetCoreApp) | ||
| && framework.Version.Major >= 11 | ||
| && framework.HasPlatform | ||
| && framework.Platform.Equals("android", StringComparison.OrdinalIgnoreCase); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Checks whether the given framework is a MonoAndroid framework. | ||
| /// </summary> | ||
| /// <param name="framework">The framework to check, or null.</param> | ||
| /// <returns>True if the framework uses the MonoAndroid framework identifier.</returns> | ||
| internal static bool IsMonoAndroidFramework(NuGetFramework framework) | ||
| { | ||
| return framework != null | ||
| && StringComparer.OrdinalIgnoreCase.Equals( | ||
| framework.Framework, | ||
| FrameworkConstants.FrameworkIdentifiers.MonoAndroid); | ||
| } | ||
| } | ||
| } | ||
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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.
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.
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.
I'm wondering if NuGet is the right place to check for this. Can this logic be moved to the Android workload instead? It's probably easiest to do in NuGet, but this is code that will run for every restore, even when the Android workload isn't installed.
When I take a binlog of a normal build, the .NET SDK reads NuGet's assets file in the
ResolvePackageAssetstask. TheRuntimeCopyLocalItemsandResolvedCompileFileDefinitionsitems havePathInPackagemetadata, which can be searched formonoandroid, for example a regex something like[lib|ref]/monoandroid*. Checking the runtime assets will be tricker to validate the subdirectory that corresponds to the TFM.It's not as precise as checking the
NuGetFrameworkfor the selected asset, but the question is if it's good enough.Another design idea is to change the assets file to emit a "framework" metadata for every asset, and change the SDK's
ResolvePackageAssetsto copy that metadata into the MSBuild item, which can then be checked by the android workload's msbuild targets. However, I don't like this idea as the increased assets file size and additional metadata on every item will cause additional memory allocations and therefore more GC and will probably have worse perf impact than the small benefit in moving the check from NuGet to the android workload.Given restore almost never breaks backwards compatibility, I just want to make sure that NuGet isn't stuck with this "forever" when it's fundamentally a non-NuGet concern. So, trying to do due diligence in checking if the owning component can feasibly implement the check, rather than NuGet.
Uh oh!
There was an error while loading. Please reload this page.
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.
I'm not familiar enough with the design of the workloads to know whether it would make sense to handle it there. @jonathanpeppers what do you think?
My instinct is that this should warn during restore, not during build, which is why I thought it made the most sense to handle it in NuGet. Plus there was precedent in the (now removed) Xamarin.iOS warning.
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.
The design says to emit this warning here in NuGet (but note the code was NU1701 back then):
I'm not aware of us running any MSBuild logic during restore from a workload.
If we had to do it from a workload, it would be easiest to do during a build -- which is maybe not what we'd want.