DanielHWe / sonar-fxcop

FxCop plugin for C# or VB.NET projects
13 stars 6 forks source link

Support multiple frameworks #25

Closed TAGrimm closed 5 years ago

TAGrimm commented 5 years ago

Hello, we are using your plugin to analyze our projects and we have started to use the new csproj format. We came across the problem that the following project is found by your plugin:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <ProjectGuid>{09806BDD-A731-405F-A31D-C83899C8850A}</ProjectGuid>
  </PropertyGroup>

</Project>

And it produces the following output:

14:02:43.876 DEBUG: Add 'E:\_1\23\s\source\SingleTarget\SingleTarget.csproj' to FxCop configuration.
14:02:43.876 DEBUG: Found TargetFramework (netcoreapp2.0)
14:02:43.876 DEBUG: Set Outputpath to default
14:02:43.876 DEBUG: Set OutputType to default (Library)
14:02:43.876 DEBUG: Set AssemblyName to default (SingleTarget)
##[error]14:02:43.876 WARN: .net core is not supported by FxCop - project E:\_1\23\s\source\SingleTarget\SingleTarget.csproj ignored.

(I know there is an issue about supporting .net core but my problem is different)

When using multi targeting and changing TargetFramework to TargetFrameworks the project creates a parsing error:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>netcoreapp2.0;net452</TargetFrameworks>
    <ProjectGuid>{09806BDD-A731-405F-A31D-C83899C8850A}</ProjectGuid>
  </PropertyGroup>

</Project>
14:02:43.876 DEBUG: Add 'E:\_1\23\s\source\MultiTarget\MultiTarget.csproj' to FxCop configuration.
##[error]14:02:43.876 WARN: No output path found for 'E:\_1\23\s\source\MultiTarget\MultiTarget.csproj'.
14:02:43.876 WARN: No output path found for 'E:\_1\23\s\source\MultiTarget\MultiTarget.csproj'.
##[error]14:02:43.876 WARN: Ignore 'E:\_1\23\s\source\MultiTarget\MultiTarget.csproj' due to parsing error.
14:02:43.876 WARN: Ignore 'E:\_1\23\s\source\MultiTarget\MultiTarget.csproj' due to parsing error.
##[error]14:02:43.876 ERROR: No projects found to scan, can not generate FxCop configuration.

From scanning your code I saw in the class CSharpProjectInfo that the pattern Pattern.compile("<TargetFramework>([\\w\\-\\ \\.\\\\]+)</TargetFramework>"); doesn't match with TargetFrameworkS.

Expected behaviour: Find projects which use multiple TargetFrameworks

DanielHWe commented 5 years ago

Projects with multiple TargetFrameworks are not supported now. So I marked this as new enhancement.

If you use a way to define the attributes by command line or SonarQube.Analysis.xml you can use the plugin anyway (then there is no need to scan the project files). How to do this documented in the readme.md.

DanielHWe commented 5 years ago

Added feature to 1.4.2 Snapshot 1, please test.

TAGrimm commented 5 years ago

Thank you for the quick support. I'm happy that my first issue on github was done so fast :) I cannot test your changes until monday.

I saw in your code that you are looking for the target netcore, can you also add netstandard? That would be awesome!

Thank you and have a great weekend!

TAGrimm commented 5 years ago

Today I could test your new code and the project:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>netstandard2.0;net452;net461</TargetFrameworks>
  </PropertyGroup>

</Project>

created the following output:


DEBUG: Add 'E:\_1\23\s\source\MultiTarget\MultiTarget.csproj' to FxCop configuration.
DEBUG: Set OutputType to default (Library)
DEBUG: Set AssemblyName to default (MultiTarget)
DEBUG: Found TargetFramework (net461)
INFO: E:\_1\23\s\source\MultiTarget\bin\Debug\netstandard2.0\MultiTarget.dll
DEBUG: Finish create FxCop configuration 'E:\_1\23\s\source\UnitedGrinding.Framework.Logging.sln.20190107020206.fxcop'

When I shuffle the Targetframeworks only the last one is found. For example with <TargetFrameworks>netstandard2.0;net461;net452</TargetFrameworks> only net452 is found.

DanielHWe commented 5 years ago

Net stadard will be added with next checkin, I did this like that because only one executbale will be scanned and not all of them. Because they do not differ for scan with fxcop.