1

We are trying to push a ConnectionString key in ApplicationInsights.config via parameters.xml. The parameter does not do his way to the said file.

We build a webdeploy package that is then published to different environnements. All the other parameters are for the web.config and works as expected. We want to replace

<ConnectionString> your connection string </ConnectionString>

tag in ApplicationInsights.config file through parameter.xml using azure DevOps release pipeline as we have connection string value different for our Development/UAT/Production environment. But its not working using

 <parameter name="ConnectionString" defaultValue="ConnectionString" >
    <parameterEntry kind="XmlFile" 
    scope="\\ApplicationInsights.config$"
    match="/ApplicationInsights/ConnectionString/text()">
   </parameterEntry>
  </parameter>

Can someone please suggest how to do it.

1 Answer 1

2
<parameter name="ConnectionString" defaultValue="ConnectionString" >
<parameterEntry kind="XmlFile" 
scope="\\ApplicationInsights.config$"
match="/*[local-name()='ApplicationInsights']/*[local-name()='ConnectionString']/text()" defaultValue="InstrumentationKey=;IngestionEndpoint=https://westus2-2.in.applicationinsights.azure.com/;LiveEndpoint=https://westus2.livediagnostics.monitor.azure.com/" >

Thanks to some helpful hints found Posted by Alex Marshall in http://mmmsoftware.blogspot.com/2015/08/parameterizing-applicationinsightsconfig.html

"

it was because the root element itself [of ApplicationInsights.config] used a non-empty namespace

"

I'm using file deployment method. And Microsoft has since deprecated *<InstrumentationKey>* element. The parameters.xml match attribute value that worked for me to update the connection string:

 match="/*[local-name()='ApplicationInsights']/*[local-name()='ConnectionString']/text()"

But hold on. I found a second problem after that one. MSDeploy or MSBuild doesn't match an empty target element with Xpath /text() function. It also will not match a missing element. So if your source doc in the project ApplicationInsights.config file looks something like

<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings"><ConnectionString>InstrumentationKey=;IngestionEndpoint=https://westus2-2.in.applicationinsights.azure.com/;LiveEndpoint=https://westus2.livediagnostics.monitor.azure.com/</ConnectionString>

This you can successfully replace inner text with your .setParammeters.xml file or the defaultValue= attribute in parameters.xml .

Side note I chose that string with the empty InstrumentationKey= not just for privacy redaction in Stackoverflow. It's because other strings such as "<ConnectionString>;</ConnectionString>" did match in deploy, but then caused failure in my Visual studio environment when I attempted to step through exceptions related to my own business logic. VS would complain about missing name spaces and code changes and basically forced me to quit without debugging. I removed the stub appinsights connection string and the problem went away. I'm guessing a bug with appinsights not releasing resources. But I still had a matching problem on deploy to solve.

I tried everything

        <ConnectionString/>
        <ConnectionString>  </ConnectionString>
        <ConnectionString><!-- nope --></ConnectionString> 
<ConnectionString><cutebutno/></ConnectionString> 
    <ConnectionString><![CDATA[]]></ConnectionString>

before realizing all I needed to do was remove is the GUID in the connection string, then VS is happy.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.