Can VB be used for a net core api project?

Larry Widing 21 Reputation points
2022-03-15T18:21:07.747+00:00

I have an existing web api project written in VB. All the examples for converting to net core 6.0 use C#, and Visual Studio will only create a Web API project using C#.

Can this be done with VB? And if so, what steps are required to do this?

And converting to C# is not, at this time, an option, so please no comments about why we should be using C#, thank you!

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,402 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,668 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 51,346 Reputation points
    2022-03-15T20:24:36.267+00:00

    Can you? Yes, it is .NET after all and any .NET language can be used to write .NET apps. VB is supported on .NET 5 as a platform including ASP.NET Core.

    Does it have full feature support and templates? No. And based upon what MS has said there are no plans to provide such templates.

    However MS has bounced back and forth between VB being fully supported and not. We are back in the "not the future" phase and with .NET 6 MS said they didn't see VB as viable for ASP.NET Core. VB does support .NET 6 as you can partially read here. But the runtime is evolving to support more questionable, performant, newer cases and some of that requires language support. MS has made it clear that C# is the language for that. So you could write an ASP.NET Core app in VB but you might run into some scenarios where VB doesn't have the language constructs needed to properly work with some changes in the framework. I'm not aware of any at this time that are critical. But you'll have to do the legwork to convert the C# project templates to the equivalent VB templates.

    As an aside, one "migration" approach is to keep all your code in VB but create the ASP.NET app itself in C#. Since the bulk of your code is likely backend then it remains in VB as normal and just the front end controller/runtime stuff would be sitting in C#. It isn't ideal but would be a bridge.

    Another approach might be to migrate your app to .NET Core 3.1. This did support VB if I remember correctly. Once you have the project migrated you can more easily upgrade that project to .NET 6 as the changes are minimal.

    1 person found this answer helpful.

3 additional answers

Sort by: Most helpful
  1. Zhi Lv - MSFT 32,106 Reputation points Microsoft Vendor
    2022-03-16T08:03:39.833+00:00

    Hi @Larry Widing ,

    Check this Microsoft statement

    Starting with .NET 5 Visual Basic will support:

    • Class Library
    • Console
    • Windows Forms
    • WPF
    • Worker Service
    • ASP.NET Core Web API

    Going forward, we do not plan to evolve Visual Basic as a language. This supports language stability and maintains compatibility between the .NET Core and .NET Framework versions of Visual Basic.

    I check it on the latest version of VS 2022 (Version 17.1.1), at present, it doesn't provide the related templates for API application.

    And I also find this issue (Add ASP.NET Core Visual Basic project template). It seems that the current development team has no plans to add VB templates.

    So, you can create a C# Asp.net core API application, then try to convert the code from C# to VB.Net by yourself.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Dillion

    1 person found this answer helpful.
    0 comments No comments

  2. AgaveJoe 27,696 Reputation points
    2022-03-15T18:24:59.8+00:00

    Visual Basic is NOT an option in Web API Core 6.0.


  3. Bruce (SqlWork.com) 61,731 Reputation points
    2022-03-21T19:59:31.463+00:00

    It is pretty clear that VB.net is targeted to support windows only development. Its cross platform support is limited to libraries and console apps. If you are writing windows desktop apps, vb.net is strong contender.

    If you want to do web, mobile, and Maui development, with .net core you should make the migration to C#. you can use your old vb code as libraries, but should write new code in C#.

    If you have a group of developers that can not move to C#, and you need to write .net core web or cross platform applications, then they will be limited to class libraries and unit tests.

    0 comments No comments