dotnet / dotnet/wpf

GenerateTemporaryTargetAssembly is case sensitive and drops metadata.

Open
#3,421 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

* .NET Core Version: All
* Windows version: doesn't matter
* Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes

**Problem description:**
The generated .csproj as part of the WPF Markup build is case sensitive to `True` for metadata such as EmbedInteropTypes. This is an issue as MSBuild is not case sensitive, and the default behavior of the VS Property Editor for References uses 'true' as the xml value for EmbedInteropTypes.

I have seen a scenario where this dropping of metadata causes two references to exist in the generated .csproj: one with EmbedInteropTypes set and one without, which causes a /reference and /link to be sent to csc.exe for the same assembly. This breaks the build.

The bug is here (metadata is being case sensitive compared to `True`): https://github.com/dotnet/wpf/blob/b9f35f41d809367623f189ef248a59edd30a3acf/src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/GenerateTemporaryTargetAssembly.cs#L487-L491


**Minimal repro:**
1. Create a new .NET Core or .NET Framework WPF project in VS
2. Add to the solution a .NET Standard 2.0 Class Library
3. Add the following to the .NET Standard project (just to make EmbedInteropTypes work):
```cs
[assembly:Guid("A5ACF709-F09F-4468-A856-50A72E62E930")]
[assembly:PrimaryInteropAssembly(1, 0)]
```
4. Reference the class library from the wpf project and set EmbedInteropTypes to `true` (this is the behavior when using the Reference Property Editor).
5. Add a new class called ViewModel and add to the XAML file
```xml

```
6. Build the project with verbose logging.

While the project builds successfully, you can check the generated project's csc.exe command line output in the logs. It is passing ClassLibrary1.dll to the compiler as /reference, however it should be as /link because of the EmbedInteropTypes. However, that metadata is getting dropped in the generated file.

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.