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 for Converge360.

comments powered by Disqus

.NET Insight

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.

Upcoming Events