How-to migrate old WinForms projects to the new VS2017 project format
Asked Answered
E

2

11

We are currently in the process of upgrading our projects to the new VS2017 project format. The main reason behind this was converting some libraries from PCL to .NetStandard and being able to use the new built in Nuget Package features that come with the new project format and therefor getting rid of the whole nuget/library reference/dependency issue.

[Edit] The main reason to migrate all projects in the solution is to prevent problems with not getting correct dependencies in .nupkg when mixing old (still working with .nuspec) and new format projects

The answers to the question How-to migrate Wpf projects to the new VS2017 format helped us a long way in converting the WPF parts of our projects. However, we still have huge amounts of Windows Forms stuff, which can't be replaced or upgraded.

With just converting the project file, adding the proper settings for file dependencies (for *.Designer.cs and *.resx files) we managed to get it to compile.

How can we now declare the project items in a way to make Visual Studio 2017 a) recognize them as either UserControl or Form ? b) open the WinForms designer tool to edit .cs or Designer.cs files accordingly ?

Any hint towards finding a solution is greatly appreciated.

Edile answered 22/6, 2017 at 10:23 Comment(1)
Use Upgrade Assistant then just change the TargetFramework to whatever flavor of .NET you want.Inset
H
7

I don't believe the SDK style projects have support for the various designers yet. While you can get the nested files to work with DependentUpon attributes, that's as far as it'll get.

That said, if your primary aim is to use the new NuGet features and use the transitive NuGet references, the existing project system supports this now.

Just remove all of your nuget packages manually then delete the packages.config file. You may then have to set <RestoreProjectStyle>PackageReference</RestoreProjectStyle>in your csproj. When you do that, the legacy project type should now use PackageReference NuGet references and do transitive restores.

Note that only packages are transitive this way, project-to-project references are not, so you'll need p2p refs the same as you did before.

Hosmer answered 22/6, 2017 at 11:59 Comment(3)
Thanks for your reply. Unfortunately, the main issue remains, that a mixture between old and new project formats (old ones using .nuspec for nuget packages) and having project-to-project references does not generate nuget dependencies. We were aware of the procedures on how to change to the new PackageReference style.Edile
As mentioned, I don't think the designers support the new project system yet. There may not be a way to get this to work today.Hosmer
14 months later, has there been any progress on this?Mims
J
2

Following the release of .NET Core 3.0, the WinForms is now supported but the designer support is currently scheduled for Q4 2020 and can be previewed using Visual Studio 16.4 Preview 3 or later, you have to set the Tools->Options->Preview Features->Use the Preview of Windows Forms designer for .NET Core apps checkbox for this to be enabled.

SDK-style projects should be setup as follows...

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

Before starting suggest you run the Portability Analyzer against the project since there are some known differences/incompatibilities. There is also another tool called try-convert which will attempt to convert your project.

Jackdaw answered 15/3, 2020 at 12:23 Comment(1)
Thanks for your input Paul. It's quite surprising that it took over 3 years for the tooling to be ready to finally support this. My question as such is now kinda obsolete.Edile

© 2022 - 2024 — McMap. All rights reserved.