简体   繁体   English

在asp.net核心中的app.config部署

[英]app.config deployement in asp.net core

In my ASP.NET Core web app, I use a .NET framework library doing ODBC work. 在我的ASP.NET Core Web应用程序中,我使用.NET框架库来完成ODBC工作。

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 我发现我可以拥有一个app.config文件并读取这样的参数

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. 我的问题是我的项目中的app.config文件随每个部署都包含在PROJECTNAME.exe.config中。 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. 文件本身不是用这种方式复制的,但仍包含在exe.config中。

Any suggestions? 有什么建议么?

Pieter 彼得

I think one solution could be to use your appsettings.json file rather than an app.config. 我认为一种解决方案可能是使用您的appsettings.json文件而不是app.config。 You can create additional sub-files like appsettings.Development.json and appsettings.Production.json which can contain environment-specific settings. 您可以创建其他子文件,例如appsettings.Development.json和appsettings.Production.json,其中可以包含特定于环境的设置。 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 更多信息: https : //docs.microsoft.com/zh-cn/aspnet/core/fundamentals/configuration

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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