Read Config Value in MSBuild Task

廉价感情. 提交于 2019-12-20 02:44:26

问题


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>

回答1:


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)



来源:https://stackoverflow.com/questions/1983010/read-config-value-in-msbuild-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!