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

标签 msbuild metadata itemgroup

我有一个 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> 的含义有点困惑元素在这里所做的 - 它将创建一个以 PropertyName 属性中的值命名的属性,并将该属性的 设置为来自构建步骤任务。您对 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/

相关文章:

visual-studio-2010 - 32/64 位的 MSBuild 和 $(ProgramFiles) 问题

msbuild - 调用 msbuild 包时如何将本地 DLL 引用包含到 nuget 包中?

msbuild - 在msbuild中过滤项目的元数据

msbuild - 删除基于 MSBuild/Convention 的文件名生成中的尾部斜杠

Jenkins MSBuild 失败,错误 NETSDK1064 : Package Microsoft. CodeAnalysis.Analyzers,未找到版本 2.9.3

azure - 覆盖 Blob 但保留元数据?

Node.js : How can I add meta data to an audio file?

python - python 类中的元数据

msbuild - MsBuild:通过CallTarget传递ItemGroup

msbuild - 将 ItemGroup 转换为分隔字符串