发布不是在转换web.config吗?

时间:2021-11-14 20:24:15

I made a web.config (full file, it doesn't show XML errors)

我做了一个网站。配置(完整文件,不显示XML错误)

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <configSections>
      ...
      <location path="." inheritInChildApplications="false">
        <connectionStrings>
          <add name="ElmahLog" connectionString="data source=~/App_Data/Error.db" />
          <add name="database" connectionString="w" providerName="System.Data.EntityClient"/>
        </connectionStrings>
      </location>
  ...

with a transform file (web.Staging.config)

使用转换文件(web. stage .config)

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <connectionStrings>
    <add name="database"
      connectionString="c"
      providerName="System.Data.EntityClient"
      xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
  </connectionStrings>
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
    <customErrors defaultRedirect="error.aspx"
      mode="RemoteOnly" xdt:Transform="Replace">
    </customErrors>
  </system.web>
</configuration>

I am publishing in Staging mode (right click website > Publish > Method: File System ...)

我以分段模式发布(右键点击网站>发布>方法:文件系统…)

------ Build started: Project: Drawing, Configuration: Staging Any CPU ------
  Drawing -> D:\Project\bin\Staging\Drawing.dll
------ Build started: Project: MySystem, Configuration: Staging Any CPU ------
  MySystem -> D:\Project\bin\Staging\MySystem.dll
...

But when I look at the web.config in the output folder it isn't changed.

但是当我看网络的时候。在输出文件夹中设置它不会被更改。

I found the following on the Build log:

我在构建日志中发现了以下内容:

D:\Project\Web.Staging.config(3,2): Warning : No element in the source document matches '/configuration'
D:\Project\Web.Staging.config(3,2): Warning : No element in the source document matches '/configuration'
D:\Project\Web.Staging.config(3,2): Warning : No element in the source document matches '/configuration'
Transformed web.config using Web.Staging.config into obj\Staging\TransformWebConfig\transformed\web.config.

What could be the problem? Am I doing this right?

有什么问题吗?我做得对吗?

5 个解决方案

#1


17  

Answering late but perhaps I can save someone a headache. In Visual Studio 2013, there are two places to select configuration for your build and deploy. The Configuration Manager and then again with Publish Web where the third step in the Wizard entitled Settings allows you to select Config you want to use. If you don't select your new configuration it will use the transform for the selected configuration instead of yours.

回答晚了,但也许我能让人不头痛。在Visual Studio 2013中,有两个地方可以为您的构建和部署选择配置。配置管理器,然后再使用发布Web,向导中的第三个步骤“设置”允许您选择要使用的配置。如果您不选择您的新配置,它将使用所选配置的转换,而不是您的。

#2


16  

I found out two things:

我发现了两件事:

  • You cannot set a namespace on the <configuration> tag (ex: for <location path="." inheritInChildApplications="false">)
  • 您不能在 标记(
  • You have to watch for the correct hierarchy in the transform file.
  • 您必须在转换文件中注意正确的层次结构。

Like

就像

<configuration>
  <location>
    <connectionStrings>

Instead of

而不是

<configuration>
  <connectionStrings>

#3


3  

Ensure that in the properties of the Web.Config file Build Action is set to Content.

确保在Web的属性中。配置文件构建操作设置为Content。

If the build action is set to None, it will not be transformed, even if it is being copied to the output directory.

如果将构建操作设置为None,那么即使将其复制到输出目录,也不会对其进行转换。

#4


0  

Don't forget to copy all the other attributes of "configuration" from the original "web.config", as it seems that VS2012 doesn't do it automatically and of course there will be no match...

不要忘记从原始的“web”中复制“配置”的所有其他属性。配置",好像VS2012没有自动完成,当然也没有匹配…

#5


0  

Answering late as well, but this may help someone.

晚些回答也可以,但这可能对某些人有帮助。

I realized that if you have two websites in the same solution, when you try to publish one of them the transformation might not work if you have one only configuration for both projects.

我意识到,如果在同一个解决方案中有两个网站,当您尝试发布其中一个网站时,如果两个项目只有一个配置,那么转换可能不会成功。

One of my websites was always transforming, but the other sometimes was and sometimes wasn't.

我的一个网站一直在改变,但另一个有时是,有时不是。

For example, I had the configuration "Auto" in the solution, and had web.Auto.config for both websites.

例如,我在解决方案中有配置“Auto”,还有web.Auto。配置两个网站。

I resolved that by creating a new configuration with a different name - "AutoAdmin" - creating also its web.AutoAdmin.config file for the second project, and when I published it again the transformation finally occurred.

我解决了这个问题,通过创建一个具有不同名称的新配置——“AutoAdmin”——也创建了它的web.AutoAdmin。第二个项目的配置文件,当我再次发布它时,最终发生了转换。

#1


17  

Answering late but perhaps I can save someone a headache. In Visual Studio 2013, there are two places to select configuration for your build and deploy. The Configuration Manager and then again with Publish Web where the third step in the Wizard entitled Settings allows you to select Config you want to use. If you don't select your new configuration it will use the transform for the selected configuration instead of yours.

回答晚了,但也许我能让人不头痛。在Visual Studio 2013中,有两个地方可以为您的构建和部署选择配置。配置管理器,然后再使用发布Web,向导中的第三个步骤“设置”允许您选择要使用的配置。如果您不选择您的新配置,它将使用所选配置的转换,而不是您的。

#2


16  

I found out two things:

我发现了两件事:

  • You cannot set a namespace on the <configuration> tag (ex: for <location path="." inheritInChildApplications="false">)
  • 您不能在 标记(
  • You have to watch for the correct hierarchy in the transform file.
  • 您必须在转换文件中注意正确的层次结构。

Like

就像

<configuration>
  <location>
    <connectionStrings>

Instead of

而不是

<configuration>
  <connectionStrings>

#3


3  

Ensure that in the properties of the Web.Config file Build Action is set to Content.

确保在Web的属性中。配置文件构建操作设置为Content。

If the build action is set to None, it will not be transformed, even if it is being copied to the output directory.

如果将构建操作设置为None,那么即使将其复制到输出目录,也不会对其进行转换。

#4


0  

Don't forget to copy all the other attributes of "configuration" from the original "web.config", as it seems that VS2012 doesn't do it automatically and of course there will be no match...

不要忘记从原始的“web”中复制“配置”的所有其他属性。配置",好像VS2012没有自动完成,当然也没有匹配…

#5


0  

Answering late as well, but this may help someone.

晚些回答也可以,但这可能对某些人有帮助。

I realized that if you have two websites in the same solution, when you try to publish one of them the transformation might not work if you have one only configuration for both projects.

我意识到,如果在同一个解决方案中有两个网站,当您尝试发布其中一个网站时,如果两个项目只有一个配置,那么转换可能不会成功。

One of my websites was always transforming, but the other sometimes was and sometimes wasn't.

我的一个网站一直在改变,但另一个有时是,有时不是。

For example, I had the configuration "Auto" in the solution, and had web.Auto.config for both websites.

例如,我在解决方案中有配置“Auto”,还有web.Auto。配置两个网站。

I resolved that by creating a new configuration with a different name - "AutoAdmin" - creating also its web.AutoAdmin.config file for the second project, and when I published it again the transformation finally occurred.

我解决了这个问题,通过创建一个具有不同名称的新配置——“AutoAdmin”——也创建了它的web.AutoAdmin。第二个项目的配置文件,当我再次发布它时,最终发生了转换。