有没有办法在MSBuild任务中读取System.Config连接字符串?
基本上我在配置文件中设置了连接字符串
<add name="MyApp.MyConnectionString" connectionString="..." />
我想在MSBuild这样的任务中引用它......
<Target Name="Migrate" DependsOnTargets="Build">
...
<Migrate Connectionstring="$(MyApp.MyConnectionString)" ... />
</Target>
答案 0 :(得分:3)
MSBuild Community Tasks Project中有一个XMLRead任务,它使用xpath来提取值。
<XmlRead
XPath="/add/@connectionString"
XmlFileName="app.config">
<Output TaskParameter="Value" PropertyName="MyConnectionString" />
</XmlRead>
<Message Text="MyConnectionString: $(MyConnectionString)"/>
(注意:完全未经测试)