Web.Debug.config 未将连接字符串转换为 MVC 5 项目中的 Web.config
Web.Debug.config is NOT transforming the connectionstrings to the Web.config in MVC 5 projects
我创建了一个新的 VS 2015 Web 项目 MVC5。默认情况下,我可以看到 Web.config 和 Web.Debug.config
阅读了几篇文章,我真的不知道我真正需要做什么才能让它从 Web.Debug.config 中获取我的值并替换当前的 Web.config。
我一直在研究另一个工作中的项目,它可以做到这一点并且工作正常,但我已经完成了很多属性和设置,但我看不出有什么不同。
我可以右键单击 Web.Debug.config 和预览,它会显示它将 "test" 替换为“10.10.10.10”,所以我觉得它不错(它应该可以工作,但是 运行ning 项目它不会更改值)
示例
项目:
调试/任何CPU,运行 google chrome,问题是数据源没有改变
Web.Debug.config
<connectionStrings>
<add name="Envy" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=myDB;user id=myLoginID;password=password" providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
<add name="EnvyIdentity" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=myDB;user id=myLoginID;password=password" providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
<add name="DNNSmartstore" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=myDB;user id=myLoginID;password=password" providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
<add name="DNNPos" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=DevFood_POS;user id=myLoginID;password=password" providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
Web.config
<connectionStrings>
<add name="Envy" connectionString="Data Source=test\MSSQLSERVER2014;Initial Catalog=myDB;user id=myLoginID;password=password" providerName="System.Data.SqlClient"/>
<add name="EnvyIdentity" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=myDB;user id=myLoginID;password=password" providerName="System.Data.SqlClient"/>
<add name="DNNSmartstore" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=myDB;user id=myLoginID;password=password" providerName="System.Data.SqlClient"/>
<add name="DNNPos" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=DevFood_POS;user id=myLoginID;password=password" providerName="System.Data.SqlClient"/>
</connectionStrings>
开箱即用,转换 (debug/release) 应用于 发布(部署)。不是构建,而是部署。
要在构建时实现这一点,您可能需要对项目文件进行一些手动编辑。看看这里例如:https://gist.github.com/EdCharbeneau/9135216
如此接近,但 倒退。对于这种情况,仅使用 Web.config 和 Web.Release.config。
将您所有的 Debug 设置放入 Web.config,将您的 Release 设置放入 Web.Release.config,然后执行不要使用 Web.Debug.config。将使用常规 Web.config 进行调试,只有已发布的构建才会获得发布设置。
从你上面的例子:
Web.config
<!-- test/debug settings in regular web.config -->
<connectionStrings>
<add name="Envy" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=myDB;user id=myLoginID;password=password" providerName="System.Data.SqlClient"/>
<add name="EnvyIdentity" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=myDB;user id=myLoginID;password=password" providerName="System.Data.SqlClient"/>
<add name="DNNSmartstore" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=myDB;user id=myLoginID;password=password" providerName="System.Data.SqlClient"/>
<add name="DNNPos" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=DevFood_POS;user id=myLoginID;password=password" providerName="System.Data.SqlClient"/>
</connectionStrings>
Web.Release.config
<connectionStrings>
<add name="Envy" connectionString="Data Source=test\MSSQLSERVER2014;Initial Catalog=myDB;user id=myLoginID;password=password" providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
<add name="EnvyIdentity" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=myDB;user id=myLoginID;password=password" providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
<add name="DNNSmartstore" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=myDB;user id=myLoginID;password=password" providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
<add name="DNNPos" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=DevFood_POS;user id=myLoginID;password=password" providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
Web.Debug.config 是放置要在部署到测试服务器时应用的设置的地方。这个名字起初很容易误导。我唯一使用过此功能的地方是如果我有一个测试服务器需要与我的开发箱不同的设置。 :-)
我创建了一个新的 VS 2015 Web 项目 MVC5。默认情况下,我可以看到 Web.config 和 Web.Debug.config
阅读了几篇文章,我真的不知道我真正需要做什么才能让它从 Web.Debug.config 中获取我的值并替换当前的 Web.config。
我一直在研究另一个工作中的项目,它可以做到这一点并且工作正常,但我已经完成了很多属性和设置,但我看不出有什么不同。
我可以右键单击 Web.Debug.config 和预览,它会显示它将 "test" 替换为“10.10.10.10”,所以我觉得它不错(它应该可以工作,但是 运行ning 项目它不会更改值)
示例
项目:
调试/任何CPU,运行 google chrome,问题是数据源没有改变
Web.Debug.config
<connectionStrings>
<add name="Envy" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=myDB;user id=myLoginID;password=password" providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
<add name="EnvyIdentity" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=myDB;user id=myLoginID;password=password" providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
<add name="DNNSmartstore" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=myDB;user id=myLoginID;password=password" providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
<add name="DNNPos" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=DevFood_POS;user id=myLoginID;password=password" providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
Web.config
<connectionStrings>
<add name="Envy" connectionString="Data Source=test\MSSQLSERVER2014;Initial Catalog=myDB;user id=myLoginID;password=password" providerName="System.Data.SqlClient"/>
<add name="EnvyIdentity" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=myDB;user id=myLoginID;password=password" providerName="System.Data.SqlClient"/>
<add name="DNNSmartstore" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=myDB;user id=myLoginID;password=password" providerName="System.Data.SqlClient"/>
<add name="DNNPos" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=DevFood_POS;user id=myLoginID;password=password" providerName="System.Data.SqlClient"/>
</connectionStrings>
开箱即用,转换 (debug/release) 应用于 发布(部署)。不是构建,而是部署。
要在构建时实现这一点,您可能需要对项目文件进行一些手动编辑。看看这里例如:https://gist.github.com/EdCharbeneau/9135216
如此接近,但 倒退。对于这种情况,仅使用 Web.config 和 Web.Release.config。
将您所有的 Debug 设置放入 Web.config,将您的 Release 设置放入 Web.Release.config,然后执行不要使用 Web.Debug.config。将使用常规 Web.config 进行调试,只有已发布的构建才会获得发布设置。
从你上面的例子:
Web.config
<!-- test/debug settings in regular web.config -->
<connectionStrings>
<add name="Envy" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=myDB;user id=myLoginID;password=password" providerName="System.Data.SqlClient"/>
<add name="EnvyIdentity" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=myDB;user id=myLoginID;password=password" providerName="System.Data.SqlClient"/>
<add name="DNNSmartstore" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=myDB;user id=myLoginID;password=password" providerName="System.Data.SqlClient"/>
<add name="DNNPos" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=DevFood_POS;user id=myLoginID;password=password" providerName="System.Data.SqlClient"/>
</connectionStrings>
Web.Release.config
<connectionStrings>
<add name="Envy" connectionString="Data Source=test\MSSQLSERVER2014;Initial Catalog=myDB;user id=myLoginID;password=password" providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
<add name="EnvyIdentity" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=myDB;user id=myLoginID;password=password" providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
<add name="DNNSmartstore" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=myDB;user id=myLoginID;password=password" providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
<add name="DNNPos" connectionString="Data Source=10.10.10.10\MSSQLSERVER2014;Initial Catalog=DevFood_POS;user id=myLoginID;password=password" providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
Web.Debug.config 是放置要在部署到测试服务器时应用的设置的地方。这个名字起初很容易误导。我唯一使用过此功能的地方是如果我有一个测试服务器需要与我的开发箱不同的设置。 :-)