以下工作,通过使用将 TargetConnection 字符串作为属性集的 MsBuild 任务回调到项目文件中。虽然不适用于空格,所以我删除了它们,希望这对你有用
<?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>
输出:
> 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