App.config中改造工作不基于环境

问题描述 投票:0回答:1

我有一个控制台应用程序,我需要单独的app.config的差异。 env中,以使用不同的连接字符串。

我右键点击的App.config - >添加配置变换,得到了两个文件:

App.Debug.config

App.Release.config

这些文件如下:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document- 
Transform">
<connectionStrings>
<add name="SqlCpaConnectionString" 
     connectionString="blahblah" 
     providerName="System.Data.SqlClient"/>
<add name="AzureStorageConnectionString"
     connectionString="blahblah"
     providerName="Microsoft.WindowsAzure.Storage"/>

获得当设置,例如:

ConfigurationManager.ConnectionStrings["AzureStorageConnectionString"].ConnectionString

我得到两个ENVS的空裁判前...

c# .net configuration app-config
1个回答
0
投票

请参阅以下的答案。这也将与控制台应用程序工作:How do I use Web.Config transform on my connection strings?

设置连接字符串变换:

<connectionStrings>
    <add name="local" connectionString="Data Source=IPAddress,Port;Initial Catalog=SomeOtherDB;User ID=TopSecretUsername;Password=SecurePassword" 
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
© www.soinside.com 2019 - 2024. All rights reserved.