xml - TFS 2010/代码度量集成,自动构建失败,代码度量不运行

标签 xml tfs build-automation tfsbuild code-metrics

在 TFS 2010 中的自动化团队构建之后,我正在尝试添加自动构建后触发器以运行 NDepend(代码度量软件)。

NDepend 的网站提供了用于集成此功能的代码,因此我已将他们的代码粘贴到我的 .csproj 文件中,他们说要这样做,但我在构建时收到错误。

错误涉及我在代码片段中的三个“BuildStep”标记中的两个。以下两个片段给我错误:

<BuildStep         
    TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
    BuildUri="$(BuildUri)"
    Message="Running NDepend analysis">
  <Output TaskParameter="Id" PropertyName="StepId" />
</BuildStep>

<BuildStep
   TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
   BuildUri="$(BuildUri)"
   Id="$(StepId)"
   Status="Failed" />

但是,这段代码不会引发任何问题:

<BuildStep
   TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
   BuildUri="$(BuildUri)"
   Id="$(StepId)"
   Status="Succeeded" />

我只是不明白为什么一个可以正常工作,而布局几乎相同的 BuildStep 标签却不能。有什么简单的东西我只是忽略了吗?

编辑:这是它的整体外观,如果这有所不同:

  <Target Name="NDepend"  >
    <PropertyGroup>
      <NDPath>c:\tools\NDepend\NDepend.console.exe</NDPath>
      <NDProject>$(SolutionDir)MyProject.ndproj</NDProject>
      <NDOut>$(TargetDir)NDepend</NDOut>
      <NDIn>$(TargetDir)</NDIn>
    </PropertyGroup>
    <Exec
      Command='"$(NDPath)" "$(NDProject)" /OutDir "$(NDOut)" /InDirs "$(NDIn)"'/>
  </Target>
  <Target Name="AfterBuild">
    <BuildStep         TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
        BuildUri="$(BuildUri)"
        Message="Running NDepend analysis">
      <Output TaskParameter="Id" PropertyName="StepId" />
    </BuildStep>
    <PropertyGroup>
      <NDPath>c:\tools\NDepend\NDepend.console.exe</NDPath>
      <NDProject>$(SolutionRoot)\Main\src\MyProject.ndproj</NDProject>
      <NDOut>$(BinariesRoot)\NDepend</NDOut>
      <NDIn>$(BinariesRoot)\Release</NDIn>
    </PropertyGroup>
    <Exec
      Command='$(NDPath) "$(NDProject)" /OutDir "$(NDOut)" /InDirs "$(NDIn)"'/>
    <BuildStep
        TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
        BuildUri="$(BuildUri)"
        Id="$(StepId)"
        Status="Succeeded" />
    <OnError ExecuteTargets="MarkBuildStepAsFailed" />
  </Target>

  <Target Name="MarkBuildStepAsFailed">
    <BuildStep
        TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
        BuildUri="$(BuildUri)"
        Id="$(StepId)"
        Status="Failed" />
  </Target>

编辑:添加了赏金,因为我真的需要为我的团队实现这一目标。

编辑:包括更多关于错误的细节,出于版权原因,我用“blah”伪装了文件的位置/名称,我不确定我在技术上是否能够发布该信息,所以我我宁愿安全也不愿后悔,但如果为了解决这个问题你绝对必须知道,我会看看我能做些什么。失败的团队构建结果中列出了以下错误以及其他各种警告,但这些错误是我能看到的与上面的 NDepend XML 代码有关的唯一错误。

我在运行团队构建时遇到的错误:

C:*Blah*.csproj (172): The "BuildStep" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with in the project file, or in the *.tasks files located in the "c:\Windows\Microsoft.NET\Framework\v4.0.30319" directory.

C:*Blah*.csproj (194): The "BuildStep" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with in the project file, or in the *.tasks files located in the "c:\Windows\Microsoft.NET\Framework\v4.0.30319" directory.

编辑:我以为它运行正常,但它仍然没有正常构建。尽管模仿了@Ewald 在下面建议的 XML,但在我构建时它仍然会抛出上面的错误。我根据我认为应该工作的方式调整了所述代码的属性值,如下所示:

  <Target Name="NDepend"  >
    <PropertyGroup>
      <NDPath>c:\tools\NDepend\NDepend.console.exe</NDPath>
      <NDProject>$(SolutionDir)MyProject.ndproj</NDProject>
      <NDOut>$(TargetDir)NDepend</NDOut>
      <NDIn>$(TargetDir)</NDIn>
    </PropertyGroup>
    <Exec
      Command='"$(NDPath)" "$(NDProject)" /OutDir "$(NDOut)" /InDirs "$(NDIn)"'/>
  </Target>

  <Target Name="AfterBuild">
    <BuildStep         
        TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
        BuildUri="$(BuildUri)"
        Name="CallMyTarget"
        Message="Call My Target"
        Condition="'$(IsDesktopBuild)'!='true'">
      <Output TaskParameter="Id" PropertyName="StepId" />
    </BuildStep>
    <CallTarget Targets="NDepend" ContinueOnError="false"/>
    <BuildStep
        TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
        BuildUri="$(BuildUri)"
        Id="$(StepId)"
        Status="Succeeded"
        Condition="'$(IsDesktopBuild)'!='true'" />
    <OnError ExecuteTargets="FailStep" />
  </Target>

  <Target Name="FailStep">
    <BuildStep
        TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
        BuildUri="$(BuildUri)"
        Id="$(StepId)"
        Status="Failed"
        Condition="'$(IsDesktopBuild)'!='true'" />
  </Target>

但是,我确实尝试将这段代码放入:

  <Target Name="NDepend"  >
    <PropertyGroup>
      <NDPath>c:\tools\NDepend\NDepend.console.exe</NDPath>
      <NDProject>$(SolutionDir)MyProject.ndproj</NDProject>
      <NDOut>$(TargetDir)NDepend</NDOut>
      <NDIn>$(TargetDir)</NDIn>
    </PropertyGroup>
    <Exec
      Command='"$(NDPath)" "$(NDProject)" /OutDir "$(NDOut)" /InDirs "$(NDIn)"'/>
  </Target>

自动构建很顺利,没有错误,但 NDepend 只是没有按预期运行。

我开始怀疑(在咨询了各种其他子问题之后)TFS2010 与 TFS2008 中使用的 XML 架构是否存在一些细微差异导致我遇到这些问题。那么,考虑到这一点,有没有人知道这些架构中的任何重大差异?

编辑:为了让大家了解我尝试过的所有内容,我现在尝试了这段代码:

<Target Name="AfterBuild">
    <PropertyGroup>
      <NDPath>c:\tools\NDepend\NDepend.console.exe</NDPath>
      <NDProject>$(SolutionDir)MyProject.ndproj</NDProject>
      <NDOut>$(TargetDir)NDepend</NDOut>
      <NDIn>$(TargetDir)</NDIn>
    </PropertyGroup>
    <Exec
      Command='"$(NDPath)" "$(NDProject)" /OutDir "$(NDOut)" /InDirs "$(NDIn)"'/>
</Target>

它产生了不同的错误消息,如下所示:

C:*Blah*.csproj (179): The command ""c:\tools\NDepend\NDepend.console.exe" "C:*Blah*\Sources\Main\MyProject.ndproj" /OutDir "C:*Blah*\Binaries\Debug\NDepend" /InDirs "C:*Blah*\Binaries\Debug\"" exited with code 1.

编辑:我试过的最新代码。这是(根据 NDepend 的网站)“内置 NDepend MSBuild 任务”。

<Target Name="AfterBuild">
    <PropertyGroup>
        <NDPath>c:\tools\NDepend\NDepend.console.exe</NDPath>
        <NDProject>$(SolutionDir)MyProject.ndproj</NDProject>
      </PropertyGroup>
      <UsingTask AssemblyFile="$(NDPath)\MSBuild\NDepend.Build.MSBuild.dll"
             TaskName="NDependTask" />
      <Target Name="NDepend"  >
        <NDependTask NDependConsoleExePath="$(NDPath)"
           ProjectFilePath="$(NDProject)" />
      </Target>
</Target>

但是我得到这个错误:

C:*Blah*.csproj (180): The element beneath element is unrecognized.

最佳答案

我使用以下代码行来实现额外的构建步骤

<Target Name="Customization">
    <BuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)" Name="CallMyTarget" Message="Call my target" Condition="'$(IsDesktopBuild)'!='true'" >
        <Output TaskParameter="Id" PropertyName="CurrentBuildStepId" />
    </BuildStep>

    <CallTarget Targets="MyTarget" ContinueOnError="false"/>

    <BuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)" Id="$(CurrentBuildStepId)" Status="Succeeded" Condition="'$(IsDesktopBuild)'!='true'" />

    <OnError ExecuteTargets="FailStep"/>
</Target>

<Target Name="FailStep">
    <BuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)" BuildUri="$(BuildUri)" Id="$(CurrentBuildStepId)" Status="Failed" Condition="'$(IsDesktopBuild)'!='true'" />
</Target>

关于xml - TFS 2010/代码度量集成,自动构建失败,代码度量不运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4620439/

相关文章:

java - 无法实例化 MessageBodyReader 错误

工作项的 TFS 权限

svn - 大量使用 TortoiseSVN/Subversion 锁定 NT 用户帐户

git - 使用带有 Git 和 NAnt 的 TeamCity 设置 CI

tfs - VS 2010,TFS 2013 SGEN : An attempt was made to load an assembly with an incorrect format

java - 在多台 Windows 机器上自动安装基于 Java 的软件

java - 将 Java DOM 文档序列化为 XML : Add CData Elements

java - 无法根据导入的 XSD 进行验证

xml - 我如何拆分 <xsl :foreach> into multiple parts?

powershell - 如何从 TFS 构建过程将参数传递给 PowerShell 脚本?