Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 611
Roman Mueller Avatar asked Jun 22 '17 10:06

Roman Mueller


People also ask

Can I open Visual Studio 2017 project in 2019?

Visual Studio 2019 can open projects created in Visual Studio 2013, Visual Studio 2015, and Visual Studio 2017.

How do I move a project in Visual Studio?

Right-click the Syncfusion ASP.NET Application from Solution Explorer and select Syncfusion Web (Essential JS 1). Choose Migrate the Essential JS 1 Project to Another version… The Project Migration window appears. You can choose the required Essential Studio version that is installed in the machine.

How do I update a Visual Studio project?

To upgrade a project created in an earlier version of Visual Studio, just open the project in the latest version of Visual Studio. Visual Studio offers to upgrade the project to the current schema. If you choose No, the project doesn't get upgraded.


2 Answers

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.

like image 186
Paul Hatcher Avatar answered Oct 18 '22 13:10

Paul Hatcher


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.

like image 29
Claire Novotny Avatar answered Oct 18 '22 15:10

Claire Novotny