MSBuild能否在生成的SetParameters.xml文件中排除“隐藏”的Web Deploy参数?

3
在我的Parameters.xml文件中,我有几个参数使用Web Deploy的“变量”语法来引用其他参数,比如这个参数引用了“IIS Web Application Name”参数:
<parameter name="MyParam"
           defaultValue="{IIS Web Application Name}/Web.config"
           tags="Hidden"/>

我的问题是,当我构建部署包时,尽管参数被标记为隐藏,但VS会自动将该参数导入到我的SetParameters.xml文件中。当通过setParamFile传递给msdeploy时,Web Deploy会直接解释参数的值。

{IIS Web Application Name}/Web.config

与其替换IIS应用程序名称,不如使用该参数。

如果我从自动生成的SetParameters.xml文件中删除该参数,则变量将按预期工作。是否有任何方法可以防止VS首先包含该参数,无论是通过名称还是标记?


你能解释一下为什么你实际上想要包含 {IIS Web Application Name} 宏,这样我们就可以寻找替代方案吗? - kroonwijk
1
"MyParam"被用作setAcl提供程序的参数 - 我们使用它来使Web.config(以及其他几个文件)可写,以便我们的部署时间配置工具可以使用。我之前的一个问题可能有助于解释为什么需要IIS应用程序名称。 - ladenedge
2个回答

1

鉴于我之前的问题的答案,这实际上比我想象的要容易得多。

我只需要在跟随AddIisAndContentDeclareParametersItems的目标中添加一个Hidden标签。这显然会在构建软件包之前将标签设置在源清单中。最终看起来像这样:

<Target Name="DeclareCustomParameters" 
        AfterTargets="AddIisAndContentDeclareParametersItems">
  <ItemGroup>
    <MsDeployDeclareParameters Include="Foo">
      <!-- <snip> -->
      <!-- the following elements are the important ones: -->
      <Tags>Hidden</Tags>  
      <ExcludeFromSetParameter>True</ExcludeFromSetParameter>
    </MsDeployDeclareParameters>
  </ItemGroup>
</Target>

就是这样了!


3
哎呀!希望你没有剪掉我感兴趣的部分!我正在尝试使用MsDeployDeclareParameters语法声明一个“变量”,以便在其他参数中使用... - Peter McEvoy
@PeterMcEvoy:缺失的部分几乎完全匹配Sayed的博客中的片段。在我的情况下,DefaultValue{IIS Web Application Name}/Web.config,当然我匹配的是“Web.config”而不是“Elmah”。 - ladenedge
3
如果您仍然拥有它,将如何实现此目标的完整示例会对我和其他人都很有用。 - Martin
说句实话,游戏晚期我终于成功在 parameters.xml 文件中加入 ExcludeFromSetParameter="True",结果完美运作。或许是有什么变化了? - user2839499

0

这个答案适用于其他寻找更完整的目标替换示例的人。此示例显示将变量“数据库服务器名称”替换为连接字符串。

ExcludeFromSetParameter元素似乎是使替换工作的关键,因为它将参数排除在SetParameters.xml文件之外(正如OP手动提到的那样)。不幸的是,我认为无法从parameters.xml文件中设置ExcludeFromSetParameter,因此这是唯一的选择...

<Target Name="DeclareCustomParameters" BeforeTargets="Package">
    <ItemGroup>

        <MsDeployDeclareParameters Include="DatabaseServer">
            <Description>Location of the database server hosting the user database</Description>
            <Value>localhost</Value>
            <DefaultValue>localhost</DefaultValue>
            <Tags>DBServer, SQL</Tags>
        </MsDeployDeclareParameters>    

        <MsDeployDeclareParameters Include="DB Connection String">
            <Kind>XmlFile</Kind>
            <Scope>Web.config</Scope>
            <Match>/configuration/connectionStrings/add[@name='Database']/@connectionString</Match>
            <Description>The connection string to the Database</Description>
            <DefaultValue>Data Source={DatabaseServer};Initial Catalog=MyDatabase;Integrated Security=true;MultipleActiveResultSets=true;</DefaultValue>
            <Tags>Hidden</Tags>
            <ExcludeFromSetParameter>True</ExcludeFromSetParameter>
        </MsDeployDeclareParameters>

    </ItemGroup>
</Target>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接