C# Project Template in VS2022 only supports up to .NET Framework 4.8 and does not support .NET 7.0

Michael Villarin 1 Reputation point
2024-01-17T05:55:29.0466667+00:00

I have a C# Project Template project that was created using the built in template for C# Project Template in Visual Studio 2022.
User's image

It targets .NET framework 4.8. Now I would like to update it to target .NET 7.0, but it does not seem to be possible. Even with .NET 7.0 installed, when creating another project from the template above, the versions available only show up to 4.8.

User's image

Does this mean that this template does not support .NET versions higher than 4.8, even though it is included in the latest Visual Studio 2022?

I checked some resources and found this link:
https://learn.microsoft.com/en-us/dotnet/core/tutorials/cli-templates-create-item-template Does it mean we need to rewrite our past templates in a new method to support newer .NET versions?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,449 questions
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,681 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,363 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,130 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Jiachen Li-MSFT 27,001 Reputation points Microsoft Vendor
    2024-01-17T06:54:34.6166667+00:00

    Hi @Michael Villarin ,

    Yes, you need to create a later version of the template to support the project that creates the later version of the target framework.

    Create a project template for dotnet new - .NET

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Bruce (SqlWork.com) 57,646 Reputation points
    2024-01-19T17:19:12.85+00:00

    .net core uses msbuild tools and a new project file format. this format can be used for many 4.* framework projects (excluding 4.* asp.net projects).

    visual studio and the build tools do not support two project files in the same folder. the new project file format supports multiple target frameworks, so you can build a 4.8 and net 8 target with the same code and project file. for shared code you will be limited to compiler version of the oldest framework.

    note: cli template (the link in your post) are only for the new dotnet build tools and are not used for 4.* projects. visual studio templates can be used for both frameworks

    https://learn.microsoft.com/en-us/visualstudio/ide/creating-project-and-item-templates?view=vs-2022

    0 comments No comments

  3. Pinaki Ghatak 2,400 Reputation points Microsoft Employee
    2024-01-20T12:37:17.4066667+00:00

    Hello @Michael Villarin The issue you’re facing is likely due to the fact that the C# Project Template you’re using was designed for .NET Framework, which supports up to version 4.8. This is a separate technology from .NET Core and the newer .NET 5 and onwards, which is why you’re not seeing the option to target .NET 7.0 in your project. To target .NET 7.0, you would need to use a project template that supports .NET Core or .NET 5 and onwards. If you want to continue using your existing project template, you would need to modify it to support the newer .NET versions. Here are some steps you can follow to update your project to target .NET 7.0 (.NET 8 is newer)

    1. Edit your project file: Open your .csproj file and change the TargetFramework element to net7.0. This tells the project to target .NET 7.0. (We advise .NET 8 here)
    2. Ensure the correct .NET SDK is installed: Make sure you have the .NET 7.0 SDK installed on your machine. You can check this by running dotnet --info in your terminal.
    3. Update your code: Some of the language features used in .NET 6 and onwards may not be supported by previous target frameworks. If you encounter compile-time errors when you retarget to .NET 7.0, use that information to guide you in changing the generated code to make it compatible with .NET 7.0.

    Remember, before making these changes, it’s a good idea to back up your project or use a version control system to save your work. This way, you can revert the changes if something goes wrong. If you’re creating a new project and want to target .NET 7.0, select the target framework you want during project creation in Visual Studio or at the command line by using dotnet new <templateName> --framework net7.0. I hope this helps in your further .NET journey. If this information helps you, please tag this as answered, so it may help further readers who may have similar questions.

    0 comments No comments