OpenAPI kann im minimalen API -Projekt nicht verwendet werden
Posted: 10 Apr 2025, 06:43
Ich versuche, das OpenAPI -Paket in meinem minimalen API -Projekt nach diesem Tutorial aus der Microsoft -Dokumentation zu verwenden.
Ich bin mir also nicht sicher, was ich fehlt. Ich verwende die .NET9-Version und meine CSproj -Datei sieht so aus:
Irgendwelche Ideen, was mir fehlt?
Code: Select all
dotnet add package Microsoft.AspNetCore.OpenApi
< /code>
Das [url=viewtopic.php?t=20324]Problem[/url] kommt, wenn ich versuche, es zu verwenden: < /p>
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();
Code: Select all
net9.0
enable
enable