MSDeploy setParameter not working
Asked Answered
T

1

12

We are trying to integrate a 'build once, deploy anywhere' model in our build-deploy system.

MSDeploy works wonders for this, cutting down build time dramatically with CRC checksum comparisons and (for the most part) it works just as well when using parameterisation to change applications web.configs depending on the environment we deploy to.

I have the majority of these parameters nailed down, but a few elements and attributes never seem to change, no matter how many different ways I call them in the parameters.xml file. I have outlined three examples of this, here is the web.config file I am trying to change:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <connectionStrings>
        <add name="DbConnectionString" connectionString="Data Source=null;Initial Catalog=null;Trusted_Connection=no;User ID=user1;Password=pass*9;" providerName="System.Data.SqlClient" />
    </connectionStrings>

    <system.web>
        <customErrors mode="On" defaultRedirect="/Library/Error/PageNotFound.aspx">
        </customErrors>
    </system.web>

    <applicationSettings>
        <settings>
            <setting name="service_Address" serializeAs="String">
                    <value></value>
            </setting>
        <settings>
    </applicationSettings>
</configuration>

Here is the parameters.xml file:

<parameter name="DbConnectionString" defaultValue="">
    <parameterEntry kind="XmlFile" scope="\\web.config$" match="/configuration/connectionStrings/add[@name='DbConnectionString']/@connectionString" />
</parameter>

<parameter name="customErrorsMode" defaultValue="">
    <parameterEntry kind="XmlFile" scope="\\web.config$" match="configuration/system.web/customErrors/@mode" />
</parameter>

<parameter name="service_Address" defaultValue="">
    <parameterEntry kind="XmlFile" scope="\\web.config$" match="/configuration/applicationSettings/aim.Web.Properties.Settings/setting[@name='service_Address']/value" />
</parameter>

And here is the corresponding setParameters.xml file:

<setParameter name="DbConnectionString" value="Data Source=dbserver;Initial Catalog=DB1;Trusted_Connection=no;User ID=user1;Password=pass*9;"/> 

<setParameter name="customErrorsMode" value="Off"/>

<setParameter name="service_Address" value="https://myservice.asmx"/>

I have tested each XPath expression and the results are the exact same as any of the other working parameters, but the above never seem to change.

Does anyone see anything obvious I'm missing here?

Turgite answered 26/6, 2014 at 11:7 Comment(0)
T
19

service_Address

I found the answer to this problem here:

Replace web.config elements with MSDeploy

I was missing 'text()' at the end of the XPath expression, the correct XPath is:

/configuration/applicationSettings/aim.Web.Properties.Settings/setting[@name='ai‌​m_Web_AddressService_Address']/value/text()


customErrorsMode

For the customErrorsMode problem, I was missing a '/' at the start of my XPath expression. The correct expression is:

/configuration/system.web/customErrors/@mode  


connectionStrings

This one really got to me, it was the last one I figured out. After doing a bit of digging I found out that MSDeploy automatically parameterizes certain elements, connection string being one of them, more info here:

Configuring Parameters for Web Package Deployment

My parameter declaration for the connection string in question should have been:

<parameter name="DbConnectionString-Web.config Connection String" defaultValue="">
    <parameterEntry kind="XmlFile" scope="\\web.config$" match="/configuration/connectionStrings/add[@name='DbConnectionString']" />
</parameter>

My setParameter definition should have looked like this:

<setParameter name="DbConnectionString-Web.config Connection String" value="Data Source=dbserver;Initial Catalog=DB1;Trusted_Connection=no;User ID=user1;Password=pass*9;" />
Turgite answered 27/6, 2014 at 15:8 Comment(5)
Very useful in debugging an AppVeyor webdeploy: help.appveyor.com/discussions/problems/…Unchancy
Very helpful, I was stuck with my connection strings not being replaced. Thanks !Colville
Thanks for putting everything together so nicely. If you want to substitute just the password in the connection string, you can insert Password={Password}; in web.config, remove the connection string from the SetParameters.xml file and instead use <setParameter name="Password" value="secret" />Brinker
@Brinker - I can't see any documentation on what you've described. Do you have a link?Dawkins
what is "aim.Web.Properties.Settings"? and is there an MS doc for a translation of XDT to parameters.xml config?Faugh

© 2022 - 2024 — McMap. All rights reserved.