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?

0

1 Answer 1

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;" />
5
  • 1
    Very useful in debugging an AppVeyor webdeploy: help.appveyor.com/discussions/problems/… Mar 12, 2015 at 12:08
  • 1
    Very helpful, I was stuck with my connection strings not being replaced. Thanks ! Jul 3, 2015 at 11:11
  • 1
    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" />
    – tobbenb3
    Mar 2, 2017 at 19:42
  • @tobbenb3 - I can't see any documentation on what you've described. Do you have a link?
    – fml
    Mar 1, 2018 at 13:28
  • what is "aim.Web.Properties.Settings"? and is there an MS doc for a translation of XDT to parameters.xml config?
    – red888
    Apr 10, 2018 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.