Philip Pittle
Philip Pittle

Reputation: 12325

MSDeploy - Allow Parameter to be optional / empty in parameters.xml

I am using to deploy a web application via .

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

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)

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

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>

Upvotes: 17

Views: 5379

Answers (2)

user4007604
user4007604

Reputation:

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>

Upvotes: 40

Steven V
Steven V

Reputation: 16595

I think you're looking for <parameterValidation />.

In your parameters.config:

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

Upvotes: 5

Related Questions