stryker-mutator / stryker-net

Mutation testing for .NET core and .NET framework!
https://stryker-mutator.io
Apache License 2.0
1.76k stars 175 forks source link

Support for solution filters #1924

Closed Kralizek closed 1 year ago

Kralizek commented 2 years ago

Is your feature request related to a problem? Please describe. My solution is divided in several sub solution using solution filters. Currently there is no way to target one of these files when executing stryker.

Describe the solution you'd like I'd like to be able to specify the solution filter file instead of a solution or a project file.

dotnet stryker -s MySolutionFilter.slnf

Describe alternatives you've considered Alternatively I need to create a parallel solution with the subset of projects needed for properly running stryker

rouke-broersma commented 2 years ago

It seems that this is not yet supported in the dotnet-cli so for that reason I doubt that we can support this at this time.

Kralizek commented 2 years ago

Which part of the dotnet-cli needs to support solution filters? dotnet test has support for it.

rouke-broersma commented 2 years ago

A quick Google search suggested dotnet build does not support solution filters.

Kralizek commented 2 years ago

Thanks. I'm not aware of the internals of this amazing library!

Just throwing things in the air: wouldn't be possible to generate a temporary sln file and add the needed projects by reading the slnf one?

I'm thinking of something like

dotnet new sln -n tmp
foreach (proj in slnf.projects)
   dotnet sln add proj.fullPath
dotnet stryker -s tmp

(Very much pseudo code)

rouke-broersma commented 2 years ago

Sure, but it's unlikely we will prioritize something like that over other more widely impactful features or fixes due to limited time.

MathiasSpanhove commented 1 year ago

I've briefly looked at this issue since building a slnf is currently possible. However there is currently no public method available on the SolutionFile that Buildalyzer returns from MSBuild that can be used to find out if a given project is included in the solution filter.

The people at Nuget had the same issue: PR But MSBuild rejected the proposal to make the method public: PR

We could use the same solution that the Nuget team used:

var projectShouldBuildMethod = isSolutionFilter ? solutionFileType.GetMethod("ProjectShouldBuild", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
rouke-broersma commented 1 year ago

@MathiasSpanhove if I understand you correctly this is something that would be contributed to buildalyzer before we can use it, correct?

I would say that if Microsoft does not think that this should be exposed publicly, we should not try to support it.

MathiasSpanhove commented 1 year ago

Technically it needs to be contributed to MSBuild since Buildalyzer returns the MSBuild SolutionFile objects. But I completely understand the reasoning to not implement this 'hack', I just wanted to add some information I found just in case someone else wants to look into this in the future (hopefully MSBuild has better slnf support then)

rouke-broersma commented 1 year ago

@MathiasSpanhove buildalyzer actually does not return msbuild objects unless you use the roslyn workspace extensions. The information is very helpful!

rouke-broersma commented 1 year ago

At this point I don't see a good way to support this, and I personally don't wish to add rebuilding visual studio to the ever growing list of external dependencies we have.