0

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 can 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.

Vaccano
  • 78,325
  • 149
  • 468
  • 850

1 Answers1

1

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
stijn
  • 34,664
  • 13
  • 111
  • 163