dotnet / dotnet/wpf

Improved incremental build/reference assembly support

Open
#5,458 10 comments 14 reactions 0 assignees View on GitHub
Investigate
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

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](https://github.com/dotnet/roslyn/blob/83bddcb0b52a206a4033eb6f3f074ebebbcdd6de/docs/features/refout.md) 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](https://github.com/dotnet/roslyn/blob/83bddcb0b52a206a4033eb6f3f074ebebbcdd6de/src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets#L128).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.