Skip to content

Nested #if processing #48545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
astuy opened this issue Apr 17, 2025 · 0 comments
Open

Nested #if processing #48545

astuy opened this issue Apr 17, 2025 · 0 comments
Labels
Area-NetSDK untriaged Request triage from a team member

Comments

@astuy
Copy link

astuy commented Apr 17, 2025

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>

And 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

I can also create a complete repro project and upload.

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.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-NetSDK untriaged Request triage from a team member labels Apr 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-NetSDK untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

1 participant