问题
I have a web application which we are deploying with msdeploy.
I've defined the following parameters.xml file in the project:
<parameters>
<parameter
name="Database Server"
description="Location of your database server."
defaultValue="localhost"
tags="DBServer, SQL">
</parameter>
<parameter
name="Database Name"
description="Name of the database for your application."
defaultValue="MyDatabase" tags="DBName, SQL">
</parameter>
<parameter
name="Database Username"
description="User name to access your application database."
defaultValue="myusername"
tags="SQL, DbUsername">
</parameter>
<parameter
name="Database Password"
description="Password for the Database Username."
defaultValue="mypassword"
tags="SQL, DbUserPassword">
</parameter>
<parameter
name="RTPOne-Web.config Connection String"
description="Connection string to enter into config"
defaultValue="Data Source={Database Server};Initial Catalog={Database Name};User Id={Database Username};Password={Database Password};Connection TimeOut=30;Pooling=false;Max Pool Size=500;"
tags="Hidden, SQL">
<parameterEntry kind="XmlFile" scope="\\web\.config$" match="//*[local-name()='connectionStrings']/*[local-name()='add'][@name='RTPOne']/@connectionString" tags="Sql, SqlConnectionString, Hidden" />
<parameterEntry kind="XmlFile" scope="\\web\.config$" match="//*[local-name()='appSettings']/*[local-name()='add'][@key='DBConnStr']/@value" tags="" />
</parameter>
</parameters>
The last parameter uses the following replacement fields:
{Database Server}
{Database Name}
{Database Username}
{Database Password}
When I use the "Import Application" option from within IIS 7.5, these replacement fields are filled in correctly using the values that were supplied by the other parameters.
However, when I use the Application.Deploy.cmd file to deploy the application via command line, none of these values are replaced correctly and I end up with a connection string that looks like this:
Data Source={Database Server};Initial Catalog={Database Name};User Id={Database Username};Password={Database Password};Connection TimeOut=30;Pooling=false;Max Pool Size=500;
The Application.SetParameters.xml file that is generated with the deployment package contains the correct default values. I'm expecting that the Deploy.cmd batch file should be able to use the default values from it:
<?xml version="1.0" encoding="utf-8"?>
<parameters>
<setParameter name="IIS Web Application Name" value="Default Web Site/MyApplication" />
<setParameter name="Database Server" value="localhost" />
<setParameter name="Database Name" value="MyDatabase" />
<setParameter name="Database Username" value="MyUsername" />
<setParameter name="Database Password" value="MyPassword" />
<setParameter name="Web.config Connection String" value="Data Source={Database Server};Initial Catalog={Database Name};User Id={Database Username};Password={Database Password};Connection TimeOut=30;Pooling=false;Max Pool Size=500;" />
</parameters>
Is there anything I can do to get the Deploy.cmd batch file to correctly substitute these values?
回答1:
One peculiarity you may not be aware of...
If the Application.SetParameters.xml file contains a setParameter
element for the connection string, that value will be used as is by WebDeploy. I.e. no attempt will be made to perform any substitution at all.
If that setParameter reference is removed from the SetParameters.xml file WebDeploy will recognize that the defined default value should be used instead, and calculate it, as expected, based on the value(s) of the other parameters.
回答2:
You can take the Application.SetParameters.xml outside and replace the values you need to and pass it Application.Deploy.cmd as an arguement. In may case, I've created separate parameter file for each environment and pass them based on to which environment we are deploying. You can find details in application.deploy-readme.txt as well.
Let me know if you need more details
来源:https://stackoverflow.com/questions/18137773/how-to-get-deploy-cmd-to-fill-in-replacement-fields-from-parameters-xml