Imported website into web application in visual studio gives 'Type typename already defines a member'

huangapple go评论63阅读模式
英文:

Imported website into web application in visual studio gives 'Type typename already defines a member'

问题

在将现有且功能正常的网站导入Visual Studio(尝试了2017和2019两个版本),运行.NET 4.0后,我遇到了大量的未找到错误。

Codebehind页面无法看到现有页面上的元素
类被声明为重复或模糊
函数名称(包括Page_Load和自定义的)被报告为已经定义。

我确信所有这些问题都是相关的。以下是我遵循的步骤:

  1. 从Visual Studio 2017模板创建新的Web应用程序
  2. 将解决方案和csproject文件复制到现有网站文件夹中
  3. 将文件添加到项目中
  4. 重新添加对网站的引用
  5. 将自定义的.CS文件设置为编译
  6. 删除“不必要”的using语句(这些语句已在web.config中声明)
  7. 创建一个新的ProfileCommon存根,引用ProfileBase

除了这些步骤,我还尝试了重命名一些这些函数和类(使用重命名操作)以创建新的参考点。

除了进行重大更改或完全重写(迄今为止有100多页的代码),我不确定还能做什么。

还有哪些其他选项可以供我选择?

英文:

After importing this existing (and functional) site into Visual studio (tried 2017 and 2019 both) running .Net 4.0 I am getting a plethora of not found errors.

Codebehind pages are not able to see elements on the existing page
Classes are declared to be duplicated or ambiguous
Function names (both standard like Page_Load and custom) are reported as already defined.

I am sure that all these items are related. Here are the steps I followed:

  1. Created new Web Application from Visual Studio 2017 template
  2. Copied solution and csproject files into existing website folder
  3. Added files into the project
  4. Re-added references to site
  5. Set custom class .CS files to Compile
  6. Removed "unnecessary" using statements (which were already declared in web.config)
  7. Create a new ProfileCommon stub referencing ProfileBase

Beyond all this I have tried renaming a number of these functions and classes (using the rename) to create a new reference point.

Not sure what else I can do on this beyond major changes or a complete rewrite (100+ pages of code so far) by creating the new class files then copy/paste.

What other options are open to me?

答案1

得分: 0

这是一个迁移项目。只有你可以“确定”是否要从网站转换为网站应用程序,以及进行这种迁移项目所需的时间和工作。

现在,基于上面所述的情况,没有疑问,我更喜欢网站应用程序。像使用VS编译和构建应用程序,能够添加程序集(而不必让.dll文件必须放在bin文件夹中以解决引用的混乱)这样的简单事情,我都喜欢。

还有像在一个项目中拥有多个项目的能力,是我多年来开发软件时所期望和享受的。

至于“唯一”的有利之处是什么呢?你的部署非常简单,因为你可以打开一个网页或代码后端,点击保存,就完成了!

但是,这意味着源代码(代码后端)都必须部署到网站上。正如我所指出的,我更喜欢在VS中进行构建和编译过程。这意味着要进行“小”更改,你必须对整个站点进行完整的重新部署。

然而,我喜欢和享受这些好处?将现有网站转换为网站应用程序是否值得努力并不是一定的。只有你可以做出这个决定。另一方面,除非你知道自己在做什么,否则你不会进行这项工作,因此可以确定这些努力是否值得。

这种转换和重构过程有点超出了SO上的简单帖子。

然而,这里概述了一些步骤和提示:

https://devblogs.microsoft.com/dotnet/converting-a-web-site-project-to-a-web-application-project/

我建议考虑重新开始,并尝试上面的步骤。

上面提到了一个“转换”选项,这可以节省大量时间。我已经有一段时间没有尝试过这样的转换了,我还没有在vs2022中测试过“转换”选项,希望它仍然存在。

然而,还有另一个可能的选项:保留网站作为网站。

英文:

Ok, this is is a migration project. Only you can "determine" if you want to convert from a web site to a web site application, and the time and efforts for such a migration project.

Now, having stated the above? No question, that I prefer hands down a web site applications. Simple things like have VS compile and build the application, ability to add assemblies (and not have the mess of .dll's HAVING to be in the bin folder to resolve references - yuk!).

And then simple things like the ability to multiple projects in one project are things I come to enjoy, and expect over the years when developing software.

About the "only" thing going for a web site? Your deployment is oh so easy, since you can open a web page, or code behind, hit save, and you are done!

but, this means both source code (code behind) has to be deployed to the web site. As noted, I prefer a build and compile process in VS. This does mean that to make a "minor" change, then you have to do a full re-deploy of the whole site.

However, these benefits I like and enjoy? it not all a given that converting an existing web site to a web site application is worth the efforts. Only you can make this decision. On the other hand, you would not be doing this work unless you KNOW what you doing, and thus can determine if these efforts are worth the time.

Such a conversion and refactoring process is somewhat beyond a simple post on SO.

However some steps and tips are outlined here:

https://devblogs.microsoft.com/dotnet/converting-a-web-site-project-to-a-web-application-project/

I would consider starting over, and try the steps in above.

There is a "convert" option outlined in above, and this can save enormous amounts of time. It has been some time since I have attempted such a conversion, and I not tested the "convert" option in vs2022, and hopefully it still exists.

However, another possible option? Keep the site as web site.

huangapple
  • 本文由 发表于 2023年2月7日 02:59:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/75365495.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定