Repository navigation
Description
(This was reported to me offline via email; I'm adding some context.)
MSBuild and the Roslyn compilers use a feature called reference assemblies to attempt to minimize the build impact of changes to referenced assemblies. When the internal implementation of an assembly changes without changes to its public API surface, referencing projects shouldn't need to rebuild. This feature is turned on by default for projects targeting .NET 5.0+.
This isn't working for WPF projects, though. As an example, take a small solution with two projects: a library and a WPF app that references the library. Change whitespace in the library and build the solution. Ideally, the library would recompile, the WPF app would not, and the library would just be copied to the output folder of the WPF app.
In the current implementation, the WPF app is always rebuilt. The proximate cause is
Target Name=CoreCompile Project=WpfApp.csproj
Building target "CoreCompile" completely.
Output file "obj\Debug\net5.0-windows\WpfApp.dll" does not exist.
That's happening in
Target Name=CleanupTemporaryTargetAssembly Project=WpfApp.csproj
Task "Message" skipped, due to false condition; ('$(MSBuildTargetsVerbose)'=='true') was evaluated as (''=='true').
Delete
Delete
Parameters
Files = obj\Debug\net5.0-windows\WpfApp.dll
Deleting file "obj\Debug\net5.0-windows\WpfApp.dll".
Delete
That's happening because the _wpftmp project builds to the same location.
The _wpftmp project builds because MarkupCompilePass1 tells it to:
_RequireMCPass2ForMainAssembly = True
It's doing that because it is taking the implementation assembly as an input, through @(ReferencePath).
I think it could use @(ReferencePathWithRefAssemblies) like CoreCompile does.
Activity
rainersigwald commentedon Oct 6, 2021
I just tried this and it didn't quite work; I still see
_RequireMCPass2ForMainAssembly = True. Looks like it'll take a bit more digging into theMarkupCompilePass1task to figure out why.ryalanms commentedon Oct 6, 2021
If any references are touched, WPF will rebuild:
https://github.com/dotnet/wpf/blob/main/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/MS/Internal/Tasks/IncrementalCompileAnalyzer.cs#L128
rainersigwald commentedon Oct 6, 2021
Great pointer. The reference assemblies feature should make it so that the references passed to the compiler aren't touched. I'll see if I can debug through to see what it thinks has been.
rainersigwald commentedon Oct 6, 2021
Fortunately I think I just hadn't run the scenario I thought I had. Things seem to be working now with this change:
I think this is too risky for 6.0 GA but it'd be a nice speedup for 6.0.200/VS 17.1 if we could get it . . .
albahari commentedon Oct 7, 2021
This patch works for me and results in a massive improvement to build times.
Yarith commentedon May 7, 2022
I have written a single targets file, to compile all workarounds so we can have incremental wpf builds now. I can not override the inputs of the MarkupCompilePass1 task, so i will give warnings if the patch is still not applied. Also i have used the workaround from here so the
GeneratedInternalTypeHelper.g.csit is not causing rebuilds. The types used in xaml must now be public, in our codebase this is the case, otherwise the designer will have problems. There were also the problem with the other generated code files. Especially the files that are based on the current project name, which are always random for the temporary project. The already existing files were always overridden, but were ending up with the exact same content. Now there will be a.timestampfile in the obj folder to preserve the last modified timestamps. All of this is the minimum required so the csharp code will not get compiled.With all the workarounds i was able to have incremental builds with all our wpf projects. I hope the correct solution to this problem will be integrated in the sdk before those workarounds stop working. Here is the content of the targets file:
czdietrich commentedon Sep 7, 2022
What is the current state of this issue?
A small check for our solution (250+ projects, ~70 wpf) showed that incremental builds start working with the given patch from @rainersigwald.
Anything that prevents that this can be merged into the SDK?
pchaurasia14 commentedon Sep 9, 2022
@czdietrich - Unfortunately, we weren't able to attend this item for the past releases. We'll certainly target this for upcoming releases.
AndreyPolovodov commentedon Nov 28, 2025
Development experience with a large WPF codebase is absolutely disgusting. Many thanks to @rainersigwald for providing us with the SDK patch. I'm wondering why the WPF support team still hasn’t fixed this, and I’d like to upvote the issue.
franchyd commentedon Nov 28, 2025
There likely is no WPF support team at this moment. See #11188