简体   繁体   English

将 VB.NET 2005 项目转换为 C# 2008 项目

[英]Convert VB.NET 2005 project to C# 2008 Project

Is there a tool to convert a VB.NET 2005 project to a C# 2008 project.有没有工具可以将 VB.NET 2005 项目转换为 C# 2008 项目。 I am trying to convert our project to VS 2008 and mostly port all the vb.NET code in some projects to C# 3.0/3.5.我正在尝试将我们的项目转换为 VS 2008,并且主要将某些项目中的所有 vb.NET 代码移植到 C# 3.0/3.5。

I had a similar decision to make with a VB.net project.我对 VB.net 项目做出了类似的决定。 Solution was a compromise, I decided to run with dual VB and C#.解决方案是一个折衷方案,我决定使用双 VB 和 C# 运行。

Upgrading VB.NET 2005 to 2008 is easy bit.将 VB.NET 2005 升级到 2008 很容易。

Added CSharp and VB folders to App_Code and将 CSharp 和 VB 文件夹添加到 App_Code 和

<codeSubDirectories>
<add directoryName="CSharp" />
<add directoryName="VB" />
</codeSubDirectories>

to compilation section of web.config到 web.config 的编译部分

As Kev says, it's not as straight forward as you might expect, and you will likely run into unexpected issues, that make running with dual language support the best solution正如 Kev 所说,它并不像你想象的那么简单,你可能会遇到意想不到的问题,这使得运行双语言支持成为最佳解决方案

I know this doesn't directly answer the question, but it's an alternative approach我知道这并不能直接回答问题,但它是另一种方法

You could check out SharpDevelop .你可以看看SharpDevelop It's an open source .NET development environment.它是一个开源的 .NET 开发环境。 SharpDevelop has some code conversion built in. SharpDevelop 内置了一些代码转换。

Take a look at this.看看这个。

http://www.developerfusion.com/tools/convert/vb-to-csharp/ http://www.developerfusion.com/tools/convert/vb-to-csharp/

Try to google term "convert vb.net project to c# project", you will find a couple of options there.尝试使用 google 术语“将 vb.net 项目转换为 c# 项目”,您会在那里找到几个选项。

There's a tool on CodeProject called GBVB (Goodbye VB) that purports to 'flawlessly' convert VB.NET code to C# code. CodeProject 上有一个名为GBVB(再见 VB)的工具,它声称可以“完美地”将 VB.NET 代码转换为 C# 代码。 However the author does add a number of caveats such as the problems with ambiguous code, optional parameters etc.然而,作者确实添加了一些警告,例如代码不明确、可选参数等问题。

Another approach could be to use Denis Bauer's Reflector.FileDisassembler .NET Reflector add-in and disassemble the compiled assemblies back to C#.另一种方法可能是使用Denis Bauer 的 Reflector.FileDisassembler .NET Reflector插件并将已编译的程序集反汇编回 C#。

Handling.aspx/.asmx pages and their code-behind files would probably be a special case because you'd need to manually change the <%@ Page Codebehind="Default.aspx.cs" %> directives to point to the correct source files. Handling.aspx/.asmx 页面及其代码隐藏文件可能是一种特殊情况,因为您需要手动更改<%@ Page Codebehind="Default.aspx.cs" %>指令以指向正确的源文件。

Automatic VB.NET to C# conversion isn't really as straight forward as it initially appears to be.自动将 VB.NET 转换为 C# 并不像最初看起来那么简单。 I've been here before and gave up on a fairly large project, there's a lot of fiddling about with specific edge cases where the translation either wouldn't compile or produced unexpected behaviour at runtime.我以前来过这里并放弃了一个相当大的项目,有很多关于特定边缘情况的摆弄,在这些情况下,翻译要么无法编译,要么在运行时产生意外行为。 I elected to go for a dual language solution where all new code was written in C# and older VB.NET code was ported gradually over time.我选择 go 作为双语言解决方案,其中所有新代码都是在 C# 中编写的,而旧的 VB.NET 代码随着时间的推移逐渐移植。

hi this code answer not您好,此代码不回答

public student ()
        {}
        private string code;
            private string name;
        public string code()
        { 
        set (code=Value);
            Get return code;

        }

Telerik has a converter you might want to take a look at. Telerik 有一个您可能想看一看的转换器

Since others have mentioned online conversion tools I've found www.carlosag.net to work the best for my code.由于其他人提到了在线转换工具,我发现www.carlosag.net最适合我的代码。 Maybe b/c I work other 3rd party API's but it seems like a lot of the other online converter just error out if they hit a line they can't convert.也许 b/c 我使用其他第 3 方 API,但似乎很多其他在线转换器在遇到无法转换的行时就会出错。

SharpDevelop is quite good, but at my company we've found VBConversions to provide a much more complete conversion. SharpDevelop 非常好,但在我的公司,我们发现 VBConversions 可以提供更完整的转换。 It's a commerical app though, but for the time saved over SharpDevelop it was a no-brainer for us.虽然它是一个商业应用程序,但对于比 SharpDevelop 节省的时间,它对我们来说是一个明智的选择。

As a specific example, one thing we found that SharpDevelop didn't convert correctly was VB indexes, which use curvy brackets.作为一个具体的例子,我们发现 SharpDevelop 没有正确转换的一件事是 VB 索引,它使用弯曲的括号。 It seemed unable to distinguish between indexes and method calls so didn't convert the indexes to square brackets.它似乎无法区分索引和方法调用,因此没有将索引转换为方括号。 VBConversions converted them fine. VBConversions 可以很好地转换它们。 This one thing made it worth its purchase for us.这件事让我们值得购买。

It looks like Tangible Software have a very similarly product to VBConversions, but I don't have any experience with it.看起来 Tangible Software有一个与 VBConversions 非常相似的产品,但我没有任何经验。 Jon Skeet suggested it though, so it must be pretty good. Jon Skeet 推荐了它,所以它一定很不错。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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