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.
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:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.