-
Notifications
You must be signed in to change notification settings - Fork 538
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
Add DiagnosticSuppressor to suppress the IDE0002 Style Hint in the IDE #9310
Merged
Conversation
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
src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceDesignerIntermediateClass.cs
Show resolved
Hide resolved
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 guess we need to update the .apkdesc
files:
File 'lib/arm64-v8a/lib__Microsoft.Android.Resource.Designer.dll.so' has changed by 87 bytes (7.24 %).
I think the threshold is like 5% and this is a really small file.
2883a5d
to
d5981a5
Compare
jonathanpeppers
approved these changes
Sep 30, 2024
src/Microsoft.Android.Sdk.Analysis/ResourceDesignerDiagnosticSuppressor.cs
Show resolved
Hide resolved
Context dotnet#8381 We generate a Resource Designer assembly and an Intermediate source file at build time. Both of these contain classes which should have the `GeneratedCode` Attribute. So lets add it. The version will be the same as the build assembly used to generate it.
ea5df3f
to
126a290
Compare
jonathanpeppers
pushed a commit
that referenced
this pull request
Sep 30, 2024
…IDE (#9310) Context: #8381 Add a `DiagnosticSuppressor` to "turn off" the `IDE0002` style diagnostic message which incorrectly tells users to use the `_Microsoft.Android.Resource.Designer.ResourceConstant` type directly. This can cause allot of annoyance with our users because it appears on EVERY single usage of `Resource.*`. So you end up with what looks like code spagetti. So we need to start shipping an `Analyzer` assembly along with the `Ref` framework pack. This is the place these things need to go. Unfortunately it means that the older frameworks will not get this analyzer. Only the current one. On the packaging side, the Analyzer assembly has to go in a `analyzers/dotnet/<language>` folder in the .Ref Nuget Package. There also needs to be an entry in the `FrameworkList.xml` file which has a `Type="Analyzer" ` and a `Language="cs"`. This allows the IDE's to pickup the code. We can ship both regular Analyzers and the DiagnosticSuppressors in the same assembly. So we can extend this with more if needed. How this works is we use Rosyln to look for the IDE0002 diagnsotic message, we then check the code and see if it is refering to a `_Microsoft.Android.Resource.Designer.*` derived class. If it is , we add a suppression. This will stop the hint appearing in the IDE. I have tested this on VS in devbox and it appears to work . Also we generate a Resource Designer assembly and an Intermediate source file at build time. Both of these contain classes which should have the `GeneratedCode` Attribute. So lets add it. The version will be the same as the build assembly used to generate it.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Context #8381
Add a
DiagnosticSuppressor
to "turn off" theIDE0002
style diagnostic message which incorrectly tells users to use the_Microsoft.Android.Resource.Designer.ResourceConstant
type directly. This can cause allot of annoyance with our users because it appears on EVERY single usage ofResource.*
. So you end up with what looks like code spagetti.So we need to start shipping an
Analyzer
assembly along with theRef
framework pack. This is the place these things need to go. Unfortunately it means that the older frameworks will not get this analyzer. Only the current one.On the packaging side, the Analyzer assembly has to go in a
analyzers/dotnet/<language>
folder in the .Ref Nuget Package. There also needs to be an entry in theFrameworkList.xml
file which has aType="Analyzer"
and aLanguage="cs"
. This allows the IDE's to pickup the code. We can ship both regular Analyzers and the DiagnosticSuppressors in the same assembly. So we can extend this with more if needed.How this works is we use Rosyln to look for the IDE0002 diagnsotic message, we then check the code and see if it is refering to a
_Microsoft.Android.Resource.Designer.*
derived class. If it is , we add a suppression. This will stop the hint appearing in the IDE. I have tested this on VS in devbox and it appears to work .Also we generate a Resource Designer assembly and an Intermediate source file at build time. Both of these contain classes which should have the
GeneratedCode
Attribute. So lets add it. The version will be the same as the build assembly used to generate it.