Monday, July 19, 2021

Visual Studio 2022 Preview 2: New Project Properties Page

Visual Studio 2022 Preview 2 was released last week, and in this post, let's have a look at another new feature that got introduced in Visual Studio 2022

If you open up a Project Properties window from Visual Studio 2022, that is entirely a new experience.
Visual Studio 2022: New Project Properties Experience

There are a lot of options we can now manage through the new Project Properties page. For example, if it's a web project, we can update Razor Properties and TypeScript properties directly from the Project Properties page. There is also a new Search box, which is very handy when we need to quickly find something.

The Debug Profile management is moved into its own dialog and has a rich UI to manage different settings such as the newest Hot Reload option, etc.
Visual Studio 2022: Launch Profiles Dialog

Haven't you still tried out Visual Studio 2022? As usual, it runs side by side with previous versions, so do try it out today: Download Visual Studio 2022

Happy Coding.

Regards,
Jaliya

Friday, July 16, 2021

.NET 6 Preview 6: Introducing OpenAPI Support in Minimal APIs in ASP.NET Core

We are getting closer to .NET 6 final release and this week .NET 6 Preview 6 was released. .NET 6 Preview 4 has introduced Minimal APIs in ASP.NET Core. With .NET 6 Preview 6, we now have OpenAPI support for Minimal APIs. In this post, let's see how we can set up Swagger for a project that uses the Minimal API approach.

If you are new to Minimal APIs in ASP.NET Core or need to refresh your memories, you can read this post I have written a couple of months back: .NET 6 Preview 4: Introducing Minimal APIs in ASP.NET Core. I am going to upgrade the sample project (minimal-api) used in that post to .NET 6 Preview 6 and add support for OpenAPI.

First, I am upgrading all the relevant packages to their latest previews, and I am installing Swashbuckle.AspNetCore latest package.
<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <LangVersion>preview</LangVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0-preview.6.21352.1" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0-preview.6.21352.12" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.4" />
  </ItemGroup>

</Project>
In my case, I had only 2 packages installed.
Once the packages are updated, setting up Swagger is pretty straightforward, it's more or less the same to what we have done over all these years.

First, set up the required dependencies.
builder.Services.AddEndpointsApiExplorer();

builder.Services.AddSwaggerGen(c =>
{
    c.SwaggerDoc("v1"new OpenApiInfo { Title = "Minimal API", Description = "OpenAPI specification for Minimal API", Version = "v1" });
});
Then add Swagger OpenAPI specification and Swagger UI to the middleware.
app.UseSwagger();
app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("/swagger/v1/swagger.json""Minimal API V1");
});
That's just it. Now run the application and navigate to https://localhost:5001/swagger and we have Swagger specification at our disposal.
Swagger UI
You can find the sample code here,
   https://github.com/jaliyaudagedara/minimal-api 
      (Commit for Updating packages to .NET Preview 6 and adding OpenAPI support)

Hope this helps.

Happy Coding.

Regards,
Jaliya

Tuesday, July 13, 2021

Azure DevOps: Building Projects Targeting .NET 6

This is a quick post on how you can build a project targetting .NET 6 in Azure DevOps Pipelines.

As of the day I am writing this post (14th July 2021), Microsoft hosted build agents in Azure DevOps doesn't support .NET 6, so if you have a pipeline that builds a project that targets .NET 6, you need to first use this task: Use .NET Core task

It's pretty straight-forward, before the build task, you need to add this task as follows.
task: UseDotNet@2
  displayName: 'Use .NET Core sdk'
  inputs:
    packageType: 'sdk'
    version: '6.0.x'
    includePreviewVersions: true
Hope this helps.

Happy Coding.

Regards,
Jaliya

Wednesday, July 7, 2021

Azure DevOps: Deploying an ASP.NET Core Worker Service to Azure Container Instances

I had a requirement where I wanted to run a timely job. Thought of using an Azure Function, but due to the complexity of the job, moved ahead with an ASP.NET Core Worker Service

Once the dev work is done, wanted to run this on Azure and set up the DevOps side of it. Azure Container Instances (ACI) is the ideal service to run an ASP.NET Core Worker Service in Azure and setting up CI/CD was pretty simple. CI part is just creating a docker image and getting it pushed to an ACR (Azure Container Registry) or where ever you want to. In my scenario, I had the Docker image pushed to an ACR. A very nice thing with ACR to note: there is this option under Repositories -> Images, where you can run any Docker image as an instance on ACI from the portal itself.
Run instance on ACI
But I wanted to CD through DevOps, and that turned out to be just a single Azure CLI Command: az container. I just had to create a container in a container group using an image from Azure Container Registry. The command is something like this (almost all of the arguments are self-descriptive).
az container create -g <ResourceGroup> `
    --name nzmiq-monitor-worker-instance `
    --image myacr.azurecr.io/nzmiqmonitor/worker:$(Build.BuildId) `
    --cpu 1 `
    --memory 1.5 `
    --registry-login-server myacr.azurecr.io `
    --registry-username <RegistryUsername> `
    --registry-password <RegistryPassword> 
Here the $(Build.BuildId) is taken from the Build pipeline.

Isn't it nice?

Happy Coding.

Regards,
Jaliya

Thursday, July 1, 2021

Received Microsoft MVP Award in Developer Technologies

I am honored to receive the precious Microsoft Most Valuable Professional (MVP) Award for the eighth consecutive year.

As always looking forward to another great year on top of Microsoft Development Stack.
Microsoft Most Valuable Professional (MVP)
Thank you Microsoft for your appreciation and Thank you everyone for your continuous support.

Happy Coding.

Regards,
Jaliya