Jim Mitchener
Jim Mitchener

Reputation: 9003

Read Config Value in MSBuild Task

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

Basically I have my connection string setup in a config file

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

And I would like to reference it in an MSBuild task like so ...

<Target Name="Migrate" DependsOnTargets="Build">
    ...
    <Migrate Connectionstring="$(MyApp.MyConnectionString)" ... />
</Target>

Upvotes: 3

Views: 4030

Answers (1)

gregmac
gregmac

Reputation: 25331

There's an XMLRead task in the MSBuild Community Tasks Project, that uses xpath to pull out a value.

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

(note: totally untested)

Upvotes: 3

Related Questions