gpt4 book ai didi

msbuild - 如何在 MSBuild 中获取扩展名(不带点)

转载 作者:行者123 更新时间:2023-12-04 06:48:29 25 4
gpt4 key购买 nike

我有一个 ItemGroup,我在我的 MSBuild 项目中使用它的元数据作为标识符进行批处理。例如:

        <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) 这样的东西。我怎样才能做到这一点?

最佳答案

我想你对 <Output> 的内容有点困惑element 在这里执行 - 它将创建一个以 PropertyName 属性中的值命名的属性,并将该属性的值设置为 BuildStep 任务的 Id 输出值。您对 Id 的值没有影响 - 您只需将其存储在一个属性中供以后引用,以便设置构建步骤的状态

考虑到这一点,我不明白您为什么担心创建的属性的名称将包含扩展的串联。只要属性名称是唯一的,您就可以稍后在后续的 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>

关于msbuild - 如何在 MSBuild 中获取扩展名(不带点),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3459043/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com