Integrating Code Metrics in TFS 2010 Build
-
Thursday, April 19, 2012 6:50 AM
Hi,
I have integrated code metrics in TFS 2010 build and able to generate MetricsResults.xml successfully. But the xml file is empty. When I run through VS IDE, it is giving metrics for that project. I have followed below 2 articles. But getting same empty result file for both the methods. Please let me know what could be the problem.
Thanks in advance.
Radhika.
Radhika
- Edited by rkilaru Thursday, April 19, 2012 6:51 AM
All Replies
-
Monday, April 23, 2012 7:12 AMModerator
Hi Radhika,
Thanks for your post.
I’m currently following that article(first blog) to integrating Code Metrics in my Team Build, try to reproduce this scenario in my TFS 2010 Build.
Can you ensure you followed the exactly the same steps in first blog to integrate code metrics in your TFS 2010 Build? If you have any further research of this issue, please share your experience here.
And you also can new a comment about this issue in that blog.
John Qiao [MSFT]
MSDN Community Support | Feedback to us
-
Tuesday, April 24, 2012 11:20 AMModerator
Hi Radhika,
I exactly followed first blog to custom my DefaultTemplate.xaml and queue the build definition, the CodeMetricsResult.xml file generated under the Binaries folder, and has the right content in it. The method which in first blog works fine in my Team Build 2010.
John Qiao [MSFT]
MSDN Community Support | Feedback to us
-
Thursday, April 26, 2012 12:27 AMHave you tried running Metrics.exe from command prompt with your argument settings to verify result?
-7
-
Monday, May 07, 2012 11:17 AMI am getting same empty output with command prompt. I tried it for multiple projects also, but the output is empty xml file.
Radhika
-
Monday, May 07, 2012 11:16 PMPost your arguments.
-7
-
Tuesday, May 08, 2012 8:00 AM
On a side note, the Community TFS Build Extensions now contains a custom activity that wraps the execution of CodeMetrics. Check out the documentation here:
http://tfsbuildextensions.codeplex.com/wikipage?title=How%20to%20integrate%20the%20codemetric%20build%20activity&referringTitle=DocumentationMicrosoft Community Contributor Award 2011
Visual Studio ALM Ranger
Blog: http://geekswithblogs.net/jakob
Twitter: http://twitter.com/jakobehn -
Tuesday, May 08, 2012 10:06 AMI am unable to download the document. I am not getting download option itself.
Radhika
-
Tuesday, May 08, 2012 11:46 AM
You mean the command that I used to calculate code metrics. Please let me know if i misunderstand your question. Here is the command.
Navigate to the folder where the assembly resides. then
metrics.exe /f:AdminUtility.exe /o:MetricsResults.xml
Radhika
-
Tuesday, June 12, 2012 6:55 PM
Hi,
I have integrated code metrics in TFS 2010 build and able to generate MetricsResults.xml successfully. But the xml file is empty. When I run through VS IDE, it is giving metrics for that project. I have followed below 2 articles. But getting same empty result file for both the methods. Please let me know what could be the problem.
Thanks in advance.
Radhika.
Radhika
I'm having the same issue. I jumped over to my build server to see what was causing the empty xml file to be produced, and found that if there were ANY errors, it would be empty. If I ran the metrics on a single DLL that I knew had a .pdb file, it worked. If it ran against other .dlls in the folder (referenced, 3rd-party dlls), then it would throw an error.
It would be nice if there were a flag to ignore errors for those DLLs that I don't have control over. As it stands, this becomes a useless tool for me.
Any ideas?
Jim Roth
-
Tuesday, June 12, 2012 7:35 PM
You don't need the pdb files. Code Metrics will throw a warning CA0068 but not an error. Your errors are likely caused by missing references.
-7
-
Tuesday, June 12, 2012 7:37 PM
Have you tried running with explicit paths to file in the arguments?
Have you been able to run in the cmd window with success?
-7
-
Wednesday, October 17, 2012 1:31 PMSorry for the late reply. I was working on some other issues and now I am back to this. I still have this issue. When I tried with command (
metrics.exe /f:AdminUtility.exe /o:MetricsResults.xml), it is giving metrics properly but when tried with TFS build, i am getting empty xml file. below is my logfile content.
Overall Build Process
00:01
Update Build Number00:01
Create the Drop Location01:31
Run On Agent (reserved build agent HOSTDEV - Agent1)00:00
Delete Test Results Directory00:00
Delete Binaries Directory00:01
Delete Workspace00:00
Delete Sources Directory00:02
Create Workspace00:08
Get Workspace00:00
Create Label
Label Bank_20121017.12@$/Sample (version W1260_66_HOSTDEV;LR\svconehostdev) was successfully created.00:40
Compile, Test, and Associate Changesets and Work Items00:39
Compile and Test00:13
If Local File Doesn't Exist00:12
Run MSBuild for Project
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe /nologo /noconsolelogger "C:\Builds\66\Sample\Bank\Sources\Bank.sln" /m:1 /fl /flp:"logfile=C:\Builds\66\Sample\Bank\Sources\Bank.log;encoding=Unicode;verbosity=normal" /p:SkipInvalidConfigurations=true /p:OutDir="C:\Builds\66\Sample\Bank\Binaries\\" /p:VCBuildOverride="C:\Builds\66\Sample\Bank\Sources\Bank.sln.vsprops" /dl:WorkflowCentralLogger,"C:\Program Files\Microsoft Team Foundation Server 2010\Tools\Microsoft.TeamFoundation.Build.Server.Logger.dll";"Verbosity=Normal;BuildUri=vstfs:///Build/Build/114751;InformationNodeId=13056312;TargetsNotLogged=GetNativeManifest,GetCopyToOutputDirectoryItems,GetTargetPath;TFSUrl=http://tfstta.int.thomson.com:8080/tfs/DefaultCollection;"*WorkflowForwardingLogger,"C:\Program Files\Microsoft Team Foundation Server 2010\Tools\Microsoft.TeamFoundation.Build.Server.Logger.dll";"Verbosity=Normal;"00:02
Built $/2010Test/Bank/Bank.sln for default targets.00:00
Built $/2010Test/Bank/Bank/Bank.csproj for default targets.00:00
Built $/2010Test/Bank/Bank.Tests/Bank.Tests.csproj for default targets.00:00
Built $/2010Test/Bank/Bank/Bank.csproj for default targets.
MSBuild Log File00:02
If CheckCodeMetrics is True00:02
Run Code Mertics for Output Dll's and Exe's00:01
Run Metrics.exe Power Tool
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\metrics /f:"C:\Builds\66\Sample\Bank\Binaries\*.dll" /f:"C:\Builds\66\Sample\Bank\Binaries\*.exe" /out:"C:\Builds\66\Sample\Bank\Binaries\CodeMetricsResult.xml" /successfile00:21
Run MSTest for Test Assemblies
The MSTestActivity was invoked without a value for Platform or Flavor. The values Any CPU and Debug were used.
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe /nologo /usestderr /testSettings:"C:\Builds\66\Sample\Bank\Sources\Local.testsettings" /searchpathroot:"C:\Builds\66\Sample\Bank\Binaries" /resultsfileroot:"C:\Builds\66\Sample\Bank\TestResults" /testcontainer:"C:\Builds\66\Sample\Bank\Binaries\Bank.Tests.dll" /publish:"http://tfs.com:8080/tfs/DefaultCollection" /publishbuild:"vstfs:///Build/Build/114751" /teamproject:"Sample" /platform:"Any CPU" /flavor:"Debug"
Loading C:\Builds\66\Sample\Bank\Sources\Local.testsettings...
Loading C:\Builds\66\Sample\Bank\Binaries\Bank.Tests.dll...
Starting execution...
The test settings file you are using specifies to run tests with code coverage enabled. To use this feature, Visual Studio Premium or Visual Studio Ultimate is required. The tests will be run without code coverage enabled.Results Top Level Tests
------- ---------------
Passed Bank.Tests.BankAccountTest.CreditTest
Passed Bank.Tests.BankAccountTest.CustomerNameTest
Passed Bank.Tests.BankAccountTest.DebitTest
Passed Bank.Tests.BankAccountTest.FreezeAccountTest
4/4 test(s) PassedSummary
-------
Test Run Completed.
Passed 4
---------
Total 4
Results file: C:\Builds\66\Sample\Bank\TestResults\svconehostdev_HYD-1HOSTDEV-S 2012-10-17 18_42_14_Any CPU_Debug.trx
Test Settings: Local
Waiting to publish...
Publishing results of test run svconehostdev@HOSTDEV 2012-10-17 18:42:14_Any CPU_Debug to http://tfs.com:8080/tfs/DefaultCollection...
...........Publish completed successfully.00:05
Associate Changesets and Work Items
Analyzing labels Bank_20121017.5 and Bank_20121017.12.00:09
Get Impacted Tests, Index Sources and Publish Symbols00:06
Get Impacted Tests00:01
Index Sources
C:\Program Files\Microsoft Team Foundation Server 2010\Tools\srctool.exe C:\Builds\66\Sample\Bank\Binaries\Bank.pdb -r
C:\Program Files\Microsoft Team Foundation Server 2010\Tools\pdbstr.exe -w -p:C:\Builds\66\Sample\Bank\Binaries\Bank.pdb -i:C:\Users\svconehostdev\AppData\Local\Temp\tmp12DD.tmp -s:srcsrv
C:\Program Files\Microsoft Team Foundation Server 2010\Tools\srctool.exe C:\Builds\66\Sample\Bank\Binaries\Bank.Tests.pdb -r
C:\Program Files\Microsoft Team Foundation Server 2010\Tools\pdbstr.exe -w -p:C:\Builds\66\Sample\Bank\Binaries\Bank.Tests.pdb -i:C:\Users\svconehostdev\AppData\Local\Temp\tmp156E.tmp -s:srcsrv
C:\Program Files\Microsoft Team Foundation Server 2010\Tools\srctool.exe C:\Builds\66\Sample\Bank\Binaries\Bank_Accessor.pdb -r00:10
Copy Files to Drop Location
Skipped execution of Revert Workspace because of BuildReason Manual
Skipped execution of Check In Gated Changes because of BuildReason ManualSummary
Debug | Any CPU
<dir></dir>0 error(s), 0 warning(s)
1 projects/solutions compiled
1 test run(s) completed - 100% average pass rate (100% total pass rate)
No Code Coverage Results
Impacted Tests
No tests were impacted
- Edited by rkilaru Wednesday, October 17, 2012 1:41 PM
-
Friday, October 19, 2012 3:49 PM
There are a couple things I would try.
1) You should run code metrics from the command line locally on the build agent just after a build. Put a stop just before the code metrics step and then log into the build agent. Check out the build folders and make sure everything is where it is supposed to be. Then open the command prompt and run code metrics with the values you have set in the workflow. You may find errors or warning messages that you were not seeing as part of the build.
2) Try adding a path to dependency file with /d option. If any of the binaries has dependency on assemblies not in the local folder, you can resolve them this way. PDB files go a long way towards this (recommended but not necessary).
-7
- Marked As Answer by rkilaru Monday, October 29, 2012 12:33 PM
-
Monday, October 29, 2012 12:33 PMThank you very much smyrin. your answer helped me in finding out the issue. One of my dll was referering dll which was not found. Now it is generating code metrics properly.
Now I need to integrate these metrics with Sonar Source tool. Anyone is having any idea?Radhika

