在MSBuild任务中读取配置值 [英] Read Config Value in MSBuild Task

查看:121
本文介绍了在MSBuild任务中读取配置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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="..." />

我想在MSBuild任务中引用它...

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

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


推荐答案

MSBuild社区任务项目,使用xpath提取值。

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

(注意:完全未经测试)

这篇关于在MSBuild任务中读取配置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆