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]: C# code created using .NET 6 templates does not support targeting earlier .NET versions #25383

Closed
2 tasks
vlada-shubina opened this issue Jul 28, 2021 · 2 comments · Fixed by #25411
Assignees
Labels
breaking-change Indicates a .NET Core breaking change 🏁 Release: .NET 6 Issues and PRs for the .NET 6 release doc-idea Indicates issues that are suggestions for new topics [org][type][category] Pri1 High priority, do before Pri2 and Pri3

Comments

@vlada-shubina
Copy link
Member

vlada-shubina commented Jul 28, 2021

Description

Area: .NET SDK templates

In .NET 6 Preview 7 we made a change to the templates shipped with .NET SDK to use latest C# language features.

The following language features will be used or enabled by default in the SDK-included project templates:

  • Top-level statements
  • Global using directives
  • File-scoped namespaces
  • Target-typed new expressions
  • Nullable reference types
  • async Main

Some of the latest C# language features are not supported by previous target frameworks, so the users might experience the issues in the following scenarios:

  • Use a .NET 6 template and then change the target framework to previous version
  • Use a .NET 6 template and then add a previous version TFM to multi-target

Version

.NET 6 Preview 7

Previous behavior

It was possible to change target framework by editing project file or in project file properties without needing to change the C# code created from a template.

It was possible to add additional target framework by editing project file without needing to change the C# code created from a template.

New behavior

When changing the target framework or adding target framework the users may need to change the C# code generated by the template to avoid using unsupported language features. Without these change the project cannot be built. The compiler errors and warnings should usually guide the user on how to change the generated code to make it compatible with new target framework.

Type of breaking change

  • Binary incompatible (existing binaries may encounter a breaking change in behavior - for example, failure to load/execute or different run-time behavior)
  • Source incompatible (existing source code may encounter a breaking change in behavior when targeting the new runtime/component/SDK - for example, compile errors or different run-time behavior)

Reason for change

We would like the templates to be in sync with latest language features so that main scenario of using single latest target framework uses the latest language features.

Recommended action

  1. Avoid changing the target framework to previous version. Select the target framework you want during project creation in Visual Studio or via dotnet new <templateName> --framework <targetFramework>.

  2. When creating multi-target project, select the lowest target framework during project creation in Visual Studio or via dotnet new.

Feature area

Other (please put exact area in description textbox)

Affected APIs

none

@vlada-shubina vlada-shubina added the breaking-change Indicates a .NET Core breaking change label Jul 28, 2021
@dotnet-bot dotnet-bot added the ⌚ Not Triaged Not triaged label Jul 28, 2021
@PRMerger6 PRMerger6 added the Pri3 label Jul 28, 2021
@dotnet-bot dotnet-bot added the 🏁 Release: .NET 6 Issues and PRs for the .NET 6 release label Jul 28, 2021
@gewarren gewarren added doc-idea Indicates issues that are suggestions for new topics [org][type][category] and removed ⌚ Not Triaged Not triaged labels Jul 28, 2021
@dsplaisted
Copy link
Member

This looks good. I would avoid using the term "down-level" though.

@vlada-shubina
Copy link
Member Author

This looks good. I would avoid using the term "down-level" though.

I replaced "down-level" with "previous version".

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 doc-idea Indicates issues that are suggestions for new topics [org][type][category] Pri1 High priority, do before Pri2 and Pri3
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants