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

Add DiagnosticSuppressor to suppress the IDE0002 Style Hint in the IDE #9310

Merged
merged 5 commits into from
Sep 30, 2024

Conversation

dellis1972
Copy link
Contributor

@dellis1972 dellis1972 commented Sep 18, 2024

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.

Copy link
Member

@jonathanpeppers jonathanpeppers left a 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.

@dellis1972 dellis1972 changed the title Add the GeneratedCode Attribute to the Resource Designer classes. Add DiagnosticSuppressor to suppress the IDE0002 Style Hint in the IDE Sep 30, 2024
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.
@jonathanpeppers jonathanpeppers merged commit b3079db into dotnet:main Sep 30, 2024
57 checks passed
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.
@dellis1972 dellis1972 deleted the addgencodeattrib branch September 30, 2024 22:12
@github-actions github-actions bot locked and limited conversation to collaborators Oct 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants