防止 Visual Studio 2015 删除 VB.NET 文件中的行继续符 (_)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31874556/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 19:22:47  来源:igfitidea点击:

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

vb.netvisual-studio-2015code-formattingpretty-printline-continuation

提问by Paolo Crociati

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

我在 Visual Studio 2015 中打开了一些旧的 VB.NET 项目,当我编辑代码时,VS 更改了语法:

It removes "_" in concatenations:

它在串联中删除“_”:

'Before
myString = "ABC" & _
           "DEF"

'After
myString = "ABC" & 
           "DEF"

or add a space before !:

或在 ! 之前添加一个空格:

'Before
myDatatable.Rows(0)!myColumn

'After
myDatatable.Rows(0) !myColumn

This syntax isn't compatible with Visual Studio 2010 or 2013.

此语法与 Visual Studio 2010 或 2013 不兼容。

How can I disable this changes?

如何禁用此更改?

回答by RiptoR

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.

PS:虽然 Roslyn 团队表示他们修复了这个问题(见下面的链接),但这个错误仍然存​​在于最新版本的 Visual Studio 2015 中。

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

编辑链接到bug报告-链接到合并后的修复(从原来的问题第一个评论复制)

回答by Ira Grollman

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

解决此问题的官方方法是修改 .vbproj 文件以包含

<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

10 适用于 VS2010,如https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/configure-language-version 所述

回答by DeveloperDan

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.

在 Visual Studio (2015-19) 为您“修复”后,只需按 CTRL-Z 即可撤消删除下划线的操作。这使得“漂亮列表”功能处于打开状态,但会恢复丢失的下划线。感谢 David Carta 作为评论留下的答案。