MSDeploy - 允许参数在parameters.xml中为可选/空

时间:2021-10-29 08:03:56

I am using to deploy a web application via .

我正在使用msdeploy通过teamcity部署asp.net-mvc Web应用程序。

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

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

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:

我有一些设置,其中只有特定环境的值才有效,其余时间值应为空(即,属性应该只有生产值)。但是,当我没有指定值时,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)

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

如何配置MSDeploy以允许参数具有空值?

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>

2 个解决方案

#1


33  

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:

我不久前遇到了这个问题,并在Richard Szalay的博客上找到了解决方案。您需要将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> 

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>

#2


4  

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

我想你正在寻找

In your parameters.config:

在你的parameters.config中:

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

#1


33  

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:

我不久前遇到了这个问题,并在Richard Szalay的博客上找到了解决方案。您需要将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> 

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>

#2


4  

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

我想你正在寻找

In your parameters.config:

在你的parameters.config中:

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