0

First let me give some background

We have our own VPS, so we do not wish to use Azure to host our web applications.

We have already successfully created a CI/CD pipeline to our VPS by installing an agent on it for a .NET Core project.

We use Azure DevOps (formerly known as VSTS) to host our code in GIT and handle our backlogs and CI/CD pipelines.

We have several .NET Framework projects where we use XTD transforms to transform our web.config files on delivery/deployment to have the correct connection strings and other configuration properties.
This makes it possible to pull the master branch from our remote repo and have it working in seconds on a previously unused (for this application) development environment without the need for any configuration.

Now to get to my question

The master branch of the .NET Core project for which we already have the CI/CD pipeline in place holds the configuration in the json files for the staging environment it is continuously delivered to. When a developer pull the master branch, he/she first needs to configure these to suite the local debug environment.

This is an undesirable situation for us.

How can we make it so that if we use .NET Core we can use a mechanism that will allow us to have the project work on a local debug environment without any configuration and in the CI/CD pipeline?

What have we already tried?

we have found that we can have multiple versions of the appsettings.json file for the different environments like appsettings.debug.json and than in the static method CreateWebhost of the Program class we can call on or the other. But how we can automate this is something that we haven't been able to figure out or find documentation about.

Daniël Tulp
  • 1,745
  • 2
  • 22
  • 51

1 Answers1

0

Okay, so here are some options you can take advantage of TODAY. (there are im sure more options/approaches)

Option A Configure the master branch to have appsetting.development.json with connection string to DEV database( or lowest environment) remove any connection string from appsettings.json

Merge master accordingly. Create environment variables on each of the backend servers for the connection string; ex, system environment variable named ConnectionStrings:cartDB with connection string to the database for the environment for which the backend server used. The result of this will be that when running using DEVELOPMENT as the environment variable, then it will be able to connect to database everyone can access. However, since all OTHER web servers have environment variables with connection string, they will take highest level of precedence, and will therefore be the values set when calling something such as

string connectionString = Configuration.GetConnectionString("cartDB");

This will satisfy the requirements you mentioned above.

Option B: Configure the master branch to have appsetting.development.json with connection string to DEV database( or lowest environment) remove any connection string from appsettings.json Place appsetting.staging.json, appsettings.prod.json in source control, and set environment name variable in web servers. :/ not the best of options/advised against. (its worth mentioning since I have seen this happen, we all have)

Option C Add appsetting.staging.json, appsettings.prod.json to source control and use a token in place of the connection string value. Then, leverage some type of Tokenization Task to replace those tokens with the appropriate values.

Judy007
  • 5,484
  • 4
  • 46
  • 68
  • thank you for your answer Joey, why would you advise against option B? and do you have some sort of reference for option C, I am unfamiliar with a Tokenization Task – Daniël Tulp Oct 10 '18 at 06:05
  • 1
    Id advice against B since there really only one rule that needs to be followed with connection strings:dont put them in source control. search google for -visual studio team services tokenization task- and those top results show you the tokenization approach. – Judy007 Oct 11 '18 at 01:56
  • OK, thanks, we will investigate and try. When we succeed I will mark it as the answer. – Daniël Tulp Oct 12 '18 at 05:53