Blazor - configure live and dev connection strings when publishing

Viewed 170

I am developing my first Blazor Server .Net 6 app. I have a live and dev environment for my app. I am using the "Publish" option in VS2022 where I have 2 ftp profiles configured (live and dev). Is there a way I can configure the Publishing profile to use a Dev db connection string and equally my Live to use the live db connection string

I noticed my app has a appsettings.json and a appsettings.Development.json but im not sure how this is being used by the Publish method

Is there a simple way to do this? Or should I be looking at another method

Many thanks in advance

1 Answers

You need to set the launchSetting.json, it override values that has been set in the system environmentASPNETCORE_ENVIRONMENT.

  {
   "iisSettings": {
     "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:59481",
      "sslPort": 44308
    }
  },
  "profiles": {
    "Development": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "https://localhost:7152;http://localhost:5105",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },,
    "Production": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "Add your url",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Production"
      }
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

After that you can can create appsettings.Development.json that has Dev db connection string and create also appsettings.Production.json that has live db connection string.
Read more

Related