質問

I can see that Web.config file contains two files:

-web.Debug.config
-web.Release.config

Inside this config files there is the following comment:

In the example below, the "SetAttributes" transform will change the value of "connectionString" to use "ReleaseSQLServer" only when the "Match" locator finds an atrribute "name" that has a value of "MyDB".

<connectionStrings>
  <add name="MyDB" 
    connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" 
    xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>

What is the "Match" locator ? I already have a connection String in Web.config So how do I set this up? should the main web.config file contain the production connection string or the other way around? I'm looking for adivices from people that have done similar things

役に立ちましたか?

解決

We are using xdt:Transform="Replace" which basically replaces the connection string of our development DB and it works perfectly. See below:

Development connection string (in your case web.Debug.config):

<connectionStrings>
  <add name="MyDB" connectionString="Data Source=DebugSQLServer;Initial Catalog=MyDebugDB;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>

Production connection string (in your case web.Release.config):

<connectionStrings xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <add name="MyDB" connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" xdt:Transform="Replace" xdt:Locator="Match(name)" />
</connectionStrings>

他のヒント

Match(name) means that the name of the connectionString in your case MyDB if it is same as in web.config that it will set the connectionString attributes to what you have in your web.debug.config file's connectionString when you publish the website. A complete documentation can be found at MSDN. And a basic how to do can be found here.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top