- 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.
Follow these steps to upgrade the project in Visual Studio:
Right-clickStarVoteControlproject inSolution Explorerwindow and selectUpdate:
See AlsoWhat is the future of .NET.NET releases, patches and supportHow to use the old .NET Update Assistant - .NET CoreA new tab will open asking you to choose how to update.
to chooseOn-site design update.
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.
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:
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:
- Right-clickWebsite ratingsproject inSolution Explorerwindow and selectUpdate:
- to chooseOn-site design updateas a way to improve.
- to choose.NET 7.0for the target frame and selectNext.
- 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.
- Right-clickWebsite ratingsproject inSolution Explorerwindow and selectClean.
- 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 article
Microsoft.Data.Sqlite
NuGet has been upgraded with1.0.0Do7.0.5. However,1.0.0depends onSQLite
NuGet packages, ali7.0.5it removes the addiction. TheSQLite
The NuGet package is still referenced in the project, although it is no longer needed. BothSQLite
ISQLite.Natywny
NuGet 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 remove
System configuration
library.(Video) Upgrading from .NET Framework to .NET 7 | .NET Conf 2022Most .NET Framework applications refer to
System configuration
library. After upgrading, this library can still be directly referenced.The
System configuration
uses the libraryapplication.configurationfile to provide runtime configuration options for your application. For .NET, this library has been superseded bySystem.Configuration.ConfigurationManager
NuGet 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:
To add
Microsoft.Web.WebView2
NuGet package.uMainWindow.xamlfile:
Import the control towpfcontrolnamespace in root element:
Downstairs where it is
element is declared, remove itWeb browser
control and replacewpfControls:WebView2
control:
editMainWindow.xaml.cscode behind the file. Please update
ListBox_SelectionChanged
installation methodbrowser.Source
important 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.
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.ConfigurationManager
NuGet package and support forappsettings.jsonensureMicrosoft.Extensions.Configuration
NuGet 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.
To remove
System.Configuration.ConfigurationManager
NuGet package.To add
Microsoft.Extensions.Configuration.Json
NuGet package.Add a file to the project namedappsettings.json.
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 following
Item group
:KeepLatest 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;" }}
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(); } }}u.\Modeli\Database.csfile, change it
OpenConnection
how to use newApplication configuration
property. This requires an importMicrosoft.Extensions.Configuration
namespace:(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 IEnumerable
ReadSite() GetConnectionString
is the extension method it offersMicrosoft.Extensions.Configuration
men'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? ›- Before You Start. Prerequisites. ...
- Migrate an Application. The DevExpress Unified Component Installer ships with the . ...
- Consider Portability Limitations. . ...
- Update Non-DevExpress NuGet Packages. DevExpress NuGet packages are compatible with both . ...
- Fix Build Issues. ...
- Test Your App. ...
- Useful Resources.
- Prerequisites. Visual Studio. ...
- Update .NET SDK version in global.json. ...
- Update the target framework. ...
- Update package references. ...
- New hosting model. ...
- Building libraries for ASP.NET Core 6. ...
- Frequently asked questions (FAQ) ...
- Blazor.
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? ›.NET SDK version | Visual Studio version |
---|---|
7 | Visual Studio 2022 version 17.4 or higher. |
6 | Visual Studio 2022 version 17.0 or higher. |
5 | Visual Studio 2019 version 16.8 or higher. |
3.1 | Visual Studio 2019 version 16.4 or higher. |
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? ›- Platform Uno.
- Avalonia.
- Blazor.
- Ooui.
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? ›Original author(s) | Microsoft |
---|---|
Initial release | November 21, 2006 |
Stable release | v6.0.2 / February 9, 2022 |
Repository | github.com/dotnet/wpf |
Written in | C#, C++, C |
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.
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? ›- Step 1: Set up the environment. ...
- Step 2: Check that all the APIs are . ...
- Step 3: Create the project file. ...
- Step 4: Declare assembly name and default namespace. ...
- Step 5: Suppress auto generation of AssemblyInfo. ...
- Step 6: Add necessary NuGet packages in the project file.
- Simplify your Visual Tree. ...
- Virtualize your ItemsControls. ...
- Favor StaticResources over DynamicResources. ...
- Opacity on Brushes Instead of Elements. ...
- Avoid Using Run to Set Text Properties. ...
- Favor StreamGeometries over PathGeometries. ...
- Use Reduced Image Sizes. ...
- Lower the BitMapScalingMode.
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? ›
- In your Solution Explorer, right-click your project and select Properties.
- In Properties, go to the Application option on the side menu.
- Locate the Target framework dropdown and select the framework version you need.
- 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. ...
- If you chose View details, then in the subsequent Update available dialog box, choose Update to update now.
- Select Target Framework.
- Target Framework for Setup.
- Select Prerequistes.
- Select Framework in Prerequisite.
- Select the Framwork to change the version.
- Change Framework Version.
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? ›- Find the Visual Studio Installer on your computer. ...
- In the installer, look for the edition of Visual Studio that you installed, and then choose Modify.
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? ›
- Create new .NET Standard library.
- Right-click project and choose Edit ClassLibrary1.
- Change target framework from <TargetFramework>netstandard1.4</TargetFramework> to <TargetFramework>net45</TargetFramework>
- Save.
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? ›- Run command "regedit" from console to open Registry Editor.
- Look for HKEY_LOCAL_MACHINE\Microsoft\NET Framework Setup\NDP.
- All installed .NET Framework versions are listed under NDP drop-down list.
- Open the project in Visual Studio.
- Right-click on the project's References folder and select Add Reference to open the Add Reference dialog box.
- Locate the new assembly version in the Add Reference dialog for each Infragistics assembly listed in your References folder.