I am trying to use the OpenApi package in my minimal API project following this tutorial from the Microsoft documentation.
I am using Ubuntu 24.04, and I was able to successfully install the library by running the command:
dotnet add package Microsoft.AspNetCore.OpenApiThe problem comes when i try to use it:
using Microsoft.AspNetCore.OpenApi; /* Error here: The type or namespace name 'OpenApi' does not exist in the namespace 'Microsoft.AspNetCore'*/var builder = WebApplication.CreateBuilder(args);var app = builder.Build();builder.Services.AddOpenApi(); /* Error here: 'IServiceCollection' does not contain a definition for 'AddOpenApi' and no accessible extension method 'AddOpenApi' accepting a first argument of type 'IServiceCollection' could be found */app.MapGet("/", () => "Hello World!");if (app.Environment.IsDevelopment()){ app.MapOpenApi(); /*Error here: 'WebApplication' does not contain a definition for 'MapOpenApi' and no accessible extension method 'MapOpenApi' accepting a first argument of type 'WebApplication' could be found*/}app.Run();So I am not sure what I am missing, I am using the .net9 version and my csproj file looks like this:
<Project Sdk="Microsoft.NET.Sdk.Web"><PropertyGroup><TargetFramework>net9.0</TargetFramework><Nullable>enable</Nullable><ImplicitUsings>enable</ImplicitUsings></PropertyGroup><ItemGroup><PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.1" /></ItemGroup></Project>Any ideas what I am missing?