简体   繁体   中英

app.config deployement in asp.net core

In my ASP.NET Core web app, I use a .NET framework library doing ODBC work.

So I need to have some configuration parameters that I can read from static methods in that library.

I found that I can have an app.config file and read the parameters like this

public class Config
{
     public static string siteLanguage = ConfigurationManager.AppSettings["siteLanguage"];
}

This allows me to call the setting from a static method.

My problem is that the app.config file in my project, gets included in the PROJECTNAME.exe.config with every deployment. So it seems impossible to have different files per site. I have specified Build Action: None, and Do Not Copy. The file itself is not copied that way, but still included in the exe.config.

Any suggestions?

Pieter

I think one solution could be to use your appsettings.json file rather than an app.config. You can create additional sub-files like appsettings.Development.json and appsettings.Production.json which can contain environment-specific settings. You could possibly do something like below in one of these files:

{
    "siteLanguage": "en"
}

More Info: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM