Web.config在部署时未参数化 [英] Web.config not being parametrized on deploy

查看:80
本文介绍了Web.config在部署时未参数化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP MVC应用程序,我正在通过TeamCity部署到Intranet服务器,并且我需要对一些appSettings进行参数化部署,以便对开发人员等隐藏客户端机密.

I have an ASP MVC app that I'm deploying to intranet servers via TeamCity, and I need some appSettings to be parametrized on deploy, so that client secrets stay hidden from developers etc.

我在项目的根目录中有Parameters.xml文件,使用软件包正确构建的SetParameters.xml包含所有这些参数及其默认值.但是,更改这些值(即使使用-setParam将其传递到MSDeploy)也不会导致已部署的web.config发生任何更改.

I have the Parameters.xml file in the root of my project, the SetParameters.xml that is built with the package correctly contains all these parameters and their default values. However changing these values (even passing them to MSDeploy with -setParam) doesn't result in any changes in deployed web.config.

当我更改SetParameters.xml文件(正确地传递给MSDeploy afaik)中的值时,部署的web.config中的设置不会更改,并且出现详细:参数条目'IIS Web应用程序名称" /1'适用"日志中的条目(IIS Web应用程序名称是另一个标准参数),没有提及我的appSettings参数.

When I change the values in the SetParameters.xml file (which is passed to MSDeploy correctly afaik), the settings in the deployed web.config don't change and while there are "Verbose: Parameter entry 'IIS Web Application Name/1' is applicable" entries in log (IIS Web Application Name being another, standard, parameter), there's no mention of my appSettings parameters.

此外,当我使用IIS管理器导入应用程序时,它会要求我提供这些参数的值,但我也看不到详细日志中提到的这些参数,除非存在该配置,否则web.config根本不会得到更新确实有一些更改,在那种情况下,这些参数不会被替换.

Also When I import the application with IIS Manager, it asks me for the values for these parameters, but I don't see them mentioned in verbose logs either, and the web.config doesn't get updated at all unless there really were some changes, and in that case the parameters aren't replaced.

我的parameters.xml看起来像这样:

My parameters.xml look like this:

<?xml version="1.0" encoding="utf-8" ?>
<parameters>
  <parameter name="PiwikToken" defaultValue="__PIWIKTOKEN__">
    <parameterEntry type="XMLFile" scope="\\web\.config$" match="/configuration/appSettings/add[@key='PiwikToken']/@value"/>
  </parameter>
  <parameter name="LoginClientSecret" defaultValue="__LOGINSECRET__">
    <parameterEntry type="XMLFile" scope="\\web\.config$" match="/configuration/appSettings/add[@key='LoginClientSecret']/@value"/>
  </parameter>
  <parameter name="SecondClientSecret" defaultValue="__SECONDSECRET__">
    <parameterEntry type="XMLFile" scope="\\web\.config$" match="/configuration/appSettings/add[@key='SecondClientSecret']/@value"/>
  </parameter>
</parameters>

我尝试了其他范围的变化("web.config $","web.config","\\ web.config $","\\ web \ .config $","Portal \ web.config $ "...),并没有改变任何事情. 针对我的web.config测试的XPath表达式可以正常工作.

I've tried other scope variations ("web.config$", "web.config", "\\web.config$", "\\web\.config$", "Portal\web.config$"...) and it didn't change a thing. The XPath expressions tested against my web.config work OK.

web.config:

web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="LoginClientId" value="portalLocal" />
    <add key="RedirectAfterAuthUrl" value="https://localhost:44321/" />
    <add key="PiwikSiteId" value="12" />
    <add key="PiwikToken" value="__PIWIKTOKEN__" />
    <add key="LoginClientSecret" value="__LOGINSECRET__" />
    <add key="SecondClientSecret" value="__SECONDSECRET__" />
  </appSettings>
  <connectionStrings>
    <add name="appDB" connectionString="..." />
  </connectionStrings>
...

我检查过的其他内容:

  • 已启用MSDeploy中的参数化

在.zip包内部生成的文件"parameters.xml"包含

The file "parameters.xml", which is generated inside the .zip package, contains

<parameters>
  <parameter name="IIS Web Application Name" defaultValue="Portal" tags="IisApp">
    <parameterEntry kind="ProviderPath" scope="IisApp" match="^D:\\BuildAgent\\work\\fec2f9c37ed1ec8e\\Portal\\obj\\DEV\\Package\\PackageTmp$" />
    <parameterEntry kind="ProviderPath" scope="setAcl" match="^D:\\BuildAgent\\work\\fec2f9c37ed1ec8e\\Portal\\obj\\DEV\\Package\\PackageTmp$" />
  </parameter>
  <parameter name="Add write permission to App_Data Folder" description="Add write permission to App_Data folder" defaultValue="{IIS Web Application Name}/App_Data" tags="Hidden">
    <parameterEntry kind="ProviderPath" scope="setAcl" match="^D:\\BuildAgent\\work\\fec2f9c37ed1ec8e\\Portal\\obj\\DEV\\Package\\PackageTmp\\App_Data$" />
  </parameter>
  <parameter name="PiwikToken" defaultValue="__PIWIKTOKEN__" />
  <parameter name="LoginClientSecret" defaultValue="__LOGINSECRET__" />
  <parameter name="SecondClientSecret" defaultValue="__SECONDSECRET__" />
</parameters>

根据网络上的各种来源,常见的原因是范围错误或匹配正则表达式错误,但是我尝试了各种变体而没有成功.

According to various sources across the net, the common cause for this would be that the scope is wrong or that the match regexp is wrong, but I've tried all kinds of variants without success.

如果任何人对尝试什么或可能的原因有任何想法,我将很高兴进一步探索或尝试,但是现在我已经花了几天时间,无法考虑什么其他尝试.谢谢!

If anyone has any ideas about what to try, or what could be the cause, I'll be glad to explore further or try it out, but right now I've spent a few days on this and cannot think of what else to try. Thanks!

现在,我已经使用MVC创建了一个新的WebAPI项目,仅添加了parameters.xml,将这些参数添加到了web.config中,而web.config在部署时仍然没有参数化.那是不是在某个地方设置了IIS?

Now I've created a fresh WebAPI project with MVC, added just parameters.xml, added those parameters to web.config, and the web.config still doesn't get parametrized on deploy. So is it some IIS setting somewhere?

经过实验后,我发现zip包中生成的 parameters.xml 确实应包含"match"和"scope"属性,而它们不包含-自从我重写xml以来使其包含具有适当匹配和范围的parameterEntry,然后将其重新打包到zip中,即可开始工作.

After experimenting I found out that the generated parameters.xml inside the zip package really should containt "match" and "scope" attributes and they don't - since when I rewrite the xml so that it contains parameterEntry with proper match and scope, and repackage it into the zip, it starts working.

问题应该是属性名为"type" ,而应该将其命名为种类" .现在我只想知道,我是从哪儿得到的那个例子?

And the problem seems to be having attribute named "type", when it should've been named "kind". Now I only wonder, where did I first get that example I used...

推荐答案

问题是我应该在我的parameters.xml中有一个名为"type"的属性,而该属性应命名为"kind".

The problem was I had an attribute named "type" in my parameters.xml, when it should've been named "kind".

感谢 https://forums.iis.net/t/1177518.aspx

这篇关于Web.config在部署时未参数化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆