News

Microsoft Explains How to Port Desktop Apps to .NET Core 3.0

With cross-platform .NET Core 3.0 poised to support desktop applications -- the next step in totally subsuming the Windows-only .NET Framework -- Microsoft has published guidance on how to port existing WinForms and WPF projects to the new platform.

As the .NET Core and .NET Standard initiatives progressed over the past few year, support for Windows Forms and Windows Presentation Foundation applications was introduced in a recent.NET Core 3.0 preview. "The big deal here is now that if you're a WinForms or WPF developer you can actually utilize the .NET Core runtime," Microsoft's Beth Massi announced at VSLive! conference last October, while proclaiming .NET Core is the best target for new development projects.

"So you shouldn't feel pressured to move off .NET Framework, but just know that it's going to be much more highly targeted compatible fixes kind of going forward and we recommend that all new development that you start on .NET is on .NET Core if possible," Massi said.

"As we move forward into the future, with .NET Core 3, we're going to see some more workloads that we're going to be working on here, mainly Windows desktop."

Beth Massi, Product Marketing Manager, .NET Platform, Microsoft

Even prior to that, Microsoft created a portability analyzer tool to help developers check if their WinForms and WPF applications were ready for the new platform.

Now, with v.3.0 coming sometime this year, Microsoft is seeking to help developers move to the new platform, existing apps and all.

"In typical cases, just retargeting your projects to .NET Core isn’t enough," said Olia Gavrysh, .NET program manager, in a blog post this week.

She explained in detail how to port a WinForms desktop application that includes multiple projects from .NET Framework to .NET Core, including how to deal with potential problems that might arise and how to fix them.

On particularly interesting tip in the presentation (also done in a video) explains how developers can keep using the WinForms designer in Visual Studio even though it's under development and not yet available for .NET Core projects. That's done in two different ways:

  • You can keep your files linked (by just not performing a previous step) and copy them when the designer support is available. This way, you can modify the files in your old .NET Framework WinForms project using the designer. And the changes will be automatically reflected in the new .NET Core WinForms project -- since they’re linked.
  • You can have two project files in the same directory as your WinForms project: the old .csproj file from the existing .NET Framework project and the new SDK-style .csproj file of the new .NET Core WinForms project. You’ll just have to unload and reload the project with corresponding project file depending on whether you want to use the designer or not.

Otherwise the post contains detailed guidance on preparing to port, porting the main project and then porting the UI for the application, which is a memory board game targeting .NET Framework 4.5. Though it's a WinForms application, Gavrysh said WPF projects work similarly.

Specifically, she explains how to port the application project to .NET Core 3.0 and the class library to .NET Standard 2.0. "Using .NET Standard instead of .NET Core allows me to reuse the game logic to provide the application for other platforms, such as iOS, Android or Web," she said.

As the tutorial requires installation of .NET Core 3, using a Visual Studio 2019 Preview version is a prerequisite.

About the Author

David Ramel is an editor and writer at Converge 360.

comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube