Skip to content
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

[Breaking change]: Windows Forms SDK support for implicit namespaces in C# projects #25438

Closed
1 of 2 tasks
RussKie opened this issue Aug 3, 2021 · 4 comments
Closed
1 of 2 tasks
Assignees
Labels
breaking-change Indicates a .NET Core breaking change 🏁 Release: .NET 6 Issues and PRs for the .NET 6 release source incompatible Source code may encounter a breaking change in behavior when targeting the new version.

Comments

@RussKie
Copy link
Member

RussKie commented Aug 3, 2021

Description

Related to #25066

Windows Forms SDK has enabled global usings in .NET 6.0 RC1 in line with the rest of .NET SDK with all guards and requirements outlined in #25066.

Implicit namespace will be enabled by default for C# projects targeting the net6.0 TFM or higher and using Microsoft.NET.Sdk, Microsoft.NET.Sdk.Web or Microsoft.NET.Sdk.Worker SDK. A generated file containing the default namespaces will be included in the set of files passed to the compiler. Projects using a C# version less than 10 need to explicitly disable this feature.

There are three ways to control the namespaces that are included in the project:

  1. Disable the feature completely by setting <DisableImplicitNamespaceImports> to true or <DisableImplicitNamespaceImports_DotNet> to true in the project file. Refer to SDK support for implicit namespaces in C# projects #25066.
  2. Disable a set of implicit namespaces added by the Windows Forms SDK by setting <DisableImplicitNamespaceImports_WindowsForms> to true in the project file.
  3. Add or remove individual namespaces in the project file by modifying the <Import> item group in the project file. For example:
<ItemGroup>
  <Import Remove="System.Linq" />
  <Import Include="MyCool.Project" />
</ItemGroup>

These are the implicit namespaces added to projects using by the Windows Forms SDKs:

System
System.Collections.Generic
System.IO
System.Linq
System.Drawing
System.Windows.Forms

Version

.NET 6 RC1

Previous behavior

No implicit namespaces are added for applicable C# projects.

New behavior

Implicit namespaces are added via global usings in a generated file in the obj directory. See how to control the list of included implicit namespaces above.

Type of breaking change

  • Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load/execute or different run-time behavior.
  • Source incompatible: Source code may encounter a breaking change in behavior when targeting the new runtime/component/SDK, such as compile errors or different run-time behavior.

Reason for change

These changes in the SDK are made to reduce the amount of boilerplate using statements that appear at the top of most C# projects.

Recommended action

This feature will be enabled by default and for most users, no action will need to be taken. However, the introduction of this mechanism can cause type name conflicts with the namespaces listed above. In those cases, action need to be take to modify the list of implicit namespaces.

Feature area

C#, Windows Forms

Affected APIs

None.

@RussKie RussKie added doc-idea breaking-change Indicates a .NET Core breaking change labels Aug 3, 2021
@dotnet-bot dotnet-bot added ⌚ Not Triaged Not triaged 🏁 Release: .NET 6 Issues and PRs for the .NET 6 release labels Aug 3, 2021
@gewarren gewarren removed the ⌚ Not Triaged Not triaged label Aug 4, 2021
@dotnet-bot dotnet-bot added the source incompatible Source code may encounter a breaking change in behavior when targeting the new version. label Aug 4, 2021
@gewarren
Copy link
Contributor

gewarren commented Aug 4, 2021

@RussKie Does it make sense to you to add this info to the existing article at https://docs.microsoft.com/en-us/dotnet/core/compatibility/sdk/6.0/implicit-namespaces? Or create a new article under WinForms?

@RussKie
Copy link
Member Author

RussKie commented Aug 4, 2021

I don't have a strong preference. If it makes sense and easier - let's add it to the existing article. Would be good to have a link from the Windows Forms area to the article though.
I expect WPF submitting a similar breaking change notification, as they have made similar changes too. /cc: @ryalanms

@RussKie RussKie closed this as completed Aug 16, 2021
@gewarren
Copy link
Contributor

@RussKie Why was this closed?

@RussKie
Copy link
Member Author

RussKie commented Aug 17, 2021

Sorry, I thought I have posted a comment.

The whole feature is being re-designed, see dotnet/sdk#19521. So the current description is no longer relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Indicates a .NET Core breaking change 🏁 Release: .NET 6 Issues and PRs for the .NET 6 release source incompatible Source code may encounter a breaking change in behavior when targeting the new version.
Projects
None yet
Development

No branches or pull requests

3 participants