【问题标题】:How to use .NET Web Deployment Projects to REMOVE a web.config section如何使用 .NET Web 部署项目删除 web.config 部分
【发布时间】:2013-09-16 23:02:05
【问题描述】:

我使用 Web 部署项目来构建我的发布包并替换我的 web.config 文件的特定部分。我使用用于调试的值配置原始 web.config 文件,例如 AppSettings。然后我有一个名为 AppSettings.Release.config 的文件,我使用以下内容构建发布包:

<ItemGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
    <WebConfigReplacementFiles Include="Config\AppSettings.Release.config">
        <Section>appSettings</Section>
    </WebConfigReplacementFiles>
    <WebConfigReplacementFiles Include="Config\Compilation.Release.config">
        <Section>system.web/compilation</Section>
    </WebConfigReplacementFiles>
    <WebConfigReplacementFiles Include="Config\CustomErrors.Release.config">
        <Section>system.web/customErrors</Section>
    </WebConfigReplacementFiles>
</ItemGroup>

我还指定了一个用于调试的连接字符串:

<connectionStrings>
    <add name="SQLConnectionString"
         connectionString="Server=[server name]Database=[database name];Integrated Security=SSPI;" />
</connectionStrings>

我正在迁移到 Windows Azure,我想使用门户界面来管理我的连接字符串 - 而不是 web.config 文件。因此,在门户中,我在名为“SQLConnectionString”的连接字符串下为我的网站添加了一个条目,其中包含正确的生产字符串。

我的问题是,我想使用部署项目从我的 web.config 文件中完全删除 &lt;connectionStrings&gt; 元素。我该怎么做?

注意:我尝试简单地用空元素替换部分,但出现以下错误:

web.config(25):错误 WDP00001:“web.config”中的部分 connectionStrings 有 1 个元素,但“Config\ConnectionStrings.Release.config”有 0 个元素。

谢谢!

【问题讨论】:

    标签: asp.net azure web-config web-deployment


    【解决方案1】:

    不知道你有没有查看过官方MSDN docmentation here。以及您是否在 connectionstrings.release.config 中尝试过以下操作:

    <connectionStrings>
        <add xdt:Transform="RemoveAll" />
    </connectionStrings>
    

    根据文档,这必须删除所有条目。

    【讨论】:

    • 我没有使用 web.config 转换。我在 Web 部署项目中使用了另一种方法。 XML 转换是通过自动合并多个 web.config 文件来完成的。
    • 我不熟悉你在说什么,或者没有适当的参考就无法进入我的脑海。但是我敢肯定,如果您深入研究有关您使用的方法的文档,您会发现类似的东西!
    猜你喜欢
    • 2012-04-08
    • 2013-06-13
    • 2010-11-20
    • 1970-01-01
    • 2014-05-26
    • 2020-02-02
    • 1970-01-01
    • 2023-03-23
    • 2011-03-22
    相关资源
    最近更新 更多