Web.config中构建VS发行变换不工作 [英] Web.config Build vs Release transform not working

查看:166
本文介绍了Web.config中构建VS发行变换不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个连接到通过实体框架远程数据库的ASP.NET Web应用程序项目。在调试过程中(如运行我的本地计算机上的项目),IP地址的数据库比发布期间不同(如项目上传到我的网络服务器和浏览器中运行它之后)。到现在为止我一直手动更改数据库连接字符串在Web.config文件,以两者之间(基本上我不得不连接字符串切换,一只叫'调试'和一个'释放',我就在换名字,每当我部署)。

现在我只注意到它应该有可能让这个通过 Web.config文件转换语法你把修改后的连接字符串中的Web.Release.config版本,那么它应该使用,当DLL被下释放配置建造的。

但它似乎并没有为我工作...

下面是我经常Web.config文件中的相关部分(持有本地使用调试连接字符串):

 <?XML版本=1.0&GT?;
<结构>  <&是connectionStrings GT;
    <! - 调试连接字符串。释放连接字符串是Web.Release.config文件 - >
    <添加名称=DatabaseEntities的connectionString =A的providerName =System.Data.EntityClient/>
  < /&是connectionStrings GT;< /结构>

下面是Web.Release.config文件,该文件根据实例应该以B代替DatabaseEntities连接字符串A如果DLL是下释放模式:

 <?XML版本=1.0&GT?;
<结构的xmlns:XDT =htt​​p://schemas.microsoft.com/XML-Document-Transform>  <! - 替换发行版的DatabaseEntities连接字符串(本地IP地址) - GT;
  <&是connectionStrings GT;
    <添加名称=DatabaseEntities
      的connectionString =B的
      XDT:转换=替换XDT:定位器=匹配(名称)/>
  < /&是connectionStrings GT;< /结构>

(显然,A和B都只是占位符,以我的真实的连接字符串)

当我调试应用程序(例如刚刚preSS F5)默认的Web.config使用,我可以访问数据库。然后,我改变构建配置通过Configuration Manager发布。在解决方案中的所有项目都设置为Release配置。然后,我生成解决方案(只是通过构建,甚至通过一个完整的重建(例如清洁,重建))。我上传新建的DLL到web服务器,以及在Web.config和Web.Release.config文件,当我尝试访问我无力的数据库,它仍在试图通过调试IP地址来访问数据库因此不能找到它...

看来Web.Release.config文件被完全忽略,或至少在连接字符串不被取代。

我是什么做错了吗?是转换语法错了吗?我不能建立正确下发布模式的应用程序?

感谢您的帮助...


解决方案

  

然后我(只是通过构建,甚至通过一个完整的生成解决方案
  重建(例如清洁,重建))。我上传新建的DLL到
  Web服务器,以及在Web.config和Web.Release.config文件


有是你的错误:Web配置转换不会为你的本地环境中工作,如果你只是建立。您需要发布。

您的部署过程似乎不可思议:你只复制DLL文件,Web.config文件和web.Release.config。对我来说,似乎,你复制你的源$ C ​​$ C,而不是一个编译的应用程序。已发布的WebApplication不包含web.release.config。

您应该发布项目。(在你的WebApplication单击鼠标右键 - >发布)到本地文件系统,文件从那里复制,或使用您选择的另一个部署方法

2年前我写的web.config变换的文章。它给你一步一步的教程VS 2010(发布对话框中的VS 2012更改):<一href=\"http://www.tomot.de/en-us/article/5/asp.net/how-to-use-web.config-transforms-to-replace-appsettings-and-connectionstrings\">http://www.tomot.de/en-us/article/5/asp.net/how-to-use-web.config-transforms-to-replace-appsettings-and-connectionstrings

I have an ASP.NET Web Application project that connects to a remote database via the Entity Framework. During debugging (eg running the project on my local computer), the IP address to the database is different than during release (eg after uploading the project to my webserver and running it from the browser). Until now I have always manually changed the database connection string in the Web.config file to switch between the two (basically I had to connection strings, one named 'Debug' and one 'Release' and I just swapped around the names whenever I deployed).

Now I just noticed that it should be possible to let this happen automatically via the Web.config Transformation Syntax where you put the modified connection string in the Web.Release.config version and it should then use that when the DLL is built under Release configuration.

However it does not seem to work for me...

Here is the relevant part of my regular Web.config file (which holds the Debug connection string for local usage):

<?xml version="1.0"?>
<configuration>

  <connectionStrings>
    <!-- Debug connection string. Release connection string is in Web.Release.config file -->
    <add name="DatabaseEntities" connectionString="A" providerName="System.Data.EntityClient" />
  </connectionStrings>

</configuration>

Here is the Web.Release.config file, which according to the examples should replace the 'DatabaseEntities' connection string "A" with "B" if the DLL is under Release mode:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

  <!-- Replace the DatabaseEntities connection string with the Release version (local IP address) -->
  <connectionStrings>
    <add name="DatabaseEntities"
      connectionString="B"
      xdt:Transform="Replace" xdt:Locator="Match(name)"/>
  </connectionStrings>

</configuration>

(Obviously "A" and "B" are just place-holders for my real connection strings)

When I debug the application (e.g. just press F5) the default Web.config is used and I can access the database. I then change the build configuration to Release via the Configuration Manager. All the projects in the solution are set to Release configuration. Then I Build the solution (just via Build or even via a complete rebuild (e.g. Clean, Rebuild)). I upload the newly built DLLs to the webserver, as well as the Web.config and Web.Release.config files, and when I try to access the database I am unable, it is still trying to access the database via the debug IP address and hence cannot find it...

It seems the Web.Release.config file is completely ignored, or at least the connection string is not being replaced.

What am I doing wrong? Is the transformation syntax wrong? Am I not building the application under Release mode correctly?

Thanks for any help...

解决方案

Then I Build the solution (just via Build or even via a complete rebuild (e.g. Clean, Rebuild)). I upload the newly built DLLs to the webserver, as well as the Web.config and Web.Release.config files

There is your error: Web config transforms won't work for your local environment, if you simply build. You need to publish.

Your deployment process seems weird: You are only copying DLLs, Web.config and web.Release.config. To me it seems, that you copy your source code and not a compiled application. A published WebApplication doesn't contain a web.release.config.

You should publish your project (rightclick on your WebApplication -> Publish) to your local filesystem and copy the files from there, or use another deployment method of your choice.

2 years ago I wrote an article about web.config transforms. It gives you a step-by-step tutorial for VS 2010 (The publish dialog changed in VS 2012): http://www.tomot.de/en-us/article/5/asp.net/how-to-use-web.config-transforms-to-replace-appsettings-and-connectionstrings

这篇关于Web.config中构建VS发行变换不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆