如何在Visual Studio 2015中更改VB.NET语言版本 [英] How to change the VB.NET language version in Visual Studio 2015

查看:254
本文介绍了如何在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 Visual Studio 2012. I'd rather not spam up my machine with a Visual Studio 2012 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语言版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆