开发者

Accessing semicolon delimited items in a MSBuild Variable

开发者 https://www.devze.com 2023-04-06 01:08 出处:网络
I have a variable that I am working with called $(TargetConnectionString) It is set to SomeValue=Things;Data Source=MySQLServer;Integrated Security=True;Pooling=False

I have a variable that I am working with called $(TargetConnectionString)

It is set to

SomeValue=Things;Data Source=MySQLServer;Integrated Security=True;Pooling=False

Is there a cool MSBuild way to get a reference to just the MySQLServer part of this list?

(I c开发者_如何转开发an use a batch file to parse it, but then I have to find a way to read it back in. So I am hoping there is a way to say $(TargetConnectionString."Data Source") (or something similar)

So, how can I get to get the MySQLServer text.


the following works, by calling back into the project file using an MsBuild task with the TargetConnection string as property set. Does not work with spaces though, so I removed them, hopefully that's usefull for you

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <TargetConnectionString>DataSource=MySQLServer;IntegratedSecurity=True;Pooling=False</TargetConnectionString>
  </PropertyGroup>

  <Target Name="Main">
    <MSBuild Projects="$(MSBuildProjectFullPath)" Targets="GetDataSource" Properties="$(TargetConnectionString)"/> 
  </Target>

  <Target Name="GetDataSource">
    <Message Text="$(DataSource)"/>
    <Message Text="$(IntegratedSecurity)"/>
    <Message Text="$(Pooling)"/>
  </Target>

</Project>

output:

> msbuild test.proj /t:Main
...
Project "test.proj" on node 0 (Main target(s)).
Project "test.proj" (1) is building "test.proj" (1:2) on node 0 (GetDataSource target(s)).
  MySQLServer
  True
  False
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号