本文介绍了是否有可能覆盖一个Local.config文件两者的appSettings和是connectionStrings?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们presently从我们的web.config覆盖的appSettings 为每个开发者Local.config文件。然而,我们还需要重写连接字符串,所以我们进入我们的机器上的本地副本,同时在web.config可能引用生产服务器。我知道,你可以通过指定文件=Local.config覆盖的appSettings,但是这是可能的是connectionStrings呢?我们已经利用一个外部文件的连接字符串,但这个文件有三个连接字符串(当地开发商,开发和生产)。

We presently override appSettings from our web.config in a Local.config file for each developer. However we also need to override connection strings, so we access our local copy on our machine while the web.config might reference the production server. I know that you can override appSettings by specifying file="Local.config", but is this possible for the connectionStrings as well? We already make use of an external file for the connection strings but this file has all three connection strings (local developer, dev, and production).

我想要做的是有默认的connectionString生产,但覆盖的开发人员的机器上并在开发服务器上。不过,这似乎并不可能的,因为不同的appSettings,当你告诉它使用一个外部文件,你不能指定一个是connectionStrings值。

What I'd like to do is have the connectionString defaulted to production, but overridden on a developer's machine and on the development server. However, this doesn't seem to be possible as unlike appSettings, you can't specify a value for connectionStrings when you tell it to use an external file.

这是有可能实现,而无需添加额外的code?

Is this possible to achieve without having to add additional code?

我要指出,我的不能使用配置转换的时刻,因为我们是在ASP.NET 3.5。

I should note that I cannot use the Config Transformations at the moment as we are on ASP.NET 3.5.

推荐答案

在主应用程序配置文件,您可以使用configSource属性来指定完全合格的名称和外部文件的位置。此例是外部命名connections.config配置文件。

In the main application configuration file, you use the configSource attribute to specify the fully qualified name and location of the external file. This example refers to an external configuration file named connections.config.

<?xml version='1.0' encoding='utf-8'?>
<configuration>
    <connectionStrings configSource="connections.config"/>
</configuration>

有关详细信息,请访问在MSDN(节:使用外部配置文件)

For detailed information, please visit this link on msdn (section: Using External Configuration Files)

这篇关于是否有可能覆盖一个Local.config文件两者的appSettings和是connectionStrings?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 06:55