How to change the VB.NET language version in Visual Studio 2015

前端 未结 3 1389
感情败类
感情败类 2020-12-01 21:49

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

I\'m looking for the same option for VB.NET - how c

相关标签:
3条回答
  • 2020-12-01 21:59

    I don't think this is possible when using VB.

    See this related connect bug: Connect: VB 14 compiler removes line continuations even when web.config specifies VB 8 as compiler

    0 讨论(0)
  • 2020-12-01 22:17

    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.

    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
    

    Output:

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

    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.

    0 讨论(0)
  • 2020-12-01 22:18

    If you're using ReSharper it turns out this is an option:

    • Left Click on the project in Solution Explorer
    • Select the Properties Window (not the Project Properties - you want the properties snap in)
    • Under ReSharper options there is a "VB Language Level" option, which gives options all the way back to VB.NET 8.

    I haven't tested how well this works.

    0 讨论(0)
提交回复
热议问题