0

I have this solution structure:

  • AppOne.Account
  • AppOne.Admin
  • AppOne.System
  • AppOne.Data
  • AppOne.ClassLibrary

AppOne.Account, AppOne.Admin and AppOne.System are ASP.NET Core Application Projects. The rest are libraries.

Currently I have to manually copy and paste the same web.config file to each of them when I deploy and even in development, I have to copy and paste the launchSettings.json file as it contains their environment variables that I need.

Is it possible to store the web.config or launchSettings.json file in a folder and then reference it in my Startup.cs.

I am thinking of storing it in a Solution folder and then reading the in. However, I am unsure if that is possible and I am also unsure of where to read it from.

Stoner
  • 846
  • 1
  • 10
  • 30
JianYA
  • 2,750
  • 8
  • 60
  • 136
  • https://stackoverflow.com/a/11535980/495455 – Jeremy Thompson Sep 26 '19 at 02:44
  • I have just read through that. I kind of understand it but where do I reference the web.config file in my other folder? Do I need to add code in or is a reference enough? – JianYA Sep 26 '19 at 02:51
  • You don't "reference" the web.config. You put the app/web.config file in the project (or a short cut to the single Config file that actually lives in another folder). Then in code you use `ConfigurationManager.AppSetting...` and that will look for the config file in the **running project**. It's context based. If you are running the main project it'll look at the main project for the config, if you're running a Unit Test project then it'll expect a config file (or a shortcut) lives in the root of the unit testing project. – Jeremy Thompson Sep 26 '19 at 04:19

1 Answers1

0

You don't "reference" the web.config. You put the app/web.config file in the project (or a short cut to the single Config file that actually lives in another folder).

Then in code you use ConfigurationManager.AppSetting... and that will look for the config file in the running project. It's context based.

If you are running the main project it'll look at the main project for the config, if you're running a Unit Test project then it'll expect a config file (or a shortcut) lives in the root of the unit testing project.

A nifty solution is adding config file shortcuts in other projects so you only update one file:

enter image description here

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321