如何在MSBuild中获取扩展名(不带点)
我有一个ItemGroup,我在MSBuild项目中使用它的元数据作为标识符进行批处理。例如:如何在MSBuild中获取扩展名(不带点),msbuild,metadata,itemgroup,Msbuild,Metadata,Itemgroup,我有一个ItemGroup,我在MSBuild项目中使用它的元数据作为标识符进行批处理。例如: <BuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)" Name="RunUnitTestsStep-%(TestSuite.Filename)-%(TestSuite.Extension)"
<BuildStep
TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
BuildUri="$(BuildUri)"
Name="RunUnitTestsStep-%(TestSuite.Filename)-%(TestSuite.Extension)"
Message=" - Unit Tests: %(TestSuite.Filename): %(TestSuite.Extension)">
<Output
TaskParameter="Id"
PropertyName="RunUnitTestsStepId-%(TestSuite.Filename)-%(TestSuite.Extension)" />
</BuildStep>
但是,这将不起作用,因为扩展名中有一个点,它对于Id是无效字符(在BuildStep任务中)。因此,MSBuild在BuildStep任务中总是失败
我一直在试着去掉这个圆点,但是运气不好。也许有一种方法可以将一些元数据添加到现有的ItemGroup中?理想情况下,我希望有类似于%(TestSuite.ExtensionWithoutDot)的东西。如何实现这一点?我想您对
元素在这里做什么有些困惑-它将创建一个名为PropertyName属性中的值的属性,并将该属性的值设置为BuildStep任务输出的Id值。您对Id的值没有影响-您只需将其存储在属性中以供以后参考,以便设置生成步骤的状态
考虑到这一点,我不明白为什么您会担心创建的属性会有一个包含扩展连接的名称。只要属性名是唯一的,您就可以在以后的BuildStep任务中引用它,我认为您的testsuite文件名足以指示唯一性 事实上,如果执行目标批处理,则可以避免创建跟踪每个testsuite/buildstep对的唯一属性:
<Target Name="Build"
Inputs="@(TestSuite)"
Outputs="%(Identity).Dummy">
<!--
Note that even though it looks like we have the entire TestSuite itemgroup here,
We will only have ONE - ie we will execute this target *foreach* item in the group
See http://beaucrawford.net/post/MSBuild-Batching.aspx
-->
<BuildStep
TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
BuildUri="$(BuildUri)"
Name="RunUnitTestsStep-%(TestSuite.Filename)-%(TestSuite.Extension)"
Message=" - Unit Tests: %(TestSuite.Filename): %(TestSuite.Extension)">
<Output
TaskParameter="Id"
PropertyName="TestStepId" />
</BuildStep>
<!--
..Do some stuff here..
-->
<BuildStep Condition=" Evaluate Success Condition Here "
TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
BuildUri="$(BuildUri)"
Id="$(TestStepId)"
Status="Succeeded" />
<BuildStep Condition=" Evaluate Failed Condition Here "
TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
BuildUri="$(BuildUri)"
Id="$(TestStepId)"
Status="Failed" />
</Target>
“考虑到这一点,我不明白为什么您会担心创建的属性会有一个包含扩展连接的名称。只要属性名称是唯一的,您可以在以后的BuildStep任务中引用它,我认为您的testsuite文件名足以指示唯一性。”一般来说,您是鲁格特-如果PropertyName是唯一的,我可以稍后参考它。但是,在我的示例中,PropertyName中会有一个点,而点对于PropertyName是无效字符。因此,将不会创建属性,而且,MSBuild将失败。目标标记的输入属性看起来像是我的问题的解决方案。我想我想说的是,如果你不使用%(扩展名),你的解决方案是可以的-你的解决方案不需要是完美的,%(文件名)本身可能就足够了,尽管有点非传统。但我关于目标批处理的建议可能更像MSBuild,使用了语言的预期特性。但是原始思维的最高分数;-)