本文介绍了如何在MSBuild中获取扩展名(不带点)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ItemGroup,并且在MSBuild项目中将其元数据用作标识符进行批处理.例如:

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>

但是,这将不起作用,因为扩展名中有一个点,该点对于ID是无效字符(在BuildStep任务中).因此,MSBuild始终在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.

我一直在尝试删除圆点,但是没有运气.也许有一种方法可以将一些元数据添加到现有的ItemGroup中?理想情况下,我想使用%(TestSuite.ExtensionWithoutDot)之类的东西.我该如何实现?

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?

推荐答案

我认为您对<Output>元素在这里所做的工作感到有些困惑-它会创建一个以PropertyName属性中的值命名的属性,并且将该属性的 value 设置为BuildStep任务中Id output 的值.您对Id的值没有任何影响-您只需将其存储在属性中以供以后参考即可设置构建步骤的状态

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

考虑到这一点,我看不到您为什么担心所创建的Property具有一个包含扩展名串联的名称.只要属性名称是唯一的,您就可以稍后在后续的BuildStep任务中引用它,并且我认为您的测试套件文件名足以表明唯一性.

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>

这篇关于如何在MSBuild中获取扩展名(不带点)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 05:06