Open
Description
Describe the bug
I am building a library for .NET48 .NET6.0 and .NET8.0 with custom WPF controls, one of them is a directory picker. In .NET48 and .NET6.0 I am using the Windows Forms picker, in .NET8.0 I am using the WPF picker and therefore also don't want to have the reference to Windows forms. See repro for details.
To Reproduce
- Create a multitargeting C# project and reference Windows Forms conditionally:
<PropertyGroup>
<TargetFrameworks>net48;net6.0-windows;net8.0-windows</TargetFrameworks>
<UseWindowsForms Condition="'$(TargetFramework)' == 'net48'">true</UseWindowsForms>
<UseWindowsForms Condition="'$(TargetFramework)' == 'net6.0-windows'">true</UseWindowsForms>
<UseWPF>true</UseWPF>
</PropertyGroup>
- Write a C# class as follows:
#if NET8_0_OR_GREATER
var dlg = new OpenFolderDialog
{
Title = Header as string,
FolderName = Text
};
if (dlg.ShowDialog().GetValueOrDefault())
{
Text = dlg.FolderName;
}
#else
var dlg = new System.Windows.Forms.FolderBrowserDialog
{
Description = Header as string,
#if NET48_OR_GREATER
SelectedPath = Text,
#endif
#if NET6_0
InitialDirectory = Text,
UseDescriptionForTitle = true,
#endif
};
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Text = dlg.SelectedPath;
}
#endif
- Add a .xaml file:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
</ResourceDictionary>
See my comment for a repro.
Exceptions (if any)
For Target .NET8.0 I get build error CS0234: The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?), though it should not be required by .NET8.0.
Further technical details
The bug was introduced with .NET SDK 9.0.200. With .NET SDK 9.0.102 I can compile successfully.