1

I have a main web application and a Web API application. (The first application calls the API of the second application.) When running locally, Visual Studio is configured to lauch both applications.

My appsettings.development.json file overrides the URL of the API website when running locally. This is working fine.

But now another developer is running these projects on his system. When he does, the URL of the API website is different than on my system.

How can this developer configure a different URL in appsettings.development.json without overwriting my settings when he checks it in?

Jonathan Wood
  • 61,921
  • 66
  • 246
  • 419

3 Answers3

3

I assume you use a Code versioning control tool. I will assume you use git. If it's not the case, you SHOULD use a Versioning Control tool, if it's not git, check how you can "ignore" specific files.

You should not track the appSettings.development.json and add it to your .gitignore (see this thread if appSettings.development.json is already tracked and you need to clean it.)

Then each developer will have his own appSettings.development.json and it will not be overwritten

HTH

1

You could use user secrets for this. It's basically a JSON config file that is outside the project folder so it won't get checked in to version control. I've used this for local DB connection strings/API URLs etc.

In Visual Studio you can right click the project and click Manage user secrets to open the user secrets file.

juunas
  • 47,491
  • 9
  • 98
  • 133
1

You could use different Launch Settings, so you can create separate appSetting file for each developer.

You can create appSettings.Developer1.json and appSettings.Developer2.json for both developer, then you will need to modify launchSetting.json as below to make it work for both developer

below is example launchSetting.json

{
  "iisSettings": {
    ...
  },
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "profiles": {
    "Developer 1": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Developer1"
      }
    },
    "Developer 2": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Developer2"
      }
    }
  }

You can choose which setting to use when running application