有VB6到C#的迁移工具吗?
有谁知道从 VB6 代码转换为 C# 的方法吗?
有没有一个工具可以为我做到这一点?
我可以遵循任何迁移流程来执行此操作吗?
Does anyone know a way to convert from VB6 code to C#?
Is there a tool that can do this for me?
Is there any migration process that I can follow to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
VisualStudio 提供(或至少提供)一个向导来进行从 VB6 到 VB.NET 的转换(然后可以通过一些工作将其转换为 C#,可能需要#develop 的 VB.NET <-> C# 转换器的帮助) ,但是当我上次使用它时,对于任何不平凡的事情都需要完成大量手动工作,因此我怀疑如果这是一个大型和/或重要的应用程序,您可能最好手动重写或移植。
VisualStudio offers (or at least offered) a wizard to do a conversion from VB6 to VB.NET (which could then be converted to C# with a bit of work, possibly helped by #develop's VB.NET <-> C# converter), but when last I used it, for anything non-trivial there was a lot of manual work needing to be done so I suspect you're probably better rewriting or porting by hand if this is a large and/or important application.
这可能看起来有点厚脸皮,但你的大脑可能是最好的工具。
可能值得重写。
也许您不需要移植它。 VB6可以变成COM组件吗?
移植到 COM,从 C# 调用,朱迪法官及时回家。
It might come across as a little bit cheeky but your brain might be the best tool to use.
Could be worth the re-write.
Maybe you don't need to porting it. Could the VB6 be turned into a COM component?
Port to COM, call from C#, home in time for Judge Judy.
作为一个已经做过很多次的人,这不是一个容易的过程。 您可以使用 VB6 到 VB.Net 工具,如此中所述答案,然后使用 Reflector 或 SharpDevelop 转换为 C#。 对于 SharpDevelop 转换,有一些注意事项。 它搞砸了所有数组引用并认为它们是函数调用,并且所有逻辑运算符都转换为按位逻辑运算符(并且变成 & 而不是 &&)。 使用 Reflector 你会失去很多东西。 此外,Visual Studio 转换器在许多大型项目中都会失败,只是挂起并且永远不会完成。
将代码转换为 C# 后,您就必须开始真正的工作。 这种转换最多只能完成 50% 的工作,你必须修复大量的东西(你会看到你的代码中充斥着 TODO),重构大量的东西,最后你只剩下 C#,这是一个VB6 的表示——除非您有非常好的 VB6 代码,而不是您真正想要的地方。 此外,您的所有代码都充斥着 VB 帮助程序,而不是使用正确的 DotNet 函数(例如,所有字符串函数都是帮助程序而不是类对象。如果您使用了 Variants,那么所有这些都必须重写。如果您使用了很多 API 调用,它们往往需要重写,
最终您将获得一个基础,但是转换一个大型项目(20-30 个表单、30 个类、30 个模块)可能需要几个人月的时间,但是从头开始重写可能会花费几个人的时间。花费两倍的时间,你就会失去所有的业务逻辑。所以,这是可以完成的(我已经完成了 3 或 4 个大型项目),但没有万能的灵丹妙药,也没有任何工具说它可以做到。它只对你来说,是谎言。
As someone who has done this a bunch of times, this is not an easy process. You can use the VB6 to VB.Net tool as stated in this answer, and then use either Reflector or SharpDevelop to convert to C#. With the SharpDevelop conversion, a few caveats. It screws up all the array references and thinks that they are function calls, and all the logical operators are converted to bitwise logical operators (And becomes & not &&). With Reflector you lose a bunch of stuff. Also the Visual Studio converter fails on a lot of large projects, just hangs and never completes.
Once you have got your code converted into C#, you have to start the real work. The conversion gets you at best 50% of the way there, you have to fix a ton of stuff (you will see your code littered with TODO's), refactor a ton of stuff, and at the end you are left with C# that is a representation of your VB6 -- unless you have very nice VB6 code not a place you really want to be. Also all of your code with be littered with the VB helpers rather than using proper DotNet functions (all the string functions are helpers rather than class objects, for examples0. If you used Variants at all those all have to be rewritten. If you used a lot of API calls, they tend to need rewritting.
In the end you will get a base, but converting a large project (20-30 forms, 30 classes, 30 modules) can take several man months. Rewritting from scratch, however, may take twice as long and you lose all of your business logic. So, it can be done (I have done it with 3 or 4 large projects), but there is no panacea, no silver bullet, and any tool that says it will do it for you alone, is lying.
使用新版本的 Visual Studio 打开您的项目,将代码转换为 VB.Net,然后下载 .Net Reflector 帮助您进行 C# 转换。
祝你好运!
Open your project with a new version of Visual Studio, convert your code to VB.Net and then download .Net Reflector to help you with the C# transformation.
Good luck!
Artinsoft(现已重命名为 Mobilize.Net) 就是这样做的,特别是 Visual Basic Upgrade Companion。
然而,即使在使用 VBUC 之后,系统的某些部分仍然需要手动迁移/校对。 但它通常是原始问题的一小部分。 由于过去迁移的经验,一些迁移问题已经得到解决。
Theraccoonbear 的帖子中提到,Artinsoft 是构建 Visual Studio 附带的向导的同一家公司。 但是,如果我没记错的话,向导只会将 VB6 迁移到 VB.Net。
全面披露:我在 Artinsoft 工作
Artinsoft (Now renamed to Mobilize.Net) does just this, especifically the Visual Basic Upgrade Companion.
However, even after using the VBUC there's still some parts that of the system that needs to be migrated/proofed by hand. But it's usually a much smaller set of the original problem. And some of the migration issues have been resolved thanks to experience with past migrations.
Artinsoft is the same company that built the wizard that ships with Visual Studio, mentioned in theraccoonbear's post. However, if I'm not mistake the wizard only migrates VB6 to VB.Net.
Full disclosure: I work for Artinsoft
简而言之,VB6 和 VB.NET(以及 C#)是独立的语言,但又是相关的语言。 两个平台之间存在许多细微的差别(Integer 是 Int32,而不是 Int16)和明显的差别(图形、表单和打印引擎)。 您需要将其视为正在转换到完全不同的平台。
The short answer is that VB6 and VB.NET (and consequently C#) are separate language but related languages. There are many subtle (Integer being Int32 instead of Int16) and gross differences (graphics, form, and printing engines) between the two platforms. You need to treat this as if you are converting to a completely different platform.
我使用 2 个免费的:
http://www.carlosag.net/Tools/CodeTranslator/
http://www.developerfusion.co.uk/utilities/convertcsharptovb。 ASPX
There are 2 free ones that I use:
http://www.carlosag.net/Tools/CodeTranslator/
http://www.developerfusion.co.uk/utilities/convertcsharptovb.aspx
Microsoft 建议使用ArtinSoft 的 Visual Basic Upgrade Companion (VBUC)。
它并不完美,生成的代码仍然需要大量手动修复才能编译,但这个工具仍然值得一试。
Microsoft recommends ArtinSoft’s Visual Basic Upgrade Companion (VBUC).
It's not perfect, resulting code still requires lots of manual fixes until it even compiles but still this tool is worth giving a shot.
要问自己的一个问题是,使用 C# 比使用 VB.NET 有多重要? 如果您要转换大型应用程序,也许您应该升级到 VB.NET,这样会更便宜。
VB6 中的某些功能在 C# 中没有完全相同的功能(错误处理、后期绑定等)。 问问自己,当您可以使用确实支持它们的 VB.NET 时,为什么值得手动转换它们。
如果你不相信我(而且没有人投票支持我的答案,呜呜呜!)也许你会相信Francesco Balena 和 Dan Appleman(在一本书中 转向 VB.NET) 同意我的观点。
One question to ask yourself is, how important is it to have C# rather than VB.NET? If you're converting a large application, perhaps you should just upgrade to VB.NET, which will be cheaper.
There are some features in VB6 with no exact equivalent in C# (the error handling, late binding etc). Ask yourself why it's worth the manual effort to convert those, when you could go to VB.NET which does support them.
And if you don't believe me (and no-one's voted for my answer, sob sob!) maybe you'll believe Francesco Balena and Dan Appleman (in a book Moving to VB.NET) who agree with me.
在 GreatMigrations,我们手工完成这件事——我们用手开发 VB6/COM 编译器。 编译器读取VBP(或相关VBP组)并引用COM库并构建“语义模型”。 该模型是一组极其详细的符号表和操作码流,完整、准确地描述了源系统定义的所有信息结构和执行的操作。
然后,该工具应用一系列算法来修改和重组模型,使其与 .NET 更加兼容,并可选择应用自定义转换; 例如,用 .NET 类替换 COM 组件。 转换规则是由人们设计并“手工”创建的,以满足他们的独特要求。
最后,模型被“执行”,但我们不是分配数据模型并执行操作,而是以目标平台的表示法编写文件结构、数据模型和操作。 我们可以使用这种方法编写 VB.NET 和 C#。 我们还使用此过程将 ASP 站点迁移到 ASPX,(我们还有多方言 FORTRAN 到 C 的产品)
该方法不会在第一次尝试时生成可用于生产的软件,但可以对其进行改进并使其生成“通过修改工具的配置并重新运行翻译过程来改进”软件。 我们工具的优势在于其可重复性、速度和灵活性,这有助于实现敏捷的工具辅助重写方法。 IMO,利用我们方法的迁移团队将受益于分配更多资源来评估重新设计和开发流程改进的替代方案,而不是重新收集功能需求、手动编码和测试。 他们最终将在迁移后享受到更易于维护的系统和更忠实地再现原始应用程序功能,以及在迁移过程中获得更好的控制和可见性。
我们工具的试用版可在此处gmStudio Trail 请求下载。 它将允许您试验最多 10K LOC 的 ASP/VB 代码,并运行最多 30 个会话。
At GreatMigrations, we do this by hand -- we use our hands to develop a VB6/COM compiler. The compiler reads a VBP (or group of related VBPs) and referenced COM libraries and constructs a "semantic model". This model is an extremely detailed set of symbol tables and opcode streams that fully and accurately describe all information structures defined and operations performed by the source system.
The tool then applies a series of algorithms that modify and restructure the model to make it more compatible with .NET and optionally applies custom transformations; for example to replace COM components with .NET classes. The transformation rules are designed by people and created "by hand" to meet their unique requirements.
Finally, the model is "executed" but instead of allocating the data model and executing the operations, we author the file structures, data model, and operations in the notation of the target platform. We can author both VB.NET and C# using this approach. We also use this process to migrate ASP sites to ASPX, (we also have a multi-dialect FORTRAN-to-C product)
The approach does not produce production ready software on the first try, but it can be improved and made to produce "better" software by modifying the configuration of the tool and re-running the translation process. The advantage of our tool is its repeatability, speed, and flexibility which facilitates an agile tool-assisted-rewrite methodology. IMO, migration teams that leverage our approach will benefit from allocating a lot more resources to evaluating alternatives for redesign, and development process improvements rather than to re-gathering functional requirements, hand coding, and testing. They will ultimately enjoy a more maintainable system and a much more faithful reproduction of the original application functionality after the migration as well as greater control and visibility during the migration.
A trial edition of our tool is available here gmStudio Trail Request Download. It will allow you to experiment with ASP/VB codes up to 10K LOC and runs for up to 30 sessions.