我正在使用msdeploy通过asp.net-mvc部署teamcity网络应用程序。
我正在使用paramaters.xml文件来操作我的应用web.config,特别是应用settings部分。
我有一些设置,其中只有特定环境的值才有效,其余时间值应该为空(即,属性应该只有生产值)。但是,当我不指定值时,MSDeploy会给我这个例外:
Microsoft.Web.Deployment.DeploymentException:
The 'facebookUserToken' argument cannot be null or empty.
at Microsoft.Web.Deployment.DeploymentSyncParameterValidation.Validate(String parameterName, String parameterValue)
at Microsoft.Web.Deployment.DeploymentSyncParameter.set_Value(String value)
at Microsoft.Web.Deployment.DeploymentSyncParameterCollection.LoadFromFile(XPathNavigator nav, String fileName, Boolean ignoreExtraSetParameters)
at Microsoft.Web.Deployment.DeploymentSyncParameterCollection.Load(Stream stream, String fileName, Boolean ignoreExtraSetParameters)
at Microsoft.Web.Deployment.DeploymentSyncParameterCollection.Load(String fileName, Boolean ignoreExtraSetParameters)
at MSDeploy.MSDeploy.HandleSetParameters(DeploymentObject sourceObject, Random random)
at MSDeploy.MSDeploy.ExecuteWorker()
at MSDeploy.MSDeploy.Execute()
at MSDeploy.MSDeploy.Main(String[] unusedArgs)
如何配置MSDeploy以允许参数具有空值?
的web.config:
<applicationSettings>
<SO.Example>
<setting name="FacebookUserToken" serializeAs="String">
<value></value>
</setting>
</SO.Example>
</applicationSettings>
parameters.config:
<parameter name="facebookUserToken" description="" defaultValue="">
<parameterEntry kind="XmlFile" scope="Web.config"
match="XPath removed for readability">
</parameterEntry>
</parameter>
答案 0 :(得分:35)
我在一段时间后遇到了这个问题,并在Richard Szalay's blog找到了解决方案。您需要将 parameterValidation 添加到参数声明中:
<parameters>
<parameter name="ReplaceVariable"
description="Sample variable that allows empty values" defaultValue="">
<parameterValidation kind="AllowEmpty" />
<parameterEntry type="TextFile" scope="Web\.config$" match="TextToReplace" />
</parameter>
</parameters>
因此,对于您的具体案例:
<parameter name="facebookUserToken" description="" defaultValue="">
<parameterValidation kind="AllowEmpty"/>
<parameterEntry kind="XmlFile" scope="Web.config"
match="XPath removed for readability">
</parameterEntry>
</parameter>
答案 1 :(得分:4)
我认为您正在寻找<parameterValidation />
。
在你的parameters.config中:
<parameter name="facebookUserToken" description="" defaultValue="">
<parameterValidation kind="AllowEmpty" />
<parameterEntry kind="XmlFile" scope="Web.config"
match="XPath removed for readability">
</parameterEntry>
</parameter>