Skip to content

Commit

Permalink
Net6.0 Minimal API projects without Startup, issue #3794 (#3814)
Browse files Browse the repository at this point in the history
Fixes missing controllers in the specification when generating Net6.0 Minimal API projects using CLI/MSBuild
  • Loading branch information
bsurprised authored Jan 25, 2022
1 parent a2c28cb commit a423377
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/NSwag.Commands/HostApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,13 @@ void OnEntryPointExit(Exception exception)
try
{
// Get the IServiceProvider from the host
#if NET6_0
var assemblyName = assembly.GetName()?.FullName ?? string.Empty;
// We should set the application name to the startup assembly to avoid falling back to the entry assembly.
var services = ((IHost)factory(new[] { $"--{HostDefaults.ApplicationKey}={assemblyName}" })).Services;
#else
var services = ((IHost)factory(Array.Empty<string>())).Services;
#endif

// Wait for the application to start so that we know it's fully configured. This is important because
// we need the middleware pipeline to be configured before we access the ISwaggerProvider in
Expand Down Expand Up @@ -176,4 +182,4 @@ public void Dispose() { }
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
}
}
}

0 comments on commit a423377

Please sign in to comment.