本文介绍了MSDeploy - 允许参数在 parameters.xml 中可选/为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 .

我正在使用 paramaters.xml 文件来操作我的应用程序的 web.config,特别是应用程序设置部分.

I am using a paramaters.xml file to manipulate my application's web.config, specifically the application settings section.

我有一些设置,其中只有特定环境的值才有效,其余时间该值应为空(即,属性应仅在生产中具有值).但是,当我指定一个值时,MSDeploy给了我这个异常:

I have some Settings where it is only valid to have a value for a specific environment and the rest of the time the value should be blank (ie, Property should only have a value on Production). However, MSDeploy gives me this Exception when I do not specify a value:

 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 以允许参数具有空值?

How can I configure MSDeploy to allow a parameter to have an empty value?

web.config:

web.config:

<applicationSettings>
    <SO.Example>
        <setting name="FacebookUserToken" serializeAs="String">
           <value></value>
        </setting>
    </SO.Example>
</applicationSettings>

parameters.config:

parameters.config:

   <parameter name="facebookUserToken" description="" defaultValue="">
      <parameterEntry kind="XmlFile" scope="Web.config"
      match="XPath removed for readability">
       </parameterEntry>
   </parameter>

推荐答案

我不久前遇到了这个问题,并在 Richard Szalay 的博客.您需要将 parameterValidation 添加到您的 parameter 声明中:

I ran across this issue a while back and found the solution at Richard Szalay's blog. You need to add the parameterValidation to your parameter declaration:

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

所以对于您的具体情况:

So for your specific case:

  <parameter name="facebookUserToken" description="" defaultValue="">
      <parameterValidation kind="AllowEmpty"/>
      <parameterEntry kind="XmlFile" scope="Web.config"
      match="XPath removed for readability">
       </parameterEntry>
   </parameter>

这篇关于MSDeploy - 允许参数在 parameters.xml 中可选/为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 19:46