Reading configuration value in MSBuild task

Is there a way to read the System.Config connection string in an MSBuild task?

Basically I have a connection string setting in the configuration file

<add name="MyApp.MyConnectionString" connectionString="..." />

And I would like to reference it in the MSBuild task, for example ...

<Target Name="Migrate" DependsOnTargets="Build">
    ...
    <Migrate Connectionstring="$(MyApp.MyConnectionString)" ... />
</Target>
+3
source share
1 answer

This sets XMLRead to the MSBuild Community Tasks Project , which uses xpath to pull the value.

<XmlRead 
  XPath="/add/@connectionString"
  XmlFileName="app.config">
    <Output TaskParameter="Value" PropertyName="MyConnectionString" />
</XmlRead>
<Message Text="MyConnectionString: $(MyConnectionString)"/>

(note: fully unverified)

+3
source

Source: https://habr.com/ru/post/1726942/


All Articles