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

发布于 2024-09-13 20:48:46 字数 754 浏览 5 评论 0原文

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

I have an ItemGroup, and I use its metadata as identifiers in my MSBuild project for batch processing. For example:

        <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>

However, this will not work, because there is a dot in the Extension, which is invalid character for an Id (in the BuildStep task). Thus, the MSBuild always fails on the BuildStep task.

I've been trying to remove the dot, but with no luck. Maybe there is a way to add some metadata to en existing ItemGroup? Ideally, I would like to have something like %(TestSuite.ExtensionWithoutDot). How can I achieve that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

困倦 2024-09-20 20:48:46

我认为您对 元素在这里所做的事情有点困惑 - 它将创建一个以 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>

I think you are slightly confused about what the <Output> element is doing here - it will create a property named with the value in the PropertyName attribute, and will set the value of that property to be value of the Id output from the BuildStep task. You have no influence on the value of Id - you just store it in a property for later reference in order to set the status of the build step

With that in mind, I can't see why you are concerned that the Property created would have a name that would include the concatenation of the extension. As long as the property name is unique, you can reference it later in a subsequent BuildStep task, and I presume your testsuite filename is enough to indicate uniqueness.

In fact, you could avoid having to create unique properties that track each testsuite/buildstep pair if you did Target batching:

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文