visual-studiovisual-studio-2022richtext

Copy text with color highlighting from Visual Studio


How can I copy (and paste) text from Visual Studio maintaining the colors? If I copy from VS Code, the colors are preserved (e.g. for C# Code). But copying from Visual Studio, only the "typewriter" font (Cascadia Mono) information is copied.

Version: Visual Studio 2022 - (17.9.7)

I checked the option "Copy rich text on copy/cut". I even unchecked it, restarted, checked it and started again - with no effects.

Is this a bug? Or did I miss something?

enter image description here


Solution

  • It might be a bug according to the documentation, which states

    Selected by default, the option copies text that includes colors and ligatures.

    and (not shown in your screenshot, but on that same dialog),

    Use accurate classification

    Toggle this checkbox to allow for semantic colorization. A "wait" dialog might appear after a few seconds. (There's syntactic colorization, which is fast to copy, and semantic colorization, which is slower to copy. Semantic information allows for richer and more accurate colorization.)

    Try turning both of these on. Also,

    If none of that works, you might be out of luck and should submit a Developer Community suggestion.

    It's worth including Peter's comment in this answer. Thank you Peter.

    It's a bug in the recent VS versions, indeed. Even the Copy As Html 2022 extension from Microsoft suffers from this problem. According to the discussion on their site, it's caused by the recent Roslyn breaking change. We need to wait.