[英]Prevent Visual Studio 2015 from removing line continuation characters (_) in VB.NET files
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?如何禁用此更改?
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 中。
edit Link to bug report - Link to merged fix (copied from first comment on original question)编辑错误报告的链接 - 合并修复的链接(从原始问题的第一条评论中复制)
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 所述
Just CTRL-Z to undo the removal of the underscores right after Visual Studio (2015-19) "fixes" it for you.只需 CTRL-Z 即可在 Visual Studio (2015-19) 为您“修复”后撤消删除下划线。 This leaves the "Pretty Listing" feature turned on but restores the missing underscores.这使得“漂亮列表”功能处于打开状态,但会恢复丢失的下划线。 Thanks David Carta for the answer left as a comment.感谢 David Carta 作为评论留下的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.