简体   繁体   中英

Convert a .NET Framework VB project to .NET Core

For some reasons, I have to convert some projects (VB.NET and C#) to .NET Core.

I've followed info from various sources, from Convert.Net Core to.Net Framework and the Assembly Portability preventively to be conscious about the work to do.

Visual Studio 2019 Intellisense, after the conversion, does not show any alert BUT Visual Basic Projects does not compile.

The Visual Compiler shows the error for the namespaces " Global.Microsoft.VisualBasic.Devices " and " Global.Microsoft.VisualBasic.ApplicationServices " (" Type 'Global.Microsoft...' is not defined ").

For each VB project, I have updated Microsoft.VisualBasic package. The current version is now 10.3.0. But the problem still persists.

Every project is targeted to .NET Core 3.1 framework.

What could be the problem?

This is the solution to my case: compiling succeded adding

<VBRuntime>Embed</VBRuntime>

to.vbproj file. stackoverflow.com/a/20005217/3185385

While the solution posted by @michele74c worked, I was also able to resolve this by removing

<MyType>Console</MyType> 

from my.vbproj file.

That's stuff relating to VB-specific features of the Application Framework and the My namespace. For instance, My.Computer exposes an instance of the Microsoft.VisualBasic.Devices.Computer type. Microsoft.VisualBasic.ApplicationServices relates to things like the shutdown mode that you can set in the project properties and the Startup event that you can handle to act at application startup.

You basically need to make sure none of those things are in use in your app before trying to migrate from .NET Framework to .NET Core. I've never tried it but I would assume that that means disabling the Application Framework and creating your own Main method as an entry point, just as you would in C#, and also replacing any uses of the My namespace with the equivalent .NET Framework types and members, as you would use in C#.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM