我正在尝试执行以下操作:
Exec
任务时使用此属性。我坚持:
<CreateProperty Value="@(Files, ';')">
<Output TaskParameter="Value" ItemName="TSFiles" />
</CreateProperty>
<Message Text="$(TSFiles)"/>
打印空字符串。
这就是我现在要做的事情......但这几乎让我哭了
<Target Inputs="@(DeployLabel)" Name="GenericDeploy" Outputs="%(Identity).Dummy">
<PropertyGroup>
<TargetFilter>%(DeployLabel.Dir)</TargetFilter>
<TargetFilterReplaced>$(TargetFilter.Replace('\', ''))</TargetFilterReplaced>
</PropertyGroup>
<WriteLinesToFile
File="$(ProjectDir)tsfiles.txt"
Condition="$([System.Text.RegularExpressions.Regex]::IsMatch(%(Filter),
'$(TargetFilterReplaced)'))"
Lines="@(TypeScriptCompile ->'"%(fullpath)"', ' ')"
Overwrite="false" />
<PropertyGroup>
<TSFilesFiltered>$([System.IO.File]::ReadAllText($(ProjectDir)tsfiles.txt))</TSFilesFiltered>
<TSFilesOneLine>$([System.Text.RegularExpressions.Regex]::Replace(
$(TSFilesFiltered), "[\n\r]+", " "))</TSFilesOneLine>
</PropertyGroup>
<Exec Command="tsc --target ES3 -c -d --out $(Deployroot)\foo.js $(TSFilesOneLine)" />
<Delete Files="$(ProjectDir)tsfiles.txt"/>
</Target>
答案 0 :(得分:0)
<PropertyGroup>
<TSFiles>@(Files)</TSFiles>
</PropertyGroup>
<Message Text="$(TSFiles)"/>
或只是
<Message Text="@(Files)"/>
更新:我不明白为什么你把一些文字写入文件并直接读取这个文件,因为你单独调用DeployLabel的每个元素来调用目标,所以tsfiles.txt只应该包括当前元素的行。
我在这里做了一个test.proj并遇到了一些问题,尤其是@(TypeScriptCompile
,因为该属性对我来说是空的。所以我创建了一些具有这种结构的虚拟文件:
d:\Temp\LabelTest\Label1.txt
d:\Temp\LabelTest2\Label2.txt
d:\Temp\LabelTest\Label2.txt
我制作了两个Label2.txt用于验证条件并发现它需要按其他顺序排列。你可以运行它,希望能得到一些新的想法,或者你可以说出需要不同的东西。这是我用于测试的proj文件:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="GenericDeploy" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Deployroot>d:\Temp</Deployroot>
</PropertyGroup>
<ItemGroup>
<DeployLabel Include="$(Deployroot)\**\Label1.txt">
<Filter>TempLabelTest</Filter>
</DeployLabel>
<DeployLabel Include="$(Deployroot)\**\Label2.txt">
<Filter>TempLabelTest2</Filter>
</DeployLabel>
</ItemGroup>
<Target Name="MessageLabels">
<Message Text="@(DeployLabel)" />
</Target>
<Target Inputs="@(DeployLabel)" Name="GenericDeploy" Outputs="%(Identity).Dummy" DependsOnTargets="MessageLabels">
<Message Text="DeployLabel.Filter: %(DeployLabel.Filter)" />
<PropertyGroup>
<TargetFilter>%(DeployLabel.Directory)</TargetFilter>
<TargetFilterReplaced>$(TargetFilter.Replace('\', ''))</TargetFilterReplaced>
<ConditionTest>$([System.Text.RegularExpressions.Regex]::IsMatch('$(TargetFilterReplaced)', '%(DeployLabel.Filter)'))</ConditionTest>
</PropertyGroup>
<Message Text="TargetFilter: $(TargetFilter)" />
<Message Text="TargetFilterReplaced: $(TargetFilterReplaced)" />
<Message Text="ConditionTest: $(ConditionTest)" />
<PropertyGroup Condition="'$(ConditionTest)' == 'True'">
<TSFilesFiltered>(TypeScriptCompile ->'"%(DeployLabel.fullpath)"', ' ') </TSFilesFiltered>
<TSFilesOneLine>$([System.Text.RegularExpressions.Regex]::Replace($(TSFilesFiltered), "[\n\r]+", " "))</TSFilesOneLine>
</PropertyGroup>
<Message Text="TSFilesFiltered: $(TSFilesFiltered)" />
<Message Text="TSFilesOneLine: $(TSFilesOneLine)" />
<Message Text="tsc --target ES3 -c -d --out $(Deployroot)\foo.js $(TSFilesOneLine)" Condition="'$(ConditionTest)' == 'True'"/>
</Target>
</Project>