stryker-net: TargetFramework cannot be set in Directory.Build.props
Describe the bug
When <TargetFramework> is set in Directory.Build.props Stryker doesn’t work.
Logs
I have a a solution folder with a Directory.Build.props that specifies <TargetFramework>net9.0</TargetFramework> and there are no <TargetFramework> in the .csproj files. The project to mutate and the unit test project are in subdirectories and the unit test project has a reference to the project to mutate. When executing dotnet stryker --verbosity debug in the unit test project I get the following console output:
[13:07:16 INF] Logging enabled at level Debug Version: 4.4.1 [13:07:16 DBG] Stryker starting, version: 4.4.1 [13:07:16 DBG] Stryker started with options: [REMOVED FOR BREVITY] [13:07:16 INF] Analysis starting. [13:07:16 DBG] Using C:\Users\[REDACTED]\[REDACTED].UnitTests\[REDACTED].UnitTests.csproj as test project [13:07:16 INF] Analyzing 1 test project(s). [13:07:16 DBG] Analyzing 0 projects. [13:07:16 DBG] Analyzing [REDACTED].UnitTests.csproj [13:07:22 DBG] Analysis of project [REDACTED].UnitTests.csproj succeeded. [13:07:23 DBG] Analyzing ..\[REDACTED]\[REDACTED].csproj [13:07:29 DBG] Analysis of project ..\[REDACTED]\[REDACTED].csproj succeeded. [13:07:29 INF] Analysis complete. [13:07:29 INF] Time Elapsed 00:00:13.2623456 Stryker.NET failed to mutate your project. For more information see the logs below: No project references found. Please add a project reference to your test project and retry.
Expected behavior
According to the logs Stryker correctly detects the project to mutate and should go ahead and perform the tests.
Adding <TargetFramework>net9.0</TargetFramework> to both .csproj files fixes the problem.
Desktop
- OS: Windows
- Type of project: “core”
- Framework Version: .NET 9.0
- Stryker Version: 4.4.1
Additional context
I haven’t tried to locate the actual problem in the source code. Even if it’s not worth fixing it might be helpful to explain this in the documentation. This is my first time using Stryker and it took me quite some time to understand why my project didn’t work with Stryker despite following the clear and useful instructions in “Getting started”.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 21 (19 by maintainers)
I dug further into this and I think I fully understand the problem now:
issue summary
Stryker may fail to analyze or build a project when the target framework is not explicitly specified in the relevant project file.
underlying cause: Buildalyzer automatic build environment selection logic:
Buildalyzer may fail to automatically select the proper build environment if the target framework is specified in the project file.
fix: won’t be fixed
This is a more of an enhancement than a fix: Buildalyzer should replicate the search and parsing logic of ‘Directory.Build.Props’ as done by latest SDKs. This requires significant work and would not be a future proof solution so I see no path forward on this. This is to be understood as a limitation of automatic build environment resolution.
therorical solution: via configuration
The proper way to address this is to ask the user the specify which msbuild version to use. Stryker offers the
msbuild-pathoption to allow one to select the version of it’s choosing. Alas, this option is not forwarded to Buildalyzer, if I understand the code correctly. I will open an issue for this.workaround: use
targetframeworkoptionThat being said, forcing user to specify the msbuild path is not practical as the exact path will depend on the machine configuration, so Stryker should try to overcome this without machine specific configuration.
One way to deal with that is to restore the behavior from earlier version when the target framework was forwarded to Buildalyzer. As such, it picks the proper msbuild version and everything runs smoothly afterward.
I have a PR for that which is almost ready: the targetframework option is forwarded to Buildalyzer when automatic mode fails.
for information cc @rouke-broersma @richardwerkman @Mobrockers
@rouke-broersma Not all of our project are able to target the same framework. Analyzer projects, for example, must target netstandard2.0 for VS compatibility.
Nonetheless, I will attempt to get a minimal repro of this issue.
thanks, I think I have enough information to reproduce this. I will get back to you if I need anything more.
Note that current Stryker releases do not support top-level statements… This will be fixed in next release.
Thanks for raising this issue. We will look into it. We may need more information if we fail to reproduce the problem.
Note that the issue may likely be within the Buildalyzer package Stryker uses for project analysis.
See https://github.com/phmonte/Buildalyzer/issues/166