Visual Studio project configuration & environment

Viewed 48

Thing I'm not getting here is very general, how do the configurations in Visual Studio projects work?

For each project there exists this launchSettings.json file which contains different logs/configurations. Each of these has its own Profile, Launch environment variables and other items.

1) Production

During app development it was necessary to create a different connection string since the production version of the app was being deployed to Azure.

I created corresponding connection string in appsettings.Production.json and my colleague helped me and set up the environmental variable ASPNETCORE_ENVIRONMENT = Production for me.

This is the configuration from launchSettings.json it created:

"SebastiansCookbook": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Production"
      },
      "dotnetRunMessages": "true",
      "applicationUrl": "https://localhost:5001;http://localhost:5000"
    },

Why is the Profile equal to "SebastiansCookbook" and not "ISS Express" or "Docker"? - SebastiansCookbook is name the solution, does this relate to more projects (whole solution) being built at once?

Why is the Launch equal to "Project" and not one of {"ISS", "ISS Express", "Snapshot Debugger", "Docker", "Executable"} - in fact, what are those anyways?

2) Testing environment

When creating tests for the application (in separate project referencing the WebApi project)

I had a problem that I believe originated from my lack of understanding of the topic of the first part of this post.

I had to create another connection string for the HttpClient I used for the tests. Following the practice of file per environment, I created appsettings.Testing.json file and put the connection string there.

The problem I encountered was "How to force the WebApplicationBuilder to use this appsettings file". And even tho the solution is relatively simple and already presented in the following thread: Set environment in integration tests I still have a question.

What I wanted to do before I was recommended this solution was to create new "configuration" for the WebApi project. I thought that if I specified the environmental variable ASPNETCORE_ENVIRONMENT = Testing I will have succeeded. There are couple of points before my question:

  1. I haven't thought about how would I make the WebApi project to use this configuration from the Testing project...
  2. I couldn't understand how would I even create the configuration - I thought as much as that if I were to create the configuration for the same Profile and Launch but with a different value to the environmental variable ASPNETCORE_ENVIRONMENT there would be a conflict

So my idea here was to use different Profile or at least Launch but since I didn't understand their meaning I couldn't. (Here actually came the question of forcing the project to use a configuration...)

Now to the question: Is it possible to set a project to use a configuration from another project? Is it also possible to somehow create another configuration like I wanted to do?

0 Answers
Related