如何获取Deploy.cmd来填充Parameters.xml中的替换字段 [英] How to get Deploy.cmd to fill in replacement fields from Parameters.xml

查看:67
本文介绍了如何获取Deploy.cmd来填充Parameters.xml中的替换字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web应用程序,我们正在使用msdeploy进行部署.

I have a web application which we are deploying with msdeploy.

我在项目中定义了以下parameters.xml文件:

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}

当我在IIS 7.5中使用导入应用程序" 选项时,将使用其他参数提供的值正确填写这些替换字段.

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.

但是,当我使用 Application .Deploy.cmd 文件通过命令行部署应用程序时,这些值均未正确替换 >,最后得到的连接字符串如下所示:

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;

与部署包一起生成的 Application .SetParameters.xml文件包含正确的默认值.我期望Deploy.cmd批处理文件应该能够使用其中的默认值:

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>

我是否可以做些什么来获取Deploy.cmd批处理文件以正确替换这些值?

推荐答案

您可能不知道的一个独特之处...

One peculiarity you may not be aware of...

如果Application.SetParameters.xml文件包含连接字符串的setParameter元素,则WebDeploy将按原样使用该值. IE.完全不会尝试进行任何替换.

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.

如果从SetParameters.xml文件中删除了setParameter引用,则WebDeploy将识别出应该使用定义的默认值,并根据其他参数的值按预期方式对其进行计算.

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.

这篇关于如何获取Deploy.cmd来填充Parameters.xml中的替换字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆