How do I convert a C# Windows Forms App project to a C# Windows Forms App (.NET Framework) project in Visual Studio?

Osamah Hadi 0 Reputation points
2023-06-03T10:58:35.9533333+00:00

I need some help and I am hoping you know how to do it. I am currently in school and I initially created my entire C# final project using a "Windows Forms App" project template in Visual Studio 2022 and have done all my work under that so far. Do you know how I can convert my current project from regular Windows Forms App to the Windows Forms App(.Net Framework) version ? I really can't afford to start this entire project from scratch by creating a new Windows Forms App(.NET Framework) project.

See the image below to understand what I mean. I made the program using the template in the red square but I need it to be the one in the green square.

apptypes

Developer technologies Windows Forms
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Minxin Yu 13,501 Reputation points Microsoft External Staff
    2023-06-05T06:32:48.5233333+00:00

    Hi, @Osamah Hadi

    You can't simply convert from .NET to .NET Framework.
    Please create a new Winform project and try the steps below.

    . Net and. Net Framework code are different. You need to modify program.cs file.

    namespace WinFormsApp1
    {
        internal static class Program
        {
            /// <summary>
            ///  The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                // To customize application configuration such as set high DPI settings or default font,
                // see https://aka.ms/applicationconfiguration.
                ApplicationConfiguration.Initialize();
                Application.Run(new Form1());
            }
        }
    }
    

    .NET Framework:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace WindowsFormsApp1
    {
        internal static class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
        }
    }
    
    

    Modify the Winform.csproj file.

    <TargetFramework>net6.0-windows</TargetFramework> to <TargetFramework>.NETFramework,Version=v4.7.2</TargetFramework> Remove content below that not supported in .NET Framework:

      <Nullable>enable</Nullable> 
    <ImplicitUsings>enable</ImplicitUsings>
    

    Save and reopen the project after modifying the above content. There are many errors, which are caused by missing reference namespaces.

    E.g.

    using System;

    using System.Windows.Forms;

    Now the Winform project will be able to compile and run.

    Summarize:

    1.Update project references: update project references to accommodate .NET Framework 4.8. Removed references specific to .NET 6 and added references to .NET Framework 4.8.

    2.Change Namespace: change the namespace to accommodate the structure of a .NET Framework 4.8 project.

    3.Change incompatible APIs: Based on features and APIs that are not supported in .NET Framework 4.8, manually change your code to use .NET Framework 4.8-compatible alternatives or workarounds.

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.