MSBuild 可以排除“隐藏”吗?生成的 SetParameters.xml 中的 Web 部署参数?

发布于 2024-12-06 22:43:21 字数 620 浏览 0 评论 0原文

在我的 Parameters.xml 文件中,我有几个参数使用 Web 部署“变量”语法来引用其他参数,例如引用 IIS Web 应用程序名称< /code> 参数:

<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 首先通过名称或标签包含该参数?

In my Parameters.xml file, I have a couple of parameters that use the Web Deploy "variable" syntax to refer to other parameters, like this one that refers to the IIS Web Application Name parameter:

<parameter name="MyParam"
           defaultValue="{IIS Web Application Name}/Web.config"
           tags="Hidden"/>

My problem is that VS automatically imports this parameter into my SetParameters.xml file when I build the deployment package in spite of it being tagged as hidden. When it is passed to msdeploy via setParamFile, Web Deploy literally interprets the value of the parameter as

{IIS Web Application Name}/Web.config

rather than substituting the IIS application name.

If I remove the parameter from the auto-generated SetParameters.xml file, the variable works as expected. Is there any way to prevent VS from including that parameter in the first place, either by name or by tag?

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

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

发布评论

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

评论(2

远昼 2024-12-13 22:43:21

考虑到 我之前的问题

我只需要在 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>

就是这样!

This was actually far easier than I thought, given the answer to my earlier question.

I just needed to add a Hidden tag in the target that follows AddIisAndContentDeclareParametersItems. This apparently sets the tag in the source manifest prior to the package being built. It ends up looking something like this:

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

That was it!

执笔绘流年 2024-12-13 22:43:21

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

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>

This answer is for anyone else looking for a more complete example of substitution via targets. This example shows substituting a variable "database server name" into a connection string.

The ExcludeFromSetParameter element appears to be the key to making substitution work as it keeps the param out of the SetParameters.xml file (as the OP mentioned he did manually). Unfortunately, I don't think that ExcludeFromSetParameter can be set from a parameters.xml file, so this is the only option...

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