Skip to content

publish my app using all those 3 different predefined environment variables #2029

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

Closed
Rick-Anderson opened this issue Oct 31, 2016 · 6 comments
Labels
Milestone

Comments

@Rick-Anderson
Copy link
Contributor

Cust asks:

Hello folks,
I would like to publish my app using all those 3 different predefined environment variables, but I cannot figure out how to target different environment when creating the publish profile.
Since .net core doesn't support multi version of web.config, I cannot use environmentVariable tag in config file to automate my publish.
I also tried launchSettings.json, everything seems fine in VS and I can run different environment locally. I just want to automate my publish process too, so when I use different publish profile, different environment is targeted.

@Rick-Anderson
Copy link
Contributor Author

@sayedihashimi can you comment?

@benzhi2011
Copy link

let me know if you have the solution to this. thx

@sayedihashimi
Copy link
Member

sayedihashimi commented Oct 31, 2016

In ASP.NET 4 the application configuration was strictly tied to the web.config file. We created web.config transforms to solve that issue. In ASP.NET Core, the framework has an extensible configuration system. In the startup.cs file you can configure sources for where config is pulled from.
If you've created the project with Individual Auth in startup.cs you'll see the following.

var builder = new ConfigurationBuilder()
    .SetBasePath(env.ContentRootPath)
    .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
    .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

Here you can see that it picks up appsettings.json and then after that it tries to load appsettings.{env.EnvironmentName}.json where {env.EnvironmentName} is an environment variable defined by ASPNETCORE_ENVIRONMENT.

For multi-environment setup you should create a file that contains the unique config values. Then on your server set the env variable ASPNETCORE_ENVIRONMENT to the correct value. If you don't have secrets then you can check the file into source control. If it has secrets then you should make sure that the file ends up somehow on the web server.

You can also look at extending the ASP.NET Core config system by adding custom providers if the json file based provider doesn't suit your needs.

More info on config at https://docs.asp.net/en/latest/fundamentals/configuration.html.

I hope that helps answer the question here. If not please let me know and I'll expand.

@benzhi2011
Copy link

benzhi2011 commented Nov 1, 2016

Thank you for your reply @sayedihashimi, great help.
I wonder if the aspnet team can do something with the publish profile too. I was using the web.config transforms chained with different publish profile, in this way I can deploy to different environment by a single click. My workaround for the current project is that I have to update the config file on the different servers manually and then not override this file when I deploy.
launchSettings.json is a great file, but this file only used by VS on my development PC. If publish profile setup can make an extra option that picks up a setting from this file will be very smart.

@sayedihashimi
Copy link
Member

@benzhi2011 thanks. I agree that we should have a better story here. I've created aspnet/Tooling#841 to track the work. We can discuss there if you have any ideas. Can we close this issue?

@spboyer
Copy link
Contributor

spboyer commented Dec 14, 2016

This is being tracked at tooling aspnet/Tooling#841

@spboyer spboyer closed this as completed Dec 14, 2016
@tdykstra tdykstra modified the milestones: December-2016, Backlog Dec 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants