web.debug.config转换不起作用

rwk*_*iii 5 iis visual-studio web.config-transform

我不知道我做错了什么,但我几乎觉得我已经尝试了一切.我似乎无法通过web.debug.config更改来获取我的项目的web.config.我在某处读到只有在发布时才进行转换.然后我读到SlowCheetah可以处理这个,所以我把它安装到我的项目中.它也没有任何区别.

运行VS 2012 Express.我使用VS安装的IIS Express本地服务器进行调试.我运行Firefox作为我的浏览器.

web.config中:

<appSettings>
  <add key="SiteUrl" value="http://development.mysite.com/" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)

web.debug.config:

<appSettings>
  <add key="SiteUrl" value="http://localhost:4652/"
      xdt:Transform="SetAttributes"
      xdt:Locator="Match(key)" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)

我也尝试过使用Replace:

<appSettings>
  <add key="SiteUrl" value="http://localhost:4652/"
      xdt:Transform="Replace"
      xdt:Locator="Match(key)" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)

在本地调试配置中运行时:

string siteurl = ConfigurationManager.AppSettings["SiteUrl"];
Run Code Online (Sandbox Code Playgroud)

仍然导致siteurl http://development.mysite.com/

我通过右键单击web.debug.config来运行预览转换,它显示转换完美,但不是我在本地运行Web应用程序时.

不得不承认,我没有看到如何配置SlowCheetah.我没有看到任何配置它的方法,我一直在想也许它本身就有"某些东西".:S

有谁知道如何克服这一点,或者我可能做错了什么?

Jer*_*ook 0

我建议暂时忽略慢速猎豹,因为我认为你不需要它。我已将其用于 Windows 窗体开发,但不需要进行 Web 开发。相反,请使用标准的一键式 Web 部署机制,并重新考虑如何使用配置转换。

基本上,仅在发布时使用转换,并将本地开发设置放在主 Web.config 中而不是转换中。

  1. 然后,如果您有一个实验室/测试/沙箱环境,您希望发布该环境以创建解决方案和项目配置。

在配置管理器中添加新的解决方案配置

  1. 接下来,右键单击 Web.config,然后单击添加配置转换,为刚刚创建的解决方案配置添加配置转换。

添加配置转换

  1. 假设您添加了“沙盒”解决方案配置。如果是这种情况,那么解决方案资源管理器中将出现一个名为 Web.Sandbox.config 的新文件。继续更新 Web.config 和 Web.Sandbox.config 中的值,如下所示。

网页配置:

<appSettings>
  <add key="SiteUrl" value="http://localhost:4652/" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)

Web.Sandbox.config:

<appSettings>
  <add key="SiteUrl" value="http://sandbox.mysite.com/"
      xdt:Transform="SetAttributes"
      xdt:Locator="Match(key)" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)
  1. 最后,您需要创建一个“sandbox.mysite.com”(或您的 URL 的实际名称)发布配置文件,并确保其配置是 Sandbox,以便在发布期间使用 Web.Sandbox.config 转换。

在“发布 Web”对话框中选择沙盒配置