Prevent Visual Studio 2015 from removing line continuation characters (_) in VB.NET files

前端 未结 3 1010
抹茶落季
抹茶落季 2020-12-15 20:19

I\'m opening some old VB.NET projects in Visual Studio 2015 and when I edit the code, VS changes the syntax:

It removes \"_\" in concatenations:

\'Be         


        
相关标签:
3条回答
  • 2020-12-15 21:00

    The official way to address this is modifying the .vbproj file to include

    <PropertyGroup>
       <LangVersion>latest</LangVersion>
    </PropertyGroup>
    

    10 is for VS2010 as described at https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/configure-language-version

    0 讨论(0)
  • 2020-12-15 21:08

    I had the same problem, and I was able to fix it by disabling the "Pretty listing" option in the editor. You can find this option here:

    Tools > Options > Text Editor > Basic > Advanced > Editor Help > Pretty listing (reformatting) of code
    

    I'm not sure what other auto-reformatting this option disables, but at least the editor stopped removing the line continuation characters in old code/projects.

    PS: While the Roslyn team says they fixed this (see links below), this bug is still present in the latest version of Visual Studio 2015.

    edit Link to bug report - Link to merged fix (copied from first comment on original question)

    0 讨论(0)
  • 2020-12-15 21:18

    Just CTRL-Z to undo the removal of the underscores right after Visual Studio (2015-19) "fixes" it for you. This leaves the "Pretty Listing" feature turned on but restores the missing underscores. Thanks David Carta for the answer left as a comment.

    0 讨论(0)
提交回复
热议问题