Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add multiple assemblies in assemblyfilters #84

Closed
madhurbhandarkumthe opened this issue Feb 24, 2017 · 14 comments
Closed

How to add multiple assemblies in assemblyfilters #84

madhurbhandarkumthe opened this issue Feb 24, 2017 · 14 comments
Labels

Comments

@madhurbhandarkumthe
Copy link

Hi daniel,

I have two doubts

  1. I want to add multiple assemblies in the assemblyfilter,but at present it only takes the first assembly
    For example ,
    currrently i an using following powershell command
    ReportGenerator.exe" -reports:"coverage.xml" -targetdir:Coverage -assemblyfilters:-tests;-fluentassertions*

but the final report only filters out the test assemly dll and not the fluentassertions.
Is there any syntax error ,if yes then please specify the correct way to do this.

  1. Also is there any way to use the output of report generator to add a build failure condition in teamcity
    for example:
    If the codecoverage is 40% ,then is there any way that i can add condition in teamcity build so that this build fails for codecoverage less than say 50%.

Thanks in advance :)

@danielpalme
Copy link
Owner

Regarding 1.
The Syntax should be correct. Can you tell me the full name of one of the assemblies that does not get filtered?

Regarding 2.
You could create a custom report that passes the overall coverage ratio to TeamCity.
Perhaps TeamCity is able to read the value from a text file? Or maybe you can write the value to an environment variable?!

Here's some sample code to generate a text file containing the coverage ratio:

using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using Palmmedia.ReportGenerator.Parser.Analysis;
using Palmmedia.ReportGenerator.Properties;

namespace Palmmedia.ReportGenerator.Reporting
{
    /// <summary>
    /// Creates text file containing overall coverage ratio.
    /// </summary>
    [Export(typeof(IReportBuilder))]
    public class CoverageRatioReportBuilder : IReportBuilder
    {
        /// <summary>
        /// Gets the report type.
        /// </summary>
        /// <value>
        /// The report type.
        /// </value>
        public string ReportType => "CoverageRatio";

        /// <summary>
        /// Gets or sets the target directory where reports are stored.
        /// </summary>
        /// <value>
        /// The target directory.
        /// </value>
        public string TargetDirectory { get; set; }

        /// <summary>
        /// Creates a class report.
        /// </summary>
        /// <param name="class">The class.</param>
        /// <param name="fileAnalyses">The file analyses that correspond to the class.</param>
        public void CreateClassReport(Class @class, IEnumerable<FileAnalysis> fileAnalyses)
        {
        }

        /// <summary>
        /// Creates the summary report.
        /// </summary>
        /// <param name="summaryResult">The summary result.</param>
        public void CreateSummaryReport(SummaryResult summaryResult)
        {
            if (summaryResult == null)
            {
                throw new ArgumentNullException(nameof(summaryResult));
            }

            string targetPath = Path.Combine(this.TargetDirectory, "CoverageRatio.txt");
            File.WriteAllText(targetPath, summaryResult.CoverageQuota.GetValueOrDefault().ToString("f0", CultureInfo.InvariantCulture));
        }
    }
}

@madhurbhandarkumthe
Copy link
Author

madhurbhandarkumthe commented Feb 25, 2017

1)currently the dlls which are not getting filtered out are "fluentassertions.core.dll","fluentassertions.dll".
However i have noticed that if i put the assembly filters in the order assemblyfilters:-fluentassertions*;-tests
then the tests dll doesn't get filtered out.so i guess currently it is only taking the first filter from the assemblyfilters list.

2)regarding the teamcity ,i will try out your solution and update you once its done.

Thanks for your quick response.

@danielpalme
Copy link
Owner

danielpalme commented Feb 27, 2017

  1. I just tried this again. It works fine for me with both filters.
    Can you please send me your coverage file. That would help me to debug with the same input you have.

  2. That would be great

@madhurbhandarkumthe
Copy link
Author

1.so the problem was with the syntax of powershell command.Had to surround assembly filter vaules with double quotes
eg :
-assemblyfilters:-tests;-fluentassertions* didn't work.
-assemblyfilters:"-tests;-fluentassertions*" worked.
In first case powershell considered ';' as end of statement,so only first assembly was getting filtered.

2.I wrote powershell script which had following steps
i)parse the out file to get the final line coverage value
ii)compare this value with the minimum required line coverage value
iii)using the teamcity service message echoed error on teamcity stdout
script for the same is as follows
Write-Host "##teamcity[message text='errorMessage ' errorDetails='' status='ERROR']"

And in the teamcity build definition added failure condition which will check for specific text in build log.

@danielpalme
Copy link
Owner

Perfect, then I can close this issue?

I think double quotes work best if placed before the complete argument, e.g.:

"-assemblyfilters:-tests;-fluentassertions*"

Also see usage section here:
https://github.com/danielpalme/ReportGenerator#usage

@TroySchmidt
Copy link

Need to reopen this. When using the Azure DevOps Extension there is no way for you to surround the parameters with " so it always only picks the first exclude (or include). There isn't a way to supply multiple filters.

@danielpalme danielpalme reopened this Jul 10, 2019
@danielpalme
Copy link
Owner

I will investigate this within the next days.

@danielpalme
Copy link
Owner

Could you please try again by triggering the build on Azure DevOps?
I published a new release which should fix the issue.

@TroySchmidt
Copy link

TroySchmidt commented Jul 11, 2019

Tested it and doesn't appear to be fixed. This is what is showing in the log for the translated command line that gets executed.

This is my task in the YAML.

- task: reportgenerator@4
    inputs:
      reports: '$(Build.SourcesDirectory)/**/coverage.cobertura.xml'
      targetdir: '$(Build.SourcesDirectory)/CodeCoverage'
      reporttypes: 'HtmlInline_AzurePipelines_Dark;Cobertura;Badges'
      assemblyfilters: '-Dapper.*;-Dommel.*'
:\Program Files\dotnet\dotnet.exe" D:\agent\_work\_tasks\reportgenerator_be803a55-9253-4895-a525-be570d86f161\4.2.7\tools\netcoreapp2.1\ReportGenerator.dll "\"-reports:D:\agent\_work\10\s/**/coverage.cobertura.xml\"" "\"-targetdir:D:\agent\_work\10\s/CodeCoverage\"" "\"-reporttypes:HtmlInline_AzurePipelines_Dark;Cobertura;Badges\"" "\"-sourcedirs:\"" "\"-historydir:\"" "\"-plugins:\"" "\"-assemblyfilters:-Dapper.*;-Dommel.*\"" "\"-classfilters:+*\"" "\"-filefilters:+*\"" "\"-verbosity:Verbose\"" "\"-tag:RCRMS Release Build_#1432\""

@danielpalme
Copy link
Owner

Can you please test once again.
The log should now contain the list of arguments that ReportGenerator receives. E.g.

Arguments
 -reports:coverage.cobertura.xml
 -targetdir:CodeCoverage
 -reporttypes:HtmlInline_AzurePipelines_Dark;Cobertura;Badges
 -sourcedirs:
 -historydir:
 -plugins:
 -assemblyfilters:-Dapper.*;-Dommel.*
 -filefilters:+*
 -verbosity:Verbose
 -tag:RCRMS Release Build_#1432

@TroySchmidt
Copy link

TroySchmidt commented Jul 11, 2019


:\Program Files\dotnet\dotnet.exe" D:\agent\_work\_tasks\reportgenerator_be803a55-9253-4895-a525-be570d86f161\4.2.8\tools\netcoreapp2.1\ReportGenerator.dll -reports:D:\agent\_work\10\s/**/coverage.cobertura.xml -targetdir:D:\agent\_work\10\s/CodeCoverage -reporttypes:HtmlInline_AzurePipelines_Dark;Cobertura;Badges -sourcedirs: -historydir: -plugins: -assemblyfilters:-Dapper.*;-Dommel.* -classfilters:+* -filefilters:+* -verbosity:Verbose "-tag:RCRMS Release Build_#1435" |  
-- | --
  | Arguments |  
  | -reports:D:\agent\_work\10\s/**/coverage.cobertura.xml |  
  | -targetdir:D:\agent\_work\10\s/CodeCoverage |  
  | -reporttypes:HtmlInline_AzurePipelines_Dark;Cobertura;Badges |  
  | -sourcedirs: |  
  | -historydir: |  
  | -plugins: |  
  | -assemblyfilters:-Dapper.*;-Dommel.* |  
  | -classfilters:+* |  
  | -filefilters:+* |  
  | -verbosity:Verbose |  
  | -tag:RCRMS Release Build_#1435 |  
  | Loading report 'D:\agent\_work\10\s\Tests\Rcrms.DataAccess.Tests\coverage.cobertura.xml' 1/2 |  
  | Preprocessing report |  
  | Initiating parser for Cobertura |  
  | Current Assembly: Dommel |  
  | Current Assembly: Rcrms.DataAccess |  
  | Current Assembly: Rcrms.Entities |  
  | Loading report 'D:\agent\_work\10\s\Tests\Rcrms.DataAccess.Tests\results\coverage.cobertura.xml' 2/2 |  
  | Preprocessing report |  
  | Initiating parser for Cobertura |  
  | Current Assembly: Dommel |  
  | Current Assembly: Rcrms.DataAccess |  
  | Current Assembly: Rcrms.Entities |  
  | Coverage report parsing took 0.4 seconds |  
  | Initializing report builders for report types: HtmlInline_AzurePipelines_Dark, Cobertura, Badges |  
  | Analyzing 216 classes |  
  | Creating report 1/216 (Assembly: Dommel, Class: Dommel.DefaultColumnNameResolver) |  
  | Writing report file 'Dommel_DefaultColumnNameResolver.htm' |  
  | Creating report 2/216 (Assembly: Dommel, Class: Dommel.DefaultForeignKeyPropertyResolver) |  
  | Writing report file 'Dommel_DefaultForeignKeyPropertyResolver.htm' |  
  | Creating report 3/216 (Assembly: Dommel, Class: Dommel.DefaultKeyPropertyResolver)


Still not working. It isn't wrapping the assemblyfilters option in quotes. So it still only processes the -Dapper.* and not the second -Dommel.* filter. Is there a different separator besides ; to use? What I understand that might resolve this is if the entire assemblyfilters option was surrounded with quotes(") in the command line where it passes it to the DLL. That still isn't happening right now when using the task. That still isn't wrapped. It could also be there is a problem with dotnet.exe and the additional parameters passing that is filtering it out when there is a semicolon.

@danielpalme
Copy link
Owner

Ok, The arguments seem to get passed correctly to ReportGeneratorr:

| -assemblyfilters:-Dapper.*;-Dommel.* |  

The problem is probably the filter definition itself.
The filters are not interpreted as regular expressions but as text with wildcards.
In your case Dommel.* does not match the assembly Dommel, it would only match Dommel.XYZ.

If you change the filter to -assemblyfilters:-Dapper.*;-Dommel or -assemblyfilters:-Dapper.*;-Dommel* it should work as expected.

@TroySchmidt
Copy link

TroySchmidt commented Jul 12, 2019 via email

@TroySchmidt
Copy link

Close this as resolved. Works!! Thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants