IncludePackageReferencesDuringMarkupCompilation causes excluded NuGet targets/props files to be executed
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
If you conditionally exclude a NuGet package based on whether we're in the wpf MarkupCompile phase (the `_wpftmp` project), any `.targets` or `.props` files in that NuGet packages `build` folder will still be executed during the `_wpftmp` build if `IncludePackageReferencesDuringMarkupCompilation` is `true`.
This behavior was surprising to me. Now that I've read through [the code in Microsoft.WinFX.targets](https://github.com/dotnet/wpf/blob/77f0456f549ca92ab7413218a7ee028f6195e340/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft.WinFX.targets#L409), I can understand the why things happen the way they do, but thought it was worth reporting anyways.
For some background, we use a code analysis NuGet package that I wanted to turn off during the MarkupCompile/inner build of the `_wpftmp` project. The analyzers are slow, we have more warnings than I'm proud of, and with them enabled during the `_wpftmp` build we get twice the number of warnings. I thought I would be able to put a condition on the `PackageReference` that excludes the package if we're in the `_wpftmp` build. However, when I did that, projects that had `IncludePackageReferencesDuringMarkupCompilation` set to true failed to build because the package wasn't included but the package's `.targets` file from the `build` folder was still executing.
I've created a small project that reproduces the issue. You can get it [here](https://github.com/nick-beer/dotnet-wpf-wpftmp-targets-issue).
**SDK Version 5.0.104**
Contributor guide
Assessment
This issue has not been assessed yet.