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

编程入门 行业动态 更新时间:2024-10-15 12:36:18
本文介绍了如何在 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?

我想这样做是为了避免在我与某人使用 VisualStudio2012.我宁愿不使用 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 文件.使用文本编辑器,记事本就行.并复制/粘贴此代码段,将其插入第 4 行,使其对所有配置和平台均有效:

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

发布评论

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

>www.elefans.com

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