我遇到了MSBuild中的以下问题。 我有一个包含列表(逐行)的文本文件(buildsolutions1.txt),其中包含我需要构建的所有解决方案以及用逗号分隔的相关开发人员电子邮件:
Common \ Common.sln,am @ email,com
ExcGw / ExcDataService.sln,下午@ email.com;上午@电子邮件,玉米; jk@email.com; mk@email.com; Ppp@email.com
MessB / MessB / Message.sln,上午@电子邮件,COM
风险/ RiskS2.sln,JP @ email.com; mz@email.com; mk@email.com; jk@email.com; ps@email.com
我需要逐行阅读此文件,编译每个解决方案,如果失败 - 向相关开发人员发送电子邮件
我的想法是创建一个项目组行,其中每个项目都是此文件中的一行,它有2个元数据值: 解决方案 - 直到逗号的第一部分 电子邮件 - 从逗号到行尾
的行的第二部分所以我创建了一个Property Grroup和一个目标ReadSolutions,如下所示。
我逐行阅读文件,但我不知道如何为每个订单项设置元数据:
FirstPartOfTheCurrentLine(%(LinesFromFile.Identity))
SecondPartOfTheCurrentLine(%(LinesFromFile.Identity))
此语法不起作用:
%(LinesFromFile.Identity.Split( '')[0])
%(LinesFromFile.Identity.Split( '')[1])
也许有人会知道如何正确设置元数据,或者可能有另一种方法来完成这项任务。 感谢
以下是代码:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
ToolsVersion="4.0" DefaultTargets="CoreBuild">
<PropertyGroup>
<TPath>$(MSBuildProjectDirectory)\..\tools\MSBuild Extension Pack Binaries\MSBuild.ExtensionPack.tasks</TPath>
</PropertyGroup>
<Import Project="$(TPath)"/>
<PropertyGroup>
<!-- Default working folder -->
<RootFolder Condition=" '$(RootFolder)' == '' " >c:\ff\</RootFolder>
<BuildSolutionsFile >buildsolutions1.txt</BuildSolutionsFile>
<BuildSolutionsFileFullPath >$(RootFolder)$(BuildSolutionsFile)</BuildSolutionsFileFullPath>
</PropertyGroup>
<Target Name="ReadSolutions">
<Message Text=" Build solutions text file is : $(BuildSolutionsFileFullPath)" />
<!—Read the file and store each line as an item into LinesFromFile item group-->
<ReadLinesFromFile
File="$(BuildSolutionsFileFullPath)" >
<Output
TaskParameter="Lines"
ItemName="LinesFromFile"/>
</ReadLinesFromFile>
<Message Text="Current line : %(LinesFromFile.Identity)" />
<Message Text="===================================" />
<!—Create the other item group where each item is a line and has the metadata Solution and Emails -->
<ItemGroup>
<Lines Include="%(LinesFromFile.Identity)" >
<Solution>FirstPartOfTheCurrentLine(%(LinesFromFile.Identity))</Solution>
<Emails>SecondPartOfTheCurrentLine(%(LinesFromFile.Identity)) </Emails>
</Lines>
</ItemGroup>
<Message Text="All the Lines :%0A@(Lines,'%0A')" />
</Target>
答案 0 :(得分:7)
以下是我正在使用的数据:
Common\Common.sln,am@email,com
ExcGw/ExcDataService.sln,pm@email.com;am@email,com;jk@email.com;mk@email.com;Ppp@email.com
MessB/MessB/Message.sln,am@email,com
RiskS/RiskS2.sln,jp@email.com;mz@email.com;mk@email.com;jk@email.com;ps@email.com
略微修改您的样本以包含第四个解决方案的换行符。
以下是修改后的代码:
<ItemGroup>
<Lines Include="@(LinesFromFile)" >
<Solution>$([System.String]::Copy('%(LinesFromFile.Identity)').Split(',')[0])</Solution>
<Emails>$([System.String]::Copy('%(LinesFromFile.Identity)').Split(',')[1])</Emails>
</Lines>
</ItemGroup>
<Message Text="Solutions to Emails-> %(Lines.Solution) -> %(Lines.Emails)" />
我们正在将值复制到属性,因此我们可以使用属性函数来分割值并获得我们需要的部分。
这是输出:
Solutions to Emails-> Common\Common.sln -> am@email
Solutions to Emails-> ExcGw/ExcDataService.sln -> pm@email.com;am@email
Solutions to Emails-> MessB/MessB/Message.sln -> am@email
Solutions to Emails-> RiskS/RiskS2.sln -> jp@email.com;mz@email.com;mk@email.com;jk@email.com;ps@email.com