TFS 2010 / Code metrics integration, automatic build failures, code metrics not starting

I am trying to add an automatic trigger after build to start NDepend (code metric software) after creating an automatic command in TFS 2010.

The NDepend website provided code to integrate this feature, and so I pasted their code into my .csproj file, where they said that it should go, but I get errors in the assembly.

Errors relate to two of the three BuildStep tags that I have in the code snippet. The following two snippets give me errors:

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

and

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

However, this piece of code does NOT throw any problems:

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

I just don’t understand why one works fine, and the almost identical BuildStep tag does not. Is there something simple that I just don’t notice?

EDIT: this is how it looks together if it matters:

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

EDIT: Added generosity because I really need to do this for my team.

EDIT: More features are included about errors, I masked the location / filename of the blah file for copyright reasons, I'm not sure if I can technically release this information, so I'm wrong on the security side, not apologizing, but if you absolutely must know for the sake of eliminating this problem, I will see what I can do. The following errors were indicated in the results of the failed build of the command, as well as in various other warnings, but these errors were the only ones that I could see related to the above NDepend XML code.

Errors that occur when you run the build command:

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

and

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

EDITOR: I thought everything was working fine for me, but this threshold is not building properly. It still raises errors higher when I build, despite imitating @Ewald suggested the XML below. I adjusted the property values ​​of the specified code in accordance with what I think will work as follows:

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

However, I tried to just put this code in:

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

And the automatic build went fine, no errors, but NDepend just didn't start as intended.

I am starting to wonder (after consulting with other other questions) if there is a slight difference in the XML schema used in TFS2010 vs TFS2008 that causes me these problems. So, with that in mind, does anyone know of any big differences in these schemes?

EDIT: just keeping you up to date with everything I tried, I now tried this code:

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

, and he produced another error message as follows:

C: * Blah * .csproj (179): command "C: \ Tools \ NDepend \ NDepend.console.exe" "C: * L * \ Sources \ Main \ MyProject.ndproj" / OutDir "C: * L * \ Binary \ Debug \ NDepend "/ InDirs" C: * L * \ Binary \ Debug \ "" exited with code 1.

EDIT: The last code I tried. It was (according to the NDepend site) the "NDepend MSBuild built-in task."

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

But I get this error:

C: * Blah * .csproj (180): the element under the element is not recognized.

+4
source share
2 answers

I use the following lines of code to achieve additional build steps

 <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> 
+1
source

Code snippets only work when Team Build starts. They probably won't succeed when you start the desktop build. You can safely delete these lines, because all they do is add the line to the build log if you use Team Buid.

0
source

Source: https://habr.com/ru/post/1334583/


All Articles