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

3

13

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 can I restrict syntax, etc. to old VB.NET versions?

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.

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

Bowleg answered 20/8, 2015 at 15:43 Comment(0)
U
15

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.

Uranium answered 20/8, 2015 at 16:17 Comment(7)
I'll have a test of that. It still seems to be allowing Readonly Auto properties. Do you see that too?Bowleg
I can repro that. Beware that this doesn't get put to the test very often, connect.microsoft.com is a good place to report bugs like this.Uranium
I'll do a test of all the new VB14 features and report on connect.Bowleg
Is raised here if you wan't to give it a vote. Not sure these days if stuff should be logged in Connect or in the open source project areas.Bowleg
I voted. Now tracked in this Roslyn bug, closed as resolved on Jan 21st.Uranium
From what I can see, setting LangVersion in the .proj file works in VS 2015, but not in 2017.Wiliness
Works just fine, checked in version 15.5.6Uranium
B
4

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.

Bowleg answered 20/8, 2015 at 16:17 Comment(0)
K
0

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

Kolb answered 20/8, 2015 at 16:5 Comment(2)
Do you think it would be possible to reproduce the C# functionality via an Extension to VS?Bowleg
Just noticed that ReSharper can do it - see my answer.Bowleg

© 2022 - 2024 — McMap. All rights reserved.