Building ASP.NET Core Minimal API in VB.NET
This post is about how to build ASP.NET Core Minimal API in VB.NET. Long back I wrote a blog post about Building ASP.NET Core web apps with VB.NET. Today Maurice asked whether we can build ASP.NET Core Minimal APIs in VB.NET. So I thought I will wrote a blog post about it.
Unfortunately by dotnet CLI / Visual Studio doesn’t support ASP.NET Core Web API with VB.NET. But both dotnet CLI and Visual Studio offers VB.NET Console app project templates. So first we need to create a console application with VB.NET with the command -
dotnet new console -lang vb -o HelloWorld --framework net6.0. We can open the project in Visual Studio or VS Code. I am not sure whether VS Code offers an extension for intellisense and other debugging. So I recommend Visual Studio.
To build the Minimal API, first we need to modify the project file - the project Sdk value from
Microsoft.NET.Sdk.Web. Now the project file will look like this.
Next modify the
Program.vb like this.
Now we are ready to build and run the application. Execute the dotnet run command. The screen will display the .NET core log messages with the http and https URLs, like this.
When we browse we will be able to see the Hello World text in browser.
Next we will modify the code similar to the default web api template - weather forecast API with open api. And for supporting Open API we need to add reference of
Swashbuckle.AspNetCore package. Once it is done, modify the
Program.vb code like this.
Now run the app again with
dotnet run command, and browse the
/swagger endpoint we will be able to see the Open API definition for the Minimal API.
This way we can implement ASP.NET Core Minimal API using VB.NET. Again I didn’t tried all the other features, but most of them should work properly. And I don’t remember the VB.NET syntax for lambda expressions, delegates etc. And I am not sure the features like
record available in VB.NET. Let me know if you face any issues.
Happy Programming :)