在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语言版本
发布评论