roslyn
roslyn copied to clipboard
Code cleanup on save while resolving merge conflicts
This issue has been moved from a ticket on Developer Community.
[severity:It's more difficult to complete my work] [regression] [worked-in:VS2019] With turned on feature 'Code Cleanup on Save', while resolving conflicts after merging branches, after applying changes all 'using' directives are gone.
Original Comments
Feedback Bot on 4/18/2022, 01:41 AM:
(private comment, text removed)
Original Solutions
(no solutions)
Very annoying, we must deactivate "Code Cleanup on Save" before resolving conflicts.
I don't know if this is the only time it happens, but I have noticed that if you have conflicts in a project file it causes the project to be unloaded. If you are then reviewing conflicts in a file within that project then it loads the files from outside of the project i.e. with the path to file on disk. Which means the code cleanup does not have context and removes all using statements. This happens even in the diff window not just the merge window.
As a workaround, it may be possible that resolving project conflicts first prevents this from happening.
Hi,
We have the same behavior.
Any news on this issue ?
As a workaround, it may be possible that resolving project conflicts first prevents this from happening.
Unfortunately not. I didn't find any workaround apart from deactivating "Code Cleanup on Save".
I am also facing the same problem, I found code cleanup feature very handy but for this problem I had to unable it.
i'm having the same behavior
Can confirm this is still a problem as of VS 2022 17.3.4. Very annoying bug.
Confirming this is still an issue
Still an issue, quite a big one (VS2022 17.3.6).
Same issue using VS2022 17.4.1
Very annoying
Same for me in VS2022 17.4.2.. 🙁
Same here
Note that this not only removes all using directives, but also breaks the code style of the merged file by ignoring rules defined in the EditorConfig file.
If someone needs steps to reproduce:
- Enable Options - Text Editor - Code Cleanup - Run Code Cleanup profile on Save
- Make sure that the chosen Code Cleanup profile formats the document and removes unnecessary usings.
- Do a Git merge that results in a conflict in a C# file.
- Resolve the conflict. Note that the preview of the resulting file in the lower part of the conflict window shows everything as it should be.
- Open the file after resolving the conflict.
- Note that all usings are removed from the file, which breaks the code.
- Also note that the formatting of the file was reset to the Visual Studio settings instead of the settings defined in the EditorConfig file.
Same problem here, in VS 2022 version 17.4.2
Our team is also seeing this issue. It's a big pain. Please fix. VS 17.4.0
@JoeRobich Can we get a quick update on this? 🙂 Seems like lots of people are running into this (including myself! 😄)
Include me in the list of people having this issue.
If anyone is looking for a quick workaround, here's what I do:
- Make sure that the
Add missing using directives on paste
option is enabled (Tools -> Options -> Text Editor -> C# -> Advanced -> "Using directives" section) - After the editor has stripped out your
using
statements, open the file and doCtrl+A
,Ctrl+X
,Ctrl+V
Basically, copying and pasting the document on top of itself triggers the Add missing using directives on paste
functionality, which readds most of the using
statements 🙂
@sharwell Sorry to message you directly, but is @JoeRobich still the correct person to be assigned to this, or could we get a status update? 🙂 Seems like a lot of people are hitting this, especially in the newer versions of VS.
@JoeRobich
@CSTI-IHarwell
@EngWagner I'm guessing they're probably on Christmas or New Year's vacation 🙂
If anyone is looking for a quick workaround, here's what I do:
- Make sure that the
Add missing using directives on paste
option is enabled (Tools -> Options -> Text Editor -> C# -> Advanced -> "Using directives" section)- After the editor has stripped out your
using
statements, open the file and doCtrl+A
,Ctrl+X
,Ctrl+V
Basically, copying and pasting the document on top of itself triggers the
Add missing using directives on paste
functionality, which readds most of theusing
statements 🙂
This is unfortunately not working for me, first I have to find the file first which is the hardest part because I always forget the name of the file and regret it immediately after hitting the accept merge button.
I also have this annoying issue. Visual Studio Professional 2022 (64bit) 17.4.3
Also suffering from this. It's also not only when resolving merges, VS always removes all using directives except System ones when I run code cleanup.
I literally created an account on github just to thumbs-up this post, though my whole team has been dealing with this since last year. Visual Studio Professional (64 bit) 17.4.4
I'm using CodeCleanupOnSave extension, which has the same functionality, but no such issue. It is very strange that this issue is still present after almost a year. It is also funny that it's an extension by Mads Kristensen :) .
Hi @sharwell, now that it's after Christmas/New Year's vacation, can we confirm that @JoeRobich is the correct person to be assigned to this?
It seems this is affecting a lot of people, and there hasn't been any visible activity from @JoeRobich since April 20th, 2022 😄
Hi @sharwell, now that it's after Christmas/New Year's vacation, can we confirm that @JoeRobich is the correct person to be assigned to this?
It seems this is affecting a lot of people, and there hasn't been any visible activity from @JoeRobich since April 20th, 2022 😄
And that activity in April was not even by Joe, it was by @jinujoseph who assigned Joe to this... 🤯