发布时不会转换Web.config

时间:2018-03-21 05:40:50

标签: c# visual-studio visual-studio-2015 app-config slowcheetah

我正在尝试在我的一个C#项目中应用配置转换。我可以看到在我做的时候应用了转换"预览转换"在我的QA配置文件上但是当我使用QA配置文件发布时,我仍然可以在部署中看到默认配置(而不是已转换的配置)。我不希望构建转换(我知道slowcheetah有帮助),我只需要发布。我们是否需要在.csproj文件中进行任何更改以启用发布转换。

编辑:通过gkb添加示例配置请求。 我们在web.config中有条目:

    <section class="pb8" id="name">
        <div class="container">
            <div class="row">


                <div class="col-md-3 col-sm-6">
                    <div class="image-tile outer-title text-center">
                        <img alt="Pic" src="source/to/img.jpg">
                        <div class="title mb16">
                            <h5 class="uppercase mb0">Title</h5>
                            <span>Subtitle</span>
                        </div>
                        <p class="lead" style="text-align: justify">
                            Some Text Some Text Some Text Some Text
                        </p>
                    </div>
                </div>


            </div>
        </div>
    </section>

我在我的网站下面.Debug-QA.config:

<connectionStrings>
        <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\xxxx.mdf;Initial Catalog=xxxx;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>

1 个答案:

答案 0 :(得分:0)

在我们的项目中,我们有两个不同的步骤:

  1. 使用慢速猎豹进行转换
    (我知道你写道你不想使用它但是试一试)
  2. 在构建时,我们在配置中创建令牌。 app.release 文件如下所示:

    <?xml version="1.0"?>
    <!-- For more information on using app.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
    <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
      <appSettings>
        <add key="InstrumentationKey" value="__InstrumentationKey__" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
      </appSettings>
    </configuration>
    

    E.g。在发布版本之后,我们的app配置如下所示:

    <configuration>
        <appSettings>
            <add key="InstrumentationKey" value="__InstrumentationKey__" />
        </appSettings>
    </configuration>
    
    1. 发布时间时间我们为每个特定环境替换令牌
    2. 我不知道你的发布过程......但在我们的例子中,我们有一个每个环境的替换列表。

      当我们发布时,所有令牌(具有两个下划线的人)都会被每个环境的特定值替换。