-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
CLI: Allow setting environment at runtime #872
Comments
I don't see --environment as an option for Also, I don't understand how the introduction of such a parameter would provide any more flexibility over passing ASPNETCORE_ENVIRONMENT as an environment variable to the command as follows:
|
Just ran into this missing option to set environment. Seems to be needed when using the Manage User Secrets feature of VS, then without the environment = Development setting, the "dotnet swagger tofile..." command embedded in a .csproj fails if you use config properties for oauth2 setup in the Startup.cs. |
I have a similar use case where we wish to use the CLI to create contract diffs during PRs. Unfortunately we access secrets in our Startup.cs file that are not available at build time and are only available when we deploy. This causes a particular piece of our Startup to error because it's attempting to use a configuration variable that's Being able to specify configuration options similar to the Environment would allow us to use the CLI without making code changes. |
I have the same use case as persalmi. I'm using Manage User Secrets with a script in the .csproj file <Target Name="SwaggerToFile" AfterTargets="AfterBuild">
<Exec Command="dotnet swagger tofile --output swagger.json $(TargetPath) v1" />
</Target> I'm getting an error that settings are null. |
If using the CLI as part of you build pipelines on Azure DevOps, you can do it like this:
|
@nascosto - it seems there's very reasonable solutions here, can this be closed? |
Yeah. Let's close this for now. Thanks. |
Just if anybody still looks for a solution to make it work in <Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="dotnet tool restore" />
<Exec Command="dotnet swagger tofile --output swagger.json $(OutputPath)$(AssemblyName).dll v1" EnvironmentVariables="ASPNETCORE_ENVIRONMENT=$(ASPNETCORE_ENVIRONMENT)" />
</Target> |
With this instruction I'm getting "Debug" and not the Environment Variable, how is this supposed to work? |
What are you trying to do? |
I'm trying to compile the project and I need the environment to be able to connect to the correct key vault.
I'm trying to compile the project and I need the environment to be able to connect to the correct key vault.
This means that I have to create a new configuration and call it "Development"? And when I run my pipeline I should create also a configuration to define the environment. What I think is the best is being able to read the environment variable already defined so you don't have to define the environment in multiple places |
Well then simply use the variable: https://stackoverflow.com/questions/48618357/how-to-get-environment-variable-in-csproj-file I updated my code above. |
Trying to do this using gitlab pipelines without much success:
Tried many variations without success:
|
passing environment variables :
is this working or any other options above? |
I would like the ability to specify the environment of the API when running the CLI to control which appsettings files get used. Currently, it defaults to Production, but our production values are tucked away into secrets and loaded outside the appsettings file. I'd like to point it to Development.
dotnet run has the ability to set environment via --environment and has the ability to set environment variables in general using =. It also can pull the ASPNETCORE_ENVIRONMENT from the launchSettings.json
I can still set ASPNETCORE_ENVIRONMENT at the user/system level, but I'd prefer the flexibility of one of these other options.
The text was updated successfully, but these errors were encountered: