45

I have a couple of confusions:

  1. I published an ASP.NET Core project and I do not see launchsettings.json in bin\Release\PublishOutput. If I use Octopus, how do I configure attributes based on server type?

  2. Is it possible to move launchsettings.json to the root folder instead of under properties?

  3. If I want to use only one json like appsettings.json, can I merge both in the root folder?

  4. Can web.config be used instead of launchsettings.json, and how?

Pang
  • 9,564
  • 146
  • 81
  • 122
newbeedeveloper
  • 759
  • 2
  • 6
  • 10
  • 13
    `launchSettings.json` is only for Visual Studio. Other than that, it's not clear what you're trying to do. – Chris Pratt Oct 26 '17 at 13:37
  • In general, it is discouraged on Stack Overflow to put more that one question in one post, With your future questions please follow this guideline :) – Will Barnwell Oct 27 '17 at 21:09
  • 3
    @Chirs Pratt, I recently hosted asp core app on linux box and when I change the values of this launchSettings.json file of key applicationUrl, and hit dotnet run, hosting is configured to this value. So I think this file has its effects on dotnet run command also. If so, is this file read on CreateDefaultBuilder() method in Program.cs ? – XPD Sep 16 '18 at 17:52
  • 1
    When an app is launched with dotnet run: launchSettings.json is read if available. environmentVariables settings in launchSettings.json override environment variables. – Fish Aug 14 '19 at 04:44

1 Answers1

46

Answers to your questions:

  1. As Chris Pratt mentioned in comment, launchSettings.json is only used by Visual Studio. You can use Octopus variables in Octopus.
  2. Don't need launchSettings.json for publishing an app.
  3. If there are settings that your application needs to use, please store them in appsettings.json. This will make deployments easier, since Octopus recognizes this file by default.
  4. It depends on your requirements. web.config is used by IIS, not by your .NET Core application directly, hence IIS limitations to what you can configure might be applied.

Hints.

  • If you have some environment specific variables, you can store them in environment specific appsettings.json, e.g. appsettings.Release.json.
  • You can leave placeholders for Octopus variable substitution in your appsettings.json file, especially in environment specific one, e.g. appsettings.Release.json may contain a config value like "#{ConnectionString}" and during deployment Octopus would substitute this placeholder with the actual value from Octopus variables.
Ignas
  • 4,092
  • 17
  • 28
  • Thanks for reply. Net Core does not have web.config, so how IIS deal with it, can IIS also read appsettings.json? – newbeedeveloper Oct 27 '17 at 06:57
  • 1
    If you don't have `web.config` in your project, it will be created when you publish. If you have one, it will be transformed to have correct parameters when published. See https://learn.microsoft.com/en-us/aspnet/core/publishing/iis?tabs=aspnetcore2x And IIS can't use `appsettings.json`, only your application can. – Ignas Oct 27 '17 at 19:59
  • @newbeedeveloper IIS Express should have no idea what those settings are, and Visual Studio is the bridge, https://blog.lextudio.com/how-visual-studio-launches-iis-express-to-debug-asp-net-core-apps-d7fd3677e3c3 – Lex Li Mar 30 '18 at 20:22
  • @Ignas if `launchsettings.json` is only for VS how can I configure `applicationurl` for each application I have on a linux server? – Offir Sep 25 '19 at 14:37
  • @OffirPe'er What do you use `applicationurl` in your applications for? Are all your applications different products, ie not just another instance of the same application? – Ignas Sep 25 '19 at 18:52
  • @Ignas, it's the same application but with different environment, production, staging and development – Offir Sep 25 '19 at 20:40
  • @OffirPe'er It might depend on your server setup, however I think you could have `applicationurl` in `appsettings.json`, and have your CD tool, e.g. Octopus to provide the correct value for the `applicationurl` depending on the environment. – Ignas Sep 26 '19 at 07:25
  • From my experience today launchSettings.json should just have the ASPNETCORE_ENVIRONMENT value e.g. Development and then you have a appsettings.Development.json file with your dev config values. Ignore setting anything else in the launchSettings.json as it just gets ruddy confusing – Andrew Jun 03 '20 at 09:53
  • 2
    why does `dotnet watch run --launch-profile "someprofile in launchsettings.json" work` if 'launchSettings.json is only used by Visual Studio'? – Lei Yang Feb 24 '21 at 01:49
  • During development my connection string is in app settings json file. When I deploy to iis should I move it to web.config? – variable Jan 11 '22 at 15:39
  • If launchsettings json is meant for dev purpose only, then why does the documentation here https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-apache?view=aspnetcore-6.0#publish-and-copy-over-the-app ask us to modify the `launchSettings.json`? – variable Jan 14 '22 at 13:55
  • 2
    this answer needs to made into a blog post – John Nyingi Feb 03 '22 at 08:44