在MSBuild任务中读取配置值

时间:2009-12-30 23:10:40

标签: configuration msbuild

有没有办法在MSBuild任务中读取System.Config连接字符串?

基本上我在配置文件中设置了连接字符串

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

我想在MSBuild这样的任务中引用它......

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

1 个答案:

答案 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)"/>

(注意:完全未经测试)