visual-studio Visual Studio:从现有代码创建 Web 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1325555/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:54:55  来源:igfitidea点击:

Visual Studio: Create a web application from existing code

visual-studioproject

提问by cbp

I have an existing directory structure that is all nicely checked into SVN, so I don't really want to mess with it.

我有一个现有的目录结构,它都很好地签入了 SVN,所以我真的不想弄乱它。

The website code lives in a folder called C:\Projects\TheProject\Website. I want to bring the website files into a new Web Application Project without changing the directory structure.

网站代码位于名为 C:\Projects\TheProject\Website 的文件夹中。我想在不更改目录结构的情况下将网站文件放入新的 Web 应用程序项目中。

Ideally the resulting file structure would look like this:

理想情况下,生成的文件结构如下所示:

  • C:\Projects\TheProject\TheProject.sln
  • C:\Projects\TheProjects\Website\Website.csproj
  • C:\Projects\TheProject\TheProject.sln
  • C:\Projects\TheProjects\Website\Website.csproj

No matter what I try I dont get what I want. There is no option to create a web application from existing code. This is very frustrating. Does anyone know if it is possible?

无论我尝试什么,我都没有得到我想要的。无法从现有代码创建 Web 应用程序。这是非常令人沮丧的。有谁知道这是否可能?

采纳答案by tsilb

Create a new web project with a .csproj file. Delete all the files it comes with. Drag everything into the project.

使用 .csproj 文件创建一个新的 Web 项目。删除它附带的所有文件。将所有内容拖到项目中。

回答by cbp

OK I figured it out. It's weird, but the following steps will work:

好的,我想通了。这很奇怪,但以下步骤将起作用:

  1. Open fresh copy of Visual Studio
  2. File->New Project, select Web Application
  3. Use the following settings:

    Name: Website (this is the name of the existing folder with the website files in it)Location: C:\Temp\ (anywhere will do for now)Solution Name: TheProject (name of the existing project's root folder) Check "Create directory for solution"

  4. Delete the auto-created Default, Global and Web.config files

  5. Save All and close Visual Studio
  6. In Windows Explorer, copy the new folder on top of the existing folder so that the files are merged.

  7. Double click on the sln file to open Visual Studio again.

  8. Select "Show all files" (at the top of Solution Explorer)

  9. Right click on any files or folders you want to add and select Include in Project.

  1. 打开 Visual Studio 的新副本
  2. File->New Project,选择Web Application
  3. 使用以下设置:

    名称:网站 (这是包含网站文件的现有文件夹的名称)位置:C:\Temp\ (现在可以在任何地方执行)解决方案名称:TheProject(现有项目的根文件夹的名称)选中“创建目录求解决”

  4. 删除自动创建的 Default、Global 和 Web.config 文件

  5. 全部保存并关闭 Visual Studio
  6. 在 Windows 资源管理器中,将新文件夹复制到现有文件夹的顶部,以便合并文件。

  7. 双击 sln 文件再次打开 Visual Studio。

  8. 选择“显示所有文件”(在解决方案资源管理器的顶部)

  9. 右键单击要添加的任何文件或文件夹,然后选择Include in Project

回答by AJ.

Have you tried something like this?

你有没有尝试过这样的事情?

  1. Create a new Visual Studio Blank Solution from File-->New Project-->Other Project Types-->Blank Solution, making sure to specify c:\Projects\TheProject as your solution directory.
  2. Copy the folder with all of the existing website stuff into c:\Projects\TheProject\WebSite.
  3. Back in Visual Studio, right-click your solution in Solution Explorer and select "Add Existing Website." Then, pick your c:\Projects\TheProject\WebSite folder.
  1. 从 File-->New Project-->Other Project Types-->Blank Solution 创建一个新的 Visual Studio 空白解决方案,确保将 c:\Projects\TheProject 指定为您的解决方案目录。
  2. 将包含所有现有网站内容的文件夹复制到 c:\Projects\TheProject\WebSite。
  3. 返回 Visual Studio,在解决方案资源管理器中右键单击您的解决方案,然后选择“添加现有网站”。然后,选择您的 c:\Projects\TheProject\WebSite 文件夹。

Good luck, HTH.

祝你好运,HTH。

回答by chenop

On top of @cbp answer I would like to add that if you would like to keep the Version control history of those files - in step 6 - instead of copy do:

在@cbp 回答之上,我想补充一点,如果您想保留这些文件的版本控制历史记录 - 在第 6 步中 - 而不是复制:

git mv original-website/* new-web-application-directory/.

回答by user2827912

In the File menu, click Open, and then click Web Site. Choose the root folder where your Web Site is located

在文件菜单中,单击打开,然后单击网站。选择您的网站所在的根文件夹

回答by RiddlerDev

What have you tried? I normally create a blank solution and add existing folders (drag and drop on solution explorer works best), and have not had a problem.

你试过什么?我通常创建一个空白解决方案并添加现有文件夹(在解决方案资源管理器上拖放效果最佳),并且没有出现问题。

回答by Funky Dude

in VS 2008 File->New->Project From Existing Code

在 VS 2008 File->New->Project From Existing Code