简体   繁体   English

将大型ASP.NET VB.NET项目转换为C# - 递增?

[英]Converting large ASP.NET VB.NET project to C# - incrementally?

Was looking for some approaches to incrementally converting an large existing ASP.NET VB.NET project to C# while still being able to deploy it as a single web application (currently deployed on a weekly basis). 正在寻找一些方法来将现有的大型ASP.NET VB.NET项目逐步转换为C#,同时仍然能够将其部署为单个Web应用程序(目前每周部署一次)。

My thoughts were to just create a new C# ASP.NET project and slowly move pages over, but I've never attempted to do this and somehow merge it with another ASP.NET project during deployment. 我的想法只是创建一个新的C#ASP.NET项目并慢慢移动页面,但我从未尝试过这样做,并在部署期间以某种方式将其与另一个ASP.NET项目合并。

(Clarification: Large ASP.NET VB.NET projects are absolute dogs in the VS IDE...) (澄清:大型ASP.NET VB.NET项目是VS IDE中的绝对狗......)

Any thoughts? 有什么想法吗?

Start with the business logic and work your way out to the pages. 从业务逻辑开始,逐步完成页面。 Encapsulate everything you can into C# libraries that you can add as references to the VB.NET site. 将所有内容封装到C#库中,您可以将其添加为VB.NET站点的引用。

Once you've got all of your backend ported over and tested, you can start doing individual pages, though I would suggest that you not roll out until you've completed all of the conversion. 一旦你的所有后端移植并进行了测试,你就可以开始做单独的页面,但我建议你在完成所有转换之前不要推出。

You are allowed to keep your App_Code Directory with both VB code and C# code in it. 您可以使用VB代码和C#代码保留App_Code目录。 So effectively, you could do it very slowly when you have the spare time to convert it. 如此有效,当您有空余时间进行转换时,您可以非常缓慢地完成它。

I currently have both VB.Net and C# code in my App_Code directory and on my spare time I convert to VB.Net code or anytime I have to go back to a page with VB.Net and mess with it I convert it to C#. 我目前在我的App_Code目录中都有VB.Net和C#代码,在我的业余时间我转换为VB.Net代码或任何时候我必须回到VB.Net的页面并弄乱它我将它转换为C#。

Easy Peasy and Microsoft made it even nicer when they allowed you to have both VB.NET and C# on the same app. Easy Peasy和Microsoft让它们在同一个应用程序中同时拥有VB.NET和C#时更加出色。 That was one of the best ideas they could have implemented in the entire app making process. 这是他们可以在整个应用程序制作过程中实现的最佳创意之一。

If you want to add both code directories in your one directory add this to your Web.config 如果要在一个目录中添加两个代码目录,请将其添加到Web.config中

<compilation>
<codeSubDirectories>
    <add directoryName="VB_Code"/>
    <add directoryName="CS_Code"/>
</codeSubDirectories>
</compilation>

And then add a folder named VB_Code and another folder named CS_Code in your App_Code directory. 然后在App_Code目录中添加名为VB_Code的文件夹和另一个名为CS_Code的文件夹。 Then throw all you vb/C# code in your folders and your good. 然后把你所有的vb / C#代码扔到你的文件夹和你的好。

A like for like port I take it? 喜欢我喜欢的端口吗? I don't really see the point and what you will gain for all the effort. 我并没有真正看到这一点以及你将为所有的努力获得什么。 Maybe write any new features or refactor sluggish/bad existing logic/service layers into c# but as for web pages I don't see the 80/20 benefit. 也许写任何新功能或重构缓慢/错误的现有逻辑/服务层到c#但是对于网页我没有看到80/20的好处。

try #Develop . 试试#Develop I think this the best way to convert ANY .net supported to any .net suppported languages. 我认为这是将ANY .net支持转换为任何.net支持语言的最佳方法。

Other tools convert only the code but this converts the whole project. 其他工具只转换代码,但这会转换整个项目。

Keep the old stuff in VB. 保留旧的东西在VB中。 All new stuff in C#. C#中的所有新东西。 The transistion might be slow but you will not loss time. 过渡可能很慢,但你不会浪费时间。 On free time, change stuff in C#. 在空闲时间,在C#中更改内容。

I did this with one project by doing the following: 我通过执行以下操作在一个项目中执行此操作:

  1. Create a C# class library 创建一个C#类库
  2. Reference the C# class library from the VB web application 从VB Web应用程序引用C#类库
  3. Create the code behind class in the C# library 在C#库中创建类后面的代码
  4. Update the "Inherits" property in the aspx/ascx file to reference the C# class (this file still exists in the original VB project) 更新aspx / ascx文件中的“Inherits”属性以引用C#类(此文件仍存在于原始VB项目中)

It worked somewhat ok; 它工作得有点好; It's a bit of a pain sometimes in that you now have to browse across multiple projects to view a single page/control, but it did let me do what you are wanting to do. 有时候你需要浏览多个项目以查看单个页面/控件,这有点痛苦,但它确实让我做了你想做的事情。

You can simply make a new c# class library project in the solution. 您只需在解决方案中创建一个新的c#类库项目。 recode a few classes at a time in here and then replace the vb classes in the main project. 在这里一次重新编写几个类,然后替换主项目中的vb类。

but to be honest I would agree I don't see the benefit unless your trying to learn c# or just really don't like vb or just bored. 但说实话,我同意我不会看到好处,除非你试图学习c#或者只是真的不喜欢vb或者只是觉得无聊。

I've had success pulling in dlls of vb projects with Reflector (it's free) and viewing the code as C#. 我已成功使用Reflector (它是免费的)将vb项目的dll拉入其中并将代码视为C#。 Local variables don't always translate but you can compare the translation and refactor things as you go. 局部变量并不总是翻译,但您可以比较翻译和重构事物。

It can be done. 可以办到。 Well I hope it can be done as I am doing this bit by bit on a legacy ASP.net application. 好吧,我希望它可以完成,因为我在传统的ASP.net应用程序上一点一点地做这件事。 You could just change over 1 Webform at a time. 您一次只能更改1个Webform。 Where you may struggle is that I can't seem to have mixed languages in the app code folder as they are compiled together. 您可能会遇到的困难是我在app代码文件夹中似乎没有混合语言,因为它们是一起编译的。

If you've got $179 you're done. 如果你有179美元就可以了。

Of course there are freeware converters available as well. 当然也有免费软件转换器。

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

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