-
Notifications
You must be signed in to change notification settings - Fork 742
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
4
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
4 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 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
84 changes: 84 additions & 0 deletions
84
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,84 @@ | ||
| // 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 System.Collections.Generic; | ||
| 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 lock file target library uses the deprecated MonoAndroid framework | ||
| /// by inspecting the paths of compile-time and runtime assemblies. | ||
| /// </summary> | ||
| /// <param name="library">The lock file target library to check.</param> | ||
| /// <returns>True if the library uses MonoAndroid framework assets.</returns> | ||
| internal static bool UsesMonoAndroidFramework(LockFileTargetLibrary library) | ||
| { | ||
| return ContainsMonoAndroidItem(library.CompileTimeAssemblies) | ||
| || ContainsMonoAndroidItem(library.RuntimeAssemblies); | ||
| } | ||
|
|
||
| private static bool ContainsMonoAndroidItem(IList<LockFileItem> items) | ||
| { | ||
| for (int i = 0; i < items.Count; i++) | ||
| { | ||
| string path = items[i].Path; | ||
|
|
||
| // Paths are like "lib/monoandroid10.0/Assembly.dll" or "ref/monoandroid10.0/Assembly.dll" | ||
| // Extract the framework folder segment (between first and second '/'). | ||
| int firstSlash = path.IndexOf('/'); | ||
| if (firstSlash >= 0) | ||
| { | ||
| int secondSlash = path.IndexOf('/', firstSlash + 1); | ||
| if (secondSlash > firstSlash + 1) | ||
| { | ||
| var folderName = path.AsSpan(firstSlash + 1, secondSlash - firstSlash - 1); | ||
| if (folderName.StartsWith("monoandroid".AsSpan(), StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
| } | ||
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
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
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 wonder if there are cheaper ways to determine this, that doesn't involve re-parsing.
Do you know how much overhead this is adding?
I guess the fact that it's only on
-androidframeworks makes it not a hot path.It's also using span to avoid allocating, but there may be some ways we can utilize the details from the asset selection logic that already parses this.