Skip to content
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

Trim leading v from TargetFrameworkVersion #7544

Merged
merged 1 commit into from
Jan 23, 2025

Conversation

tannergooding
Copy link
Member

This is follow up to #7542 which ensures that our checks of build_property.TargetFrameworkVersion support no leading v, the same as the SDK allows.

@tannergooding tannergooding requested a review from a team as a code owner January 23, 2025 17:40
@@ -285,8 +285,7 @@ private static bool PlatformAnalysisAllowed(AnalyzerOptions options, Compilation
string tfmVersion = options.GetMSBuildPropertyValue(MSBuildPropertyOptionNames.TargetFrameworkVersion, compilation) ?? "";

if (tfmIdentifier.Equals(NetCoreAppIdentifier, StringComparison.OrdinalIgnoreCase) &&
tfmVersion.StartsWith("v", StringComparison.OrdinalIgnoreCase) &&
Version.TryParse(tfmVersion[1..], out var version) &&
Version.TryParse(tfmVersion.TrimStart(['v', 'V']), out var version) &&
Copy link
Member Author

@tannergooding tannergooding Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An interesting "quirk" of this is that technically vvvvvvvv5.0 is also valid (and the SDK appears to "support" it as well since they also just TrimStart("vV")); but I don't think that's worth adding an explicit test around 😄

@@ -285,8 +285,7 @@ private static bool PlatformAnalysisAllowed(AnalyzerOptions options, Compilation
string tfmVersion = options.GetMSBuildPropertyValue(MSBuildPropertyOptionNames.TargetFrameworkVersion, compilation) ?? "";

if (tfmIdentifier.Equals(NetCoreAppIdentifier, StringComparison.OrdinalIgnoreCase) &&
tfmVersion.StartsWith("v", StringComparison.OrdinalIgnoreCase) &&
Version.TryParse(tfmVersion[1..], out var version) &&
Version.TryParse(tfmVersion.TrimStart(['v', 'V']), out var version) &&
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth noting that the reason this is TrimStart(['v', 'V']) and not TrimStart("vV") is because analyzers are .NET Standard 2.0 and the latter API returns a ROSpan<char>.

Since we're .NET Standard 2.0, there is no Version.TryParse(ROSpan<char>, out Version) API and we have to convert back to string anways. So I went with what I thought was the shorter/simpler option here.

Copy link

codecov bot commented Jan 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.50%. Comparing base (5c3c07b) to head (9b3ef43).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7544      +/-   ##
==========================================
- Coverage   96.50%   96.50%   -0.01%     
==========================================
  Files        1452     1452              
  Lines      347574   347575       +1     
  Branches    11418    11418              
==========================================
- Hits       335424   335423       -1     
- Misses       9254     9256       +2     
  Partials     2896     2896              

@tannergooding
Copy link
Member Author

-- I don't actually have permission to merge, so if someone else could that'd be great; thanks!

@ViktorHofer ViktorHofer merged commit b0d5ca3 into dotnet:main Jan 23, 2025
14 checks passed
@tannergooding tannergooding deleted the fix-7525 branch January 23, 2025 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants