9 Easy Steps to Port a WPF Application to .NET Core | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (174).NET Core  (29).NET MAUI  (207)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (219)BoldSign  (14)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (66)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (100)Streamlit  (1)Succinctly series  (131)Syncfusion  (917)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (36)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (149)Chart  (131)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (631)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (40)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (507)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (11)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (595)What's new  (332)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
WPF - .NET Core Image

9 Easy Steps to Port a WPF Application to .NET Core

As the world moves toward cross-platform application development, most developers are choosing these methods to build their applications and are migrating their existing applications to platforms that make this easier. In this blog, I am going to walk you through porting an existing WPF application to .NET Core in 9 easy steps.

For my example, I am choosing ExpenseAnalysis, a Syncfusion WPF showcase application, to port to a .NET Core application.

Step 1: Set up the environment.

To develop a .NET Core WPF application, you need Visual Studio 2019 and .NET Core 3.0 installed in your machine.

Step 2: Check that all the APIs are .NET Core compatible.

Before starting to port an application, check whether all the APIs are compatible using .NET Portability Analyzer.

Step 3: Create the project file.

Now add a new .csproj file. In this example, ExpenseAnalysisDemo_NetCore.csproj is added to the same folder where the other .NET .csproj files are placed. Add the following content in to the new .csproj file.

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <UseWPF>true</UseWPF>
  </PropertyGroup>
</Project>

Step 4: Declare assembly name and default namespace.

Specify the assembly name and default namespace in the new project file as it is in the .NET project.

<AssemblyName>ExpenseAnalysisDemo</AssemblyName>
<RootNamespace>ExpenseAnalysisDemo</RootNamespace>

Step 5: Suppress auto generation of AssemblyInfo.

A .NET Core project will automatically generate an AssemblyInfo.cs file. As we already have it, we need to suppress the auto generation by setting GenerateAssemblyInfo to false.

<GenerateAssemblyInfo>false</GenerateAssemblyInfo>

You don’t have to add any .cs or .xaml. They will automatically be added.

Step 6: Add necessary NuGet packages in the project file.

Unlike in .NET projects, the packages.config file will not be considered in .NET Core. Instead, you have to add the necessary NuGet package reference in the .NET Core project file.

<ItemGroup>
	<PackageReference Include="Syncfusion.Compression.Base" version="17.2.0.35" />
	<PackageReference Include="Syncfusion.Data.WPF" version="17.2.0.35" />
	<PackageReference Include="Syncfusion.DataGridExcelExport.Wpf" version="17.2.0.35"/>
	<PackageReference Include="Syncfusion.Licensing" version="17.2.0.35" />
	<PackageReference Include="Syncfusion.Pdf.Wpf" version="17.2.0.35" />
	<PackageReference Include="Syncfusion.SfChart.WPF" version="17.2.0.35" />
	<PackageReference Include="Syncfusion.SfGrid.WPF" version="17.2.0.35" />
	<PackageReference Include="Syncfusion.Shared.WPF" version="17.2.0.35" />
	<PackageReference Include="Syncfusion.XlsIO.Wpf" version="17.2.0.35" />
	<PackageReference Include="Syncfusion.XlsIO.Wpf" version="17.2.0.35" />
  </ItemGroup>

Step 7: Add necessary resources to the project file.

The project may use different resources and images for various purposes. Add these resources to the .NET Core project manually in the ItemGroup section.

<Resource Include="**\*.png" />
<Resource Include="App.ico" />

Step 8: Open and run.

Open the project file in Visual Studio 2019 and run the Expense Analysis showcase.Expense Analysis .NET Core project output

You can now interact with this report and use grids, charts with filtering, pagination, exporting, etc.

Step 9: Use condition compilation for framework-specific code.

After exporting data in the DataGrid, Expense Analysis will suggest opening the file. On choosing yes, the file will not open, as Process.Start() will lead to a Win32Exception: “The specified executable is not a valid application for this OS platform.”View Confirmation

Opening a file through .NET Core is different from .NET Framework, so use condition compilation to resolve this issue.

#if !NETCORE
    System.Diagnostics.Process.Start(sfd.FileName);
#else
    ProcessStartInfo psi = new ProcessStartInfo
    {
        FileName = "cmd",
        WindowStyle = ProcessWindowStyle.Hidden,
        UseShellExecute = false,
        CreateNoWindow = true,
        Arguments = "/c start " + sfd.FileName
    };
    Process.Start(psi);
#endif

Conclusion

With this, we have successfully migrated a WPF .NET Framework project to .NET Core. The migrated application of this converted project is provided for your reference in this GitHub location.

All Syncfusion WPF and WinForms components support .NET Core 3.0. From the recent 17.2 release, you can run existing WPF and WinForms product showcase demos in both .NET Core and .NET Framework.WPF Dashboard

Download the Syncfusion WinForms and WPF samples from their respective locations and use these controls for your development needs in .NET Core. Share your feedback in the comment section.

You can always contact us using Direct Trac, our support forum, or the feedback portal. We are happy to assist you.

Tags:

Share this post:

Comments (2)

[…] on August 20, 2019by admin submitted by /u/prabakarinfo [link] [comments] No comments […]

I just came to your blog yesterday and I have been checking it out often. You have a ton of good information on the site and I love the design of the website also. Keep up the great work!

Comments are closed.

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed