Buildalyzer icon indicating copy to clipboard operation
Buildalyzer copied to clipboard

.NET MAUI support?

Open mrlacey opened this issue 10 months ago • 3 comments

Apparently, .NET MAUI projects are not supported. (https://github.com/stryker-mutator/stryker-net/issues/3181#issuecomment-2633346545) Is this a known issue? Are there plans to support it? Is this documented anywhere?

mrlacey avatar Feb 04 '25 09:02 mrlacey

I've had a little test with Buildalyzer and StrykerBugRepro, it looks like it will build with Buildalyzer, but only if the net9.0 tfm is specified with the TargetFramework property. I'm testing it like this:

var analyzer = manager.GetProject(path);
var envFactory = new EnvironmentFactory(manager, analyzer.ProjectFile);
var buildEnv =  envFactory.GetBuildEnvironment("net9.0", new EnvironmentOptions
{
    GlobalProperties = { ["TargetFramework"] = "net9.0" } // omitting this fails the build
});
var results = analyzer.Build(buildEnv!);
results.OverallSuccess.ShouldBeTrue();

I'm not sure if Buildalyzer should set this property automatically or if stryker should pass it in, however if I delete the platform specific TFMs from the MAUI app, then stryker gets past the initial build, but now it fails on the mutations compilation with:

Stryker.NET encountered a compile error in .../StrykerBugRepro/StrykerBugRepro/App.xaml.cs (at 5:9) with message: The name 'InitializeComponent' does not exist in the current context (Source code: InitializeComponent)

I'm not sure what's happening here to be honest.

slang25 avatar Feb 05 '25 18:02 slang25

So to break this into actionable things:

  • When Stryker detects a multi-TFM project with a single TFM test project, it should use the test project TFM (passing that to Buildalyzer)
  • Buildalyzer should probably set the TargetFramework property automatically so that multi-target projects build just the requested TFM
  • Buildalyzer shouldn't fail for multi-target builds anyway, even though this isn't what you want to build with Stryker, Buildalyzer should not freak out because of an unexpected output for native TFMs. Specifically here I'm seeing the maccatalyst build fail, and I think this is because the build is doing more stuff, like running the linker, but it's partly a design-time build so the linker fails (as there is no built dll), so I think if we want MAUI builds to work seamlessly for all TFMs (which isn't what you want here for Stryker, but could still be useful to someone) then we should have Buildalyzer detect the native TFMs and disable design-time build settings.
  • That last issue with InitializeComponent needs investigating, I think this might be a Stryker issue (although not sure)

slang25 avatar Feb 05 '25 18:02 slang25

Ok, so I went to add the target framework change I mentioned above (bullet point 2), and it's actually already a thing. There is a Build overload that takes a TFM, so if I do this:

var analyzer = manager.GetProject(path);
var results = analyzer.Build("net9.0");
results.OverallSuccess.ShouldBeTrue();

it also passes. So this will be a change that Stryker can implement. I'll take a quick look at that now 👀

slang25 avatar Feb 06 '25 00:02 slang25