Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set environment because IHost is already constructed in .NET 6 web app #75

Open
azborgonovo opened this issue Dec 20, 2022 · 2 comments

Comments

@azborgonovo
Copy link

azborgonovo commented Dec 20, 2022

Symptom

Running a command like dotnet run -- db-patch file.sql --environment Staging results in the following error:

image

Context

I tried to set up my .NET 6 web application as described in the docs. In summary, my Program.cs file looks like the following:

var builder = WebApplication.CreateBuilder(args);
builder.Host.ApplyOaktonExtensions();
// ... other changes in the host builder (e.g. builder.Services.AddAuthentication())
var app = builder.Build();
// ... changes in the app (e.g. app.UseAuthentication())
return await app.RunOaktonCommands(args);

My development environment is a macOS with Apple silicon.

@azborgonovo
Copy link
Author

There is a workaround/containment that can be used locally (at least for setting up env variables).

Set the environment with the launchprofile instead of via --environment parameter:

dotnet run --launch-profile Staging -- db-patch file.sql

@agross
Copy link
Contributor

agross commented Feb 6, 2023

That workaround unfortunately does not work for me. I receive the same "is already constructed" as above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants