Reputation: 111
After updating Visual Studio 2022 to version 17.12.3, I noticed that the "Create and Assign Field" quick action no longer respects the naming conventions I configured in Tools > Options > Text Editor > C# > Code Style > Naming.
Previously, I had set up a naming rule for private fields to use an underscore prefix (e.g., _fieldName) as shown in the screenshot below:
This configuration worked globally for all solutions, and the generated code adhered to my customizations. However, after the update:
The quick action generates fields prefixed with this (e.g., this.fieldName), ignoring my rules.
Here's an example of what I'm experiencing: Create and Assign Field Behavior
What I Tried: I added an .editorconfig file (originally generated from an old project) This resolves the issue, but I have to repeat this process for every new solution, which wasn’t necessary before the update.
Is there a way to make the naming rules global again, so they apply to all solutions without needing an .editorconfig file for each one?
Upvotes: 11
Views: 476
Reputation: 111
The issue is fixed in Visual Studio 2022 version 17.13.2. After updating, the 'Create and Assign Field' quick action follows the naming conventions correctly again. Thanks to @purplecat for pointing this out
Upvotes: 0
Reputation: 21
This is a feature that was shipped with .NET 9 (see Microsoft developer community post). On the aforementioned thread Microsoft have since said they are going to revert this behaviour in a service release of .NET 9. As someone else pointed out on that thread, it's utterly ridiculous that this change in behaviour was part of a point release. Another reason to move to Rider I guess lol.
Upvotes: 0
Reputation: 6717
Edit: Just noticed that this only fixed the issue until Visual Studio was restarted, then the issue came back again...
I had the exact same issue. I dont know what caused Visual Studio to "forget" my naming rule, but removing it and adding it back again fixed it for me.
So:
Then open Visual Studio and add them back again
Some screenshots if you forgot how it looked like:
Upvotes: 1