Upgrade your WPF application to .NET 7 - WPF .NET (2023)

  • Article

This article describes how to upgrade a Windows Presentation Foundation (WPF) desktop application to .NET 7. Although WPF runs on .NET, a cross-platform technology, WPF is still a Windows-only platform. The following types of WPF-related projects can be upgraded with the .NET Upgrade Assistant:

  • project
  • Biblioteka kontrolna
  • Library .NET

If you're upgrading from .NET Framework to .NET, consider taking a look at thisDifferences from WPF .NETarticle iMigration from .NET Framework to .NETdriver.

Warning

Don't build on Visual Basic WPF projects. There seems to be a bug in the extension. This article will be updated when the bug is fixed.

Prerequisites

  • Windows operating system
  • Visual Studio 2022 version 17.1 or later to .NET 7
  • Visual Studio 2022 version 17.7 Preview 1 or later to target .NET 8
  • .NET Upgrade Assistant extension for Visual Studio

Demo app

This article was written in the context of an updateSample favorite websitesproject from which you can download.NET samples from the GitHub repository.

Start the update

If you're updating multiple projects, start with projects that don't have dependencies. In a sample of favorite websites,Website ratingsproject depends onStarVoteControlso the libraryStarVoteControlmust be updated first.

She works

Make sure you have a backup of your code, such as source control or copying.

(Video) Modernize your WPF and Windows Forms application with Blazor | .NET Conf 2022

Follow these steps to upgrade the project in Visual Studio:

  1. Right-clickStarVoteControlproject inSolution Explorerwindow and selectUpdate:

    Upgrade your WPF application to .NET 7 - WPF .NET (1)

    A new tab will open asking you to choose how to update.

  2. to chooseOn-site design update.

  3. Then select the target frame. Depending on the type of project being updated, different options are presented.Standard .NET 2.0is a good choice if the library does not rely on desktop technology such as WPF, and can be used in both .NET Framework and .NET projects. However, the latest versions of .NET provide many language and compiler improvements over the .NET standard.

    to choose.NET 7.0then selectNext.

    Upgrade your WPF application to .NET 7 - WPF .NET (2)

  4. A tree will be displayed with all artifacts related to the project, such as code files and libraries. You can update individual artifacts or the entire project, which is the default setting. To chooseUpdate selectionto start the update.

    After the update is complete, the results will be displayed:

    Upgrade your WPF application to .NET 7 - WPF .NET (3)

    Artifacts with a full green circle are enhanced while empty green circles are skipped. Missed artifacts mean that the update assistant found nothing to update.

    (Video) Upgrade Your .NET Projects Faster with Visual Studio

Now that the application support library has been updated, update the main application.

Please update the application

After all supporting libraries are updated, you can update the main application project. Do the following:

  1. Right-clickWebsite ratingsproject inSolution Explorerwindow and selectUpdate:
  2. to chooseOn-site design updateas a way to improve.
  3. to choose.NET 7.0for the target frame and selectNext.
  4. Leave all artifacts selected and selectUpdate selection.

The results will be displayed when the update is complete. If an item has a warning symbol, it means there is a note you can read about what you can do by expanding the item.

Generate a clean build

After upgrading the project, clean it up and build it.

  1. Right-clickWebsite ratingsproject inSolution Explorerwindow and selectClean.
  2. Right-clickWebsite ratingsproject inSolution Explorerwindow and selectBuild.

If your application encountered errors, you can find them in the fileError lista window with a recommendation on how to fix it.

Post-Update Steps

If your project is upgrading from .NET Framework to .NET, refer to the information inUpgrade after upgrading to .NET with .NET Frameworkarticle.

After upgrading, you'll want:

  • Check your NuGet packages.

    The .NET Upgrade Assistant updated some packages to new versions. Thanks to the sample application found in this articleMicrosoft.Data.SqliteNuGet has been upgraded with1.0.0Do7.0.5. However,1.0.0depends onSQLiteNuGet packages, ali7.0.5it removes the addiction. TheSQLiteThe NuGet package is still referenced in the project, although it is no longer needed. BothSQLiteISQLite.NatywnyNuGet packages can be removed from the project.

  • Clean old NuGet packages.

    Thepackages.configthe file is no longer needed and can be removed from the project because NuGet package references are now declared in the project file. Also, a local NuGet package cache folder namedpackage, is in the folder or in the parent folder of the project. This local cache folder can be deleted. The new NuGet package references use the global cache folder for packages, available in the user profile directory named.nuget\package.

  • To removeSystem configurationlibrary.

    (Video) Upgrading from .NET Framework to .NET 7 | .NET Conf 2022

    Most .NET Framework applications refer toSystem configurationlibrary. After upgrading, this library can still be directly referenced.

    TheSystem configurationuses the libraryapplication.configurationfile to provide runtime configuration options for your application. For .NET, this library has been superseded bySystem.Configuration.ConfigurationManagerNuGet package. Remove the library reference and add the NuGet package to your project.

  • Check out where you can upgrade your app.

    The APIs and libraries have changed quite a bit since the release of .NET. In most cases, the .NET Framework does not have access to these improvements. After upgrading to .NET, you now have access to more modern libraries.

    The following sections describe the areas where you can modernize the sample application used in this article.

Upgrade: Web browser control

TheWeb browserthe control referenced by the WPF sample application is based on Internet Explorer, which is deprecated. WPF for .NET can useWebView2Microsoft Edge based control. Follow the steps below to update to the new versionWebView2web browser control:

  1. To addMicrosoft.Web.WebView2NuGet package.

  2. uMainWindow.xamlfile:

    1. Import the control towpfcontrolnamespace in root element:

    2. Downstairs where it iselement is declared, remove itWeb browsercontrol and replacewpfControls:WebView2control:

       
  3. editMainWindow.xaml.cscode behind the file. Please updateListBox_SelectionChangedinstallation methodbrowser.Sourceimportant propertyUri. This code was previously passed to the website URL as a string, but it isWebView2control requires aUri.

    private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e){ var siteCollection = (ViewModels.SiteCollection)DataContext; if (siteCollection.SelectedSite != null) browser.Source = new Uri(siteCollection.SelectedSite.Url); otherwise browser.NavigateToString("");}

Depending on the version of Windows your app user is using, you may need to install the WebView2 runtime. For more information, seeGet started with WebView2 in WPF applications.

(Video) How to migrate WinForms/WPF application to .NET Core 3.0

Modernization: appsettings.json

It uses .NET FrameworkApplication configurationfile to load application settings such as connection strings and logging providers. .NET now usesappsettings.jsonfile for app items.Application configurationfiles are served in .NET bySystem.Configuration.ConfigurationManagerNuGet package and support forappsettings.jsonensureMicrosoft.Extensions.ConfigurationNuGet package.

When other libraries are upgraded to .NET, they are modernized with their supportappsettings.jsonInsteadApplication configuration. For example, logging providers in the .NET Framework that have been upgraded to .NET 6+ no longer use itApplication configurationfor settings. It's a good idea to follow their instructions and stop using themApplication configurationwhere can you.

Use appsettings.json with the WPF sample app

For example, after upgrading the WPF sample application, useappsettings.jsonfor local database connection parameters.

  1. To removeSystem.Configuration.ConfigurationManagerNuGet package.

  2. To addMicrosoft.Extensions.Configuration.JsonNuGet package.

  3. Add a file to the project namedappsettings.json.

  4. put it downappsettings.jsonfile to be copied to the output directory.

    put it downcopy to outputsetup with visual studio usingreal estatewindow after selecting the file inSolution Explorer. Alternatively, you can directly edit the project and add the followingItem group:

      KeepLatest  
  5. Transfer settings toApplication configurationsave to newappsettings.jsonfile.

    In the sample WPF application,application.configurationcontained only one connection string. editappsettings.jsonfile to define the connection string:

    { "ConnectionStrings": { "database": "DataSource=sqlite.db;" }}
  6. editapplication.xaml.csfile by instantiating the configuration object it loadsappsettings.jsonfile, added lines are marked:

    using System.Windows; using Microsoft.Extensions.Configuration;namespace WebSiteRatings{ ////// Interaction logic for App.xaml ///public partial class App: Application { public static IConfiguration Config { get; private set; } public App() { Config = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); } }}
  7. u.\Modeli\Database.csfile, change itOpenConnectionhow to use newApplication configurationproperty. This requires an importMicrosoft.Extensions.Configurationnamespace:

    (Video) Publishing/Deploying WPF Applications (feat. GitHub Actions) - EASY WPF (.NET Core)

    using Microsoft.Data.Sqlite;using System.Collections.Generic;using Microsoft.Extensions.Configuration;namespace WebSiteRatings.Models{ międzynarodowa klasa Baza podataka { public static SqliteConnection OpenConnection() => new SqliteConnection(App.Config.GetConnectionString("database " )); javni statički IEnumerableReadSite()

    GetConnectionStringis the extension method it offersMicrosoft.Extensions.Configurationmen's space

FAQs

Upgrade your WPF application to .NET 7 - WPF .NET? ›

In Visual Studio in Solution Explorer right-click on the project you want to upgrade, choose Upgrade. You will see the main page with a few options for your upgrade. Which option to choose is described in different upgrade types.

How do I update Visual Studio to .NET 7? ›

In Visual Studio in Solution Explorer right-click on the project you want to upgrade, choose Upgrade. You will see the main page with a few options for your upgrade. Which option to choose is described in different upgrade types.

How to migrate WPF to .NET 6? ›

Migrate WPF Applications to . NET
  1. Before You Start. Prerequisites. ...
  2. Migrate an Application. The DevExpress Unified Component Installer ships with the . ...
  3. Consider Portability Limitations. . ...
  4. Update Non-DevExpress NuGet Packages. DevExpress NuGet packages are compatible with both . ...
  5. Fix Build Issues. ...
  6. Test Your App. ...
  7. Useful Resources.
Oct 17, 2022

How do I upgrade my project from .NET 5 to .NET 6? ›

  1. Prerequisites. Visual Studio. ...
  2. Update .NET SDK version in global.json. ...
  3. Update the target framework. ...
  4. Update package references. ...
  5. New hosting model. ...
  6. Building libraries for ASP.NET Core 6. ...
  7. Frequently asked questions (FAQ) ...
  8. Blazor.
May 8, 2023

Is WPF being discontinued? ›

According to the documentation Overview - Product end of support, there are no plans to remove wpf. So it will be supported.

What version of Visual Studio do I need for .NET 7? ›

Install with Visual Studio
.NET SDK versionVisual Studio version
7Visual Studio 2022 version 17.4 or higher.
6Visual Studio 2022 version 17.0 or higher.
5Visual Studio 2019 version 16.8 or higher.
3.1Visual Studio 2019 version 16.4 or higher.
3 more rows
Apr 6, 2023

What version of Visual Studio supports .NET 7? ›

Visual Studio 2022 version 17.4.

Does .NET 7 support WPF? ›

This article describes how to upgrade a Windows Presentation Foundation (WPF) desktop app to . NET 7. Even though WPF runs on . NET, a cross-platform technology, WPF is still a Windows-only framework.

What will replace WPF? ›

Alternatives to WPF include:
  • Platform Uno.
  • Avalonia.
  • Blazor.
  • Ooui.
Jun 20, 2022

Does .NET 6 support WPF? ›

NET 5/6+ gives us an updated version of Windows Presentation Foundation (WPF). Unlike Web Forms or the Windows Communication Foundation (WCF), Microsoft brought this .

How do I upgrade .NET version of project? ›

NET versions with Upgrade Assistant right from Visual Studio. Right click on your project file and let the tool guide you through the process. The tool will choose the best upgrade type for your application and upgrade your project file and your code to accommodate some breaking changes and to use newer features.

Is .NET 6 backwards compatible with .NET 5? ›

NET 5/6/7 are cross-platform, and do not include all the windows-specific code. It can be installed on linux/mac/windows. NET Standard is a set of interfaces that help to guarantee cross-compatibility no matter whether you are running NET Framework or NET 5/6/7.

Is .NET 6 compatible with .NET 5? ›

NET 6 towards the end of 2021 gives you a target to aim for, with more features and increased cross-platform support. Code built for . NET 5 will run on . NET 6, and you can update it to take advantage of the new release's additional options and APIs.

Is WPF still used 2023? ›

WPF is definitely not dead. The WPF project was open sourced by Microsoft and published on GitHub [2]. There is even a public roadmap for WPF with target dates for 2022.

Why is WPF so difficult? ›

The difficulty with learning WPF is not so much the API as the model. It's a very different mental model than you'd use with something like Windows Forms. Rather than writing methods that imperatively populate a UI element, you generally data bind to properties on an object.

What is the latest version of WPF? ›

Windows Presentation Foundation
Original author(s)Microsoft
Initial releaseNovember 21, 2006
Stable releasev6.0.2 / February 9, 2022
Repositorygithub.com/dotnet/wpf
Written inC#, C++, C
8 more rows

Is .NET 7 long term support? ›

NET 7 includes a lot of awesome new features and performances improvements. It is a Standard Term Support (STS) release and not a Long Term Support (LTS) one though so it will go End of Support after only 18 months.

Why upgrade to net 7? ›

The . NET 7 SDK improves the CLI template experience, enables publishing to containers, and central package management with NuGet. Publish to a container:Container images are now a supported output type of the . NET SDK, and you can create containerized versions of your applications using dotnet publish.

Is .NET 7 same as .NET Core? ›

Net Core. Latest version of . Net Core is . NET 7.0 and which was released on November 8, 2022 and How to create a simple .

Which .NET framework should I use for Windows 7? ›

  • c#
  • .net.
Jan 15, 2019

Is .NET 7 better than .NET 6? ›

NET 6 introduced built-in support for OpenAPI, making it easy to generate API documentation and test your APIs using Swagger UI. . NET 7 is expected to continue improving OpenAPI support, with more features and enhancements that could make it even easier to build and document APIs with . NET.

Which database is best for WPF? ›

Mostly SQLite would be suggested, because it is the most widely known and thus would be perceived as 'best'.

Will Maui replace WPF? ›

NET MAUI is intended to unify and replace technologies like WPF. UWP or Xamarin. It's in preview at the moment, but it only matters if you want to release in the next four months.

How to migrate WPF to .NET core? ›

9 Easy Steps to Port a WPF Application to . NET Core
  1. Step 1: Set up the environment. ...
  2. Step 2: Check that all the APIs are . ...
  3. Step 3: Create the project file. ...
  4. Step 4: Declare assembly name and default namespace. ...
  5. Step 5: Suppress auto generation of AssemblyInfo. ...
  6. Step 6: Add necessary NuGet packages in the project file.
Sep 26, 2022

How can I improve my WPF application performance? ›

15 WPF Performance Tips
  1. Simplify your Visual Tree. ...
  2. Virtualize your ItemsControls. ...
  3. Favor StaticResources over DynamicResources. ...
  4. Opacity on Brushes Instead of Elements. ...
  5. Avoid Using Run to Set Text Properties. ...
  6. Favor StreamGeometries over PathGeometries. ...
  7. Use Reduced Image Sizes. ...
  8. Lower the BitMapScalingMode.
Jun 24, 2019

Does WPF exist in .NET core? ›

WPF is a . NET Core UI framework for building Windows desktop applications.

Is WPF better than Windows Forms? ›

WPF uses a more modern approach to layout that is based on XAML, while WinForms uses a more traditional approach that is based on forms and controls. This means that WPF provides more flexibility and control over the layout and appearance of the UI, while WinForms is simpler to use for basic UI design.

Is .NET 6 compatible with .NET 7? ›

However, the . NET 7 version of the . NET WebAssembly build tools are incompatible with existing projects built with . NET 6.

Who is the successor of WPF? ›

Familiar. Considered a spiritual successor to WPF, Avalonia UI provides a familiar developer experience allowing you to leverage years of pre-existing knowledge and investments.

Can a .NET 6 app run on Windows 7? ›

Windows 7 is only supported (with . NET 6) for organizations that have purchased Extended Security Updates (ESU).

How do I change the .NET version in Visual Studio? ›

How to change the . NET Framework Version in Visual Studio
  1. In your Solution Explorer, right-click your project and select Properties.
  2. In Properties, go to the Application option on the side menu.
  3. Locate the Target framework dropdown and select the framework version you need.
Apr 6, 2020

How do I update my existing Visual Studio? ›

Use the message box in the IDE
  1. When you open Visual Studio, the IDE checks to see if an update is available. In certain situations, a Visual Studio 2022 update message will briefly appear. ...
  2. If you chose View details, then in the subsequent Update available dialog box, choose Update to update now.
May 16, 2023

How do I change the .NET framework version in Visual Studio? ›

Changing the target framework for the setup file
  1. Select Target Framework.
  2. Target Framework for Setup.
  3. Select Prerequistes.
  4. Select Framework in Prerequisite.
  5. Select the Framwork to change the version.
  6. Change Framework Version.

Where to change net version in Visual Studio? ›

Change the target framework. In an existing Visual Basic, C#, or F# project, you change the target . NET version in the project properties dialog box. For information about how to change the target version for C++ projects, see How to modify the target framework and platform toolset instead.

How do I upgrade to the latest version of NET Framework? ›

NET Framework version. To update the target framework for all projects, right-click on the project (one by one), click properties, and from the “Application” tab change the target framework to the desired one as in the following screenshot and select “Yes” in the popup that is displayed after the framework is changed.

How do I change my .NET standard version? ›

To do that, complete the following steps: In Visual Studio, select Analyze and then Portability Analyzer Settings. In the General Settings window, select . NET Standard 2.0 under Target Platforms, and then choose OK.

How to change .NET version using command prompt? ›

To switch to a specific version of the SDK, you can use the “dotnet --list-sdks” command to list the available SDKs and then use the “dotnet use” command to switch to the desired version.

How do I modify Visual Studio after installation? ›

To modify your Visual Studio installation, you first need to launch the Visual Studio Installer, and then select a Visual Studio installation to modify.
  1. Find the Visual Studio Installer on your computer. ...
  2. In the installer, look for the edition of Visual Studio that you installed, and then choose Modify.
May 16, 2023

Can I install different versions of Visual Studio? ›

The term side-by-side means that you can install and maintain multiple versions of a product on the same computer. For VSPackages, that means a user can have several Visual Studio versions installed on the same computer.

What's the difference between Visual Studio and Visual Studio code? ›

Visual Studio is an Integrated Development Environment, also known as an IDE. Visual Studio Code is a code editor. A developer can easily edit their code. VS is slower when it comes to performing across different platforms.

How do I change a project from .NET core to .NET framework? ›

Comments
  1. Create new .NET Standard library.
  2. Right-click project and choose Edit ClassLibrary1.
  3. Change target framework from <TargetFramework>netstandard1.4</TargetFramework> to <TargetFramework>net45</TargetFramework>
  4. Save.
Jan 18, 2017

How to check the .NET Framework version of an application in Visual Studio? ›

Open Visual Studio Developer Command Prompt or Visual Studio Developer PowerShell and enter clrver . For .NET Framework 4.5 and later versions, don't use the Environment.Version property to detect the version of the CLR.

How do I create a .NET 7 project? ›

Give the project name, location of the project, and click on Next. Then, select Framework: . NET 7.0(Preview) as illustrated below and click Create. Then it will create a project which looks like it as depicted below.

What is the difference between .NET and .NET framework? ›

NET Core and . NET Framework is a platform for . NET applications on Windows whereas, NET Core is the latest version of the . NET Framework which is a cross-platform and open-source framework optimized for modern app needs and developer workflows.

How do I know which version of .NET framework is installed? ›

To check what version of .Net installed on the machine, follow steps below:
  1. Run command "regedit" from console to open Registry Editor.
  2. Look for HKEY_LOCAL_MACHINE\Microsoft\NET Framework Setup\NDP.
  3. All installed .NET Framework versions are listed under NDP drop-down list.

How do I change the project version in Visual Studio? ›

Upgrading a Project Manually
  1. Open the project in Visual Studio.
  2. Right-click on the project's References folder and select Add Reference to open the Add Reference dialog box.
  3. Locate the new assembly version in the Add Reference dialog for each Infragistics assembly listed in your References folder.

Videos

1. WPF Update to C# 11 and .NET 7 | RSS Reader | Software Technology Versatility | Omni-tech Mastery
(Michael Gautier)
2. Upgrade to .NET 7: Simplified Migration for Legacy .NET Apps
(Claudio Bernasconi)
3. Create your first WPF app on .NET Core | Desktop and .NET Core
(WPF)
4. Upgrade to .Net6 | How to convert dotnet framework 4 project to dotnet 6 in 2023 (Today)
(Tech In Talk)
5. Modernizing .NET Desktop Applications with .NET Core
(Microsoft Visual Studio)
6. Changing C# project dotnet version (.NET Standard, .NET Framework, .NET Core)
(Cezary Piątek)

References

Top Articles
Latest Posts
Article information

Author: Ouida Strosin DO

Last Updated: 26/09/2023

Views: 6647

Rating: 4.6 / 5 (76 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Ouida Strosin DO

Birthday: 1995-04-27

Address: Suite 927 930 Kilback Radial, Candidaville, TN 87795

Phone: +8561498978366

Job: Legacy Manufacturing Specialist

Hobby: Singing, Mountain biking, Water sports, Water sports, Taxidermy, Polo, Pet

Introduction: My name is Ouida Strosin DO, I am a precious, combative, spotless, modern, spotless, beautiful, precious person who loves writing and wants to share my knowledge and understanding with you.