Publish 不是改造 web.config 吗?

发布于 2024-10-26 04:55:46 字数 2232 浏览 4 评论 0原文

我制作了一个 web.config完整文件,它不显示 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>
  ...

与转换文件 (web.Staging.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>

我正在 Staging 模式下发布(右键单击网站 > 发布 > 方法:文件系统 ...)

------ 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
...

但是当我查看输出文件夹中的 web.config 时,它并没有改变。

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

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.

可能是什么问题?我这样做对吗?

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

<?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)

<?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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

灼疼热情 2024-11-02 04:55:46

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

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.

霊感 2024-11-02 04:55:46

我发现了两件事:

  • 您无法在 标记上设置命名空间(例如:对于 )
  • 您必须注意转换文件中的正确层次结构。

喜欢

<configuration>
  <location>
    <connectionStrings>

而不是

<configuration>
  <connectionStrings>

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>
你怎么这么可爱啊 2024-11-02 04:55:46

确保在 Web.Config 文件的属性中将 Build Action 设置为 Content

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

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

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

眼泪都笑了 2024-11-02 04:55:46

如果您尝试添加的部分尚未出现在输出中,请确保包含 InsertIfMissing

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

      <security xdt:Transform="InsertIfMissing">
        <requestFiltering allowDoubleEscaping="true" />
      </security>

    </system.webServer>
  </location>
</configuration>

Make sure to include InsertIfMissing if the section you are trying to add does not already appear in the output.

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

      <security xdt:Transform="InsertIfMissing">
        <requestFiltering allowDoubleEscaping="true" />
      </security>

    </system.webServer>
  </location>
</configuration>
阪姬 2024-11-02 04:55:46

不要忘记从原始的“web.config”中复制“configuration”的所有其他属性,因为VS2012似乎不会自动执行此操作,当然不会匹配...

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...

柠檬心 2024-11-02 04:55:46

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

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

我的一个网站总是在变化,但另一个网站有时会变化,有时则不会。

例如,我在解决方案中具有“自动”配置,并且两个网站都有 web.Auto.config 。

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

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.

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.

雪化雨蝶 2024-11-02 04:55:46

我按照以下步骤解决了这个问题。谢谢@michaelhawkins 指出正确的方向。您需要确保更改配置以在两个位置发布。

输入图片此处描述

右键单击​​您的项目并选择“属性”。如果不起作用,请尝试在 CPU 架构中选择 x86

在此处输入图像描述

I followed the below steps to fix this issue. Thanks, @michaelhawkins for pointing in the right direction. You need to make sure you change the configuration to release in two places.

enter image description here

And right click on your project and select "Properties". IF not working try selecting x86 in CPU Architecture

enter image description here

姐不稀罕 2024-11-02 04:55:46

@Karthikeyan VK 你的帖子解决了我的问题。尽管我在发布配置文件中选择了生产配置,但在配置管理器中它被设置为 dev,因此它没有改变我的设置。

微软需要修复这个错误。一旦您在发布配置文件中选择了配置,它也会自动更新配置管理器。

@Karthikeyan VK your post resolved my issue. Although I was selecting Production configuration in my publish profile, in configuration manager it was set to dev therefore It didn't transform my settings.

Microsoft needs to fix this bug. Once you pick a configuration in the publishing profile it should automatically update the configuration manager as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文