MSBuild 可以排除“隐藏”吗?生成的 SetParameters.xml 中的 Web 部署参数?
在我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
考虑到 我之前的问题。
我只需要在
AddIisAndContentDeclareParametersItems
后面的目标中添加一个 Hidden 标记。这显然是在构建包之前在源清单中设置标签。它最终看起来像这样:就是这样!
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:That was it!
这个答案适用于任何其他正在寻找通过目标进行替换的更完整示例的人。此示例显示将变量“数据库服务器名称”替换为连接字符串。
ExcludeFromSetParameter 元素似乎是进行替换工作的关键,因为它将参数保留在 SetParameters.xml 文件之外(正如 OP 提到的他手动执行的那样)。不幸的是,我不认为可以从parameters.xml 文件中设置ExcludeFromSetParameter,所以这是唯一的选择......
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...