<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.