>> Hi, I'm Scott Hunter,
and I'm here with Olia today,
and we're going to talk about how you can
actually take WinForms in
WPF applications and move them from.NET framework to .NET Core 3.0.
To start off, let's talk about.NET core 3.0, .NET Core
3.0 doesn't ship as part of Visual Studio 2019,
but previews are available,
you can try it today with Visual Studio
.NET Core 3.0 brings the desktop workloads so .NET Core,
so we're bringing WinForms in WPF to .NET Core.
Because that of course open source,
we couldn't just bring them to .NET core,
we had to open source them.
So, in December 2018 we
open sourced Windows Forms in WPF there both in GitHub,
available today in open source,
people are already contributing to them but
that's part of our journey of bringing the desktop to core.
The next thing is, why would you want to port
your application from data frameworks to .NET Core?
What I would tell you is, if you have
a desktop application you're not changing anymore.
You probably shouldn't want to port it,
but if you have a desktop application
that you're actively developing
on there are a variety
of benefits you're going to get by moving to.NET Core.
One of those is going to be .NET
Core is our fast innovating version of.NET.
So if you want the latest C#,
if you want the latest frameworks,
if you went the latest BCL,
latest all those things,
it's going to be.NET Core, .NET
Core is fully side-by-side which means
we can actually innovate there faster
without risk of bricking existing applications.
The second thing is we've always had feedback about deployment,
and I'll give you an idea what that means.
We've .NET Framework, if you want to take advantage of
the latest feature in .NET Framework,
you have to wait until your IT department
is actually put that version of .NET
Framework on all the machines in your office.
With .NET Core,
we actually give you the flexibility of either having .NET Core
installed on the machine or you
can actually just install .NET Core as part of
your application meaning that
you'll actually take the files from .NET Core
and put them in the same folder of
your application, or even better.
If you want you can actually check a box in
Visual Studio and we will make
a single EXE that contains the latest
version .NET Core and your application all bundled together.
This means you can build
a desktop application using the latest C# and install it on
any machine in the network without
worrying about what version of.NET is on that machine.
The second thing is the BCL.
The BCL is the base class libraries
and.NET that make all the things that you do work.
Because .NET Framework is installed
once globally on the machine
and installed on billions of machines,
we can't really change much the BCL there.
Even a slight change might break the applications,
but in .NET Core we're actually able to
do that because you can opt in when
you want the next version of the framework.
Because of this, we've been able to actually optimize many of
the features in the BCL there much faster.
Just by moving your application to .NET Core you're likely to
see a 20 to 30 percent improvement in
performance because of these API improvements.
Then finally, the next area that I think is
really impressive is desktop applications.
We have then trying to figure out how to make them better,
we created the UWP platform a couple of years
ago but it requires you to rewrite your entire application in UWP.
Now with a XAML Islands you can take any of the new controls and
UWP and inject them into your wind former WPF application,
which means you can touch enable an existing desktop application
just by using one of those controls maybe you want
a modern browser control or modern media control,
you can bring those directly in to do that.
So all of these into being a bunch of
great reasons to actually move to .NET Core 3.0.
>> Hi my name is Olia Gavrysh,
I am PM on.NET team and today I'll talk about how
you port your framework desktop application to.NET Core.
You probably have many questions as;
Where do I start?
What I do with my class libraries?
Are there available tools to help me pour it in? And so on.
Luckily, we thought about all that and we put
together step-by-step porting guide available on
our.NET blog where you can see
how each stage in all details is performed.
We took a WinForms application and ported it to core describing
all possible challenges you might
encounter and available solutions for that.
So when you will be porting consult was that guide,
and now I'll just briefly talk about migration process.
So to migrate to .NET Core you simply need to
update your target framework to .NET Core 3.0 version.
If you're like that is the only change in you to
do and your application will be fully migrated.
But it might happen that your project is using
old project files style that is a long HTML file
that has many items and
properties you cannot edit it right away you
need to first unload your project and then you'll
be able to look in your project file.
The main problem with that is
that target framework property
does not know about .NET Core or .NET Standard,
it was created way before those two were around.
You cannot just specified desired version of .NET Core to migrate.
To be able to migrate to core you first need to update
your project file to the latest so-called SDK-style,
and our blog post describes how you do it in all details.
Once you're done, you can move your project to .NET Core.
Another thing that we are working on right now are our designers.
WinForms and WPF designers are not yet
available for your.NET Core 3.0 Projects,
but there is a workaround how you can benefit from
the designer experience for your new projects.
To do that you just link existing .NET
Framework source into the new .NET Core app.
Then when you want to edit your user interface,
you open all.NET Framework application you make changes,
those changes will be immediately translated to your
new .NET Core project that you will use for everything else.
So if you're porting your application from framework to core,
you might have dependencies on some APIs that are not
available in core but available in framework.
And if you encounter
that issue Windows Compatibility Pack might help you solve in it.
Windows Compat Pack is distributed as a NuGet package,
it has 21,000 APIs from a framework that were not included in .NET
Standard but you can still keep using
them even targeting .NET Core or .NET Standard.
If you're installed Compatibility Pack,
you want to install API analyzer as well.
API analyzer is a Roslyn tool that prompts you every time you are
using API that does not cross platform or API that is duplicated.
So you can on the flow while you're
coding be prompted and make decisions
regarding the risk of not
having your code being supported on other platforms.
With that I will jump into the demo and show you
how you brought your desktop applications to .NET Core.
So today we will pour it Windows application,
this is a memory game where you have decks
of cards facing down and you're trying to find a match.
If you look at this app,
this is a Windows forums UI MatchingGame project
and game logic project which
is a class library targeting.NET Framework.
My user interface has dependency on
class library and class library does not
depend on any other projects and the application,
so I will start port in with the class library.
I always recommend start supporting
projects that have least dependencies.
So to update it to .NET Core we need to open the project file,
and as you can see for this project we cannot open it right
away we need to unload our project and then do edit MatchingGame.
Here we can see old properties that does not support the .NET Core.
So first, we need to update
old format to the new SDK staff project.
I happen to have a code snippet here but to see how it looks like
you can just create a new empty .NET Core or .NET Standard Project,
and copy paste the content of the project file.
Now when we save it and reload the project.
We can see that it opens right away so it's fully migrated.
Please notice that I'm also using
generate assembly info and setting it to false.
The reason I did because I
already have assemblyinfo.cs file in my project,
and new SDK-style project generates assembly info automatically.
So, to disable duplication
I disabled generation of
assembly info or you can simply delete the file from the disk.
So now my project file is ready for me to update it the .NET Core.
In fact because this is class library
I'm going update it to .NET Standard,
because I might want to reuse this code in other projects
and .NET Standard to be compatible with any .NET Project.
So, for your class library I always
recommend to use standard instead of core.
All right. Let's see.
So now our project is migrated to .NET Standard but
we have some issues related to register API.
The reason is registry is APIs
available only for Windows and .NET Standard is
a cross platform project and this is the case where
Compatibility Pack will help us to resolve those dependencies.
So to install Windows compatibility Pack,
I go to Manage NuGet packages and I
search for Microsoft Windows Compatibility,
so I install this guy
and this errors disappear.
Perfect. But now to be able to track
all the APIs that are not
cross-platform I will also install API analyzer,
but that it will search for
Microsoft.DotNet.Analyzers.Compatibility.
It isn't pre-released version,
so I need to click include prerelease.
I'm going to install this.
All right.
So now I got some notifications,and I see that for registering
API I'm notified that this isn't supported on Linux or Mac OS.
I can customize all those notifications,
I can suppress them if I don't want to see them,
or choose how I'd like to be prompted as a form of error,
warning, or information, this is all available for you.
So right now they're fully migrated
our game logic project and let's see if it works, and it does.
So with that I will give it back to Scott. Thank you for watching.
>> So thanks Olia for that demo showing how you can put
a WinForms application from.NET Framework to .NET Core.
Now you've done that, let talking about the
future..NET Core 3.0 will ship later this year,
but you can run the previews of.NET Core 3.0
today on the Visual Studio 2019 preview
channel. .NET Core is completely
side-by-side meaning that you can install
the [inaudible] preview with no risks of bricking a
2.2 or 2.1 or a 2.0 or even a 1.x application.
We have a guide on this page that will send you to
some directions on how to port
an application from .NET Framework to .NET Core.
If you have any questions about,
that there's an email [inaudible] here as well,
feel free to send us questions,
feedback, on how you put your applications.
Any of that will help us build
a better product and I look forward
you try .NET Core 3.0.
[MUSIC]