如何在Visual Studio 2015中更改VB.NET语言版本

编程入门 行业动态 更新时间:2024-10-15 14:16:24
本文介绍了如何在Visual Studio 2015中更改VB.NET语言版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在Visual Studio 2015中,可以选择要编码的C#语言版本,如此处.

In Visual Studio 2015 it is possible to select which version of the C# language is being coded in, as shown here.

我正在为VB.NET寻找相同的选项-如何将语法等限制为旧的VB.NET?

I'm looking for the same option for VB.NET - how can I restrict syntax, etc. to old VB.NET versions?

我想这样做,以便在与某人共享使用 Visual Studio 2012 .我宁可不要在Visual Studio 2012上安装垃圾邮件,也不必为偶发的需求创建新的VM.

I want to do this so that I stop accidentally using VB 14 features in a project I'm sharing with someone using VisualStudio2012. I'd rather not spam up my machine with a VisualStudio2012 install or have to create a new VM for a fairly occasional requirement.

注意:我不想更改目标.NET Framework版本.

NOTE: I don't want to change the target .NET Framework version.

推荐答案

VB.NET编译器具有/langversion 选项.也受MSBuild支持.但不是通过IDE,就很难更改它.

The VB.NET compiler has the /langversion option for this. Also supported by MSBuild. But not by the IDE, that makes it awkward to change it.

仍然有可能,您必须编辑.vbproj文件.使用文本编辑器,记事本即可.然后复制/粘贴此代码段,将其插入第四行,这样对所有配置和平台均有效:

Still possible, you have to edit the .vbproj file. Use a text editor, Notepad will do. And copy/paste this snippet, insert it in the 4th line so it is effective for all configurations and platforms:

<PropertyGroup> <LangVersion>12</LangVersion> </PropertyGroup>

并再次检查它是否有效:

And double-check that it is effective:

Module Module1 Sub Main() Dim test As String Console.WriteLine(NameOf(test)) End Sub End Module

输出:

error BC36716: Visual Basic 12.0 does not support 'nameof' expressions.

行之有效,也被IntelliSense标记为红色花体.您可能想要创建自己的项目模板,因此不必一遍又一遍地执行此操作.使用文件>导出模板.

Well, that works, also flagged by IntelliSense with red squiggles. You probably want to create your own project templates so you don't have to do this over and over again. Use File > Export Template.

更多推荐

如何在Visual Studio 2015中更改VB.NET语言版本

本文发布于:2023-11-07 23:19:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1567702.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语言   版本   如何在   Visual   Studio

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!