简体   繁体   English

如何在 Visual Studio IDE 中打开 Visual Studio Code 文件夹(项目)

[英]How to open a Visual Studio Code Folder (Project) in Visual Studio IDE

How do I open I a Visual Studio Code folder in Visual Studio 2015?如何在 Visual Studio 2015 中打开 Visual Studio Code 文件夹?

If I open it as a "Web Site", it tries to treat the node_modules directory as part of the project's normal JavaScript files and hits an error when the path exceed the maximum path length.如果我将其作为“网站”打开,它会尝试将 node_modules 目录视为项目正常 JavaScript 文件的一部分,并在路径超过最大路径长度时遇到错误。

But I can't open it as any other project type unless I first create a project of that type and then move all the VS Code files into that folder.但是我无法将它作为任何其他项目类型打开,除非我首先创建该类型的项目,然后将所有 VS Code 文件移动到该文件夹​​中。

  • Should I be trying to open it as a web site?我应该尝试将其作为网站打开吗?
  • Or should I create a new project and then copy the files + folders into it?或者我应该创建一个新项目,然后将文件+文件夹复制到其中?
  • Is there any advantage to having it as a project?把它作为一个项目有什么好处吗?
  • If I do create a project, it makes it difficult to work together with someone who is just using VS Code?如果我确实创建了一个项目,与仅使用 VS Code 的人一起工作会变得困难吗?
  • And if I use a project, which project type should I select?如果我使用一个项目,我应该选择哪种项目类型?

Currently there is no way to open a folder directly with Visual Studio.目前无法直接使用 Visual Studio打开文件夹

Why?为什么? Because因为Visual Studio and Visual Studio Code only shared their name, not the idea behind it. Visual Studio 和 Visual Studio Code 只分享了他们的名字,而不是它背后的想法 To extend Jenny O'Reilly answer:扩展 Jenny O'Reilly 的回答:

  • Visual Studio Code is a folder oriented editor Visual Studio Code 是一个folder oriented编辑器

    This means VSC has the same Point-of-View to your Project as the File Explorer.这意味着 VSC 与文件资源管理器具有相同的项目视角。

  • Visual Studio (not Code) is a solution oriented integrated development environment (short IDE) Visual Studio(不是 Code)是一个solution oriented集成开发环境(简称 IDE)

    Instead every Project in Visual Studio needs a *.sln Solution-File as Root Component.相反,Visual Studio 中的每个项目都需要一个*.sln解决方案文件作为根组件。 From this point Visual Studio looks at your Project.从这一点来看,Visual Studio 会查看您的项目。 An example would, if you copy File in your Project Folder, they wouldn't be recognized from Visual Studio.例如,如果您在项目文件夹中复制文件,则 Visual Studio 将无法识别它们。 You have to add them first to your sln File, to see them.您必须先将它们添加到您的sln文件中,才能看到它们。 It also allows the developer to combine multiple projects ( *.csproj ,..) into one single Solution to build.它还允许开发人员将多个项目 ( *.csproj ,..) 组合成一个解决方案来构建。

This means the idea behind these two editors is completely different.这意味着这两个编辑器背后的想法是完全不同的。


Visual Studio (not code) Project-types for Web Visual Studio(非代码)Web 项目类型


Workaround 1解决方法 1

A workaround would be a Blank Solution in which you set up your Visual Studio Code Project.一种解决方法是在其中设置 Visual Studio Code 项目的空白解决方案


Workaround 2解决方法 2

Another trick would be the answer to this question.另一个技巧是这个问题的答案 You can open your Project Folder as a Website Project.您可以将项目文件夹作为网站项目打开。

File -> Open Website -> File System and choose the folder文件 -> 打开网站 -> 文件系统并选择文件夹

Update更新

As you mentioned, there will be errors because Visual Studio tries to build the solutions.正如您提到的,会出现错误,因为 Visual Studio 尝试构建解决方案。 For the next few readers of this response, the work around for this (as John Pankowicz writes in the comment) is:对于此回复的接下来的几位读者,对此的解决方法(如 John Pankowicz 在评论中所写)是:

Right-click Web Site in Solution Explorer -> Property Pages -> Build -> Uncheck "Build Web Site as part of solution"在解决方案资源管理器中右键单击网站 -> 属性页 -> 构建 -> 取消选中“构建网站作为解决方案的一部分”


Update 2更新 2

(Thanks to JC1001 for this update) (感谢 JC1001 的这次更新)

The next version of Visual Studio (Visual Studio "15") will support opening a folder.下一版本的 Visual Studio(Visual Studio“15”)将支持打开文件夹。 This is mentioned in the Visual Studio Blog . Visual Studio 博客中提到了这一点。

Also like in Visual Studio Code, there will be a prompt command for opening Folders.也像在 Visual Studio Code 中一样,会有一个用于打开文件夹的提示命令。 Right now you can use this in the preview version:现在您可以在预览版中使用它:

devenv /command “file.openfolder FOLDER_PATH” devenv /command “file.openfolder FOLDER_PATH”

In the future you will be able to use:将来您将能够使用:

devenv FOLDER_PATH devenv FOLDER_PATH


Opinion观点

Personally I wouldn't recommend Visual Studio (not code) for HTML/Website projects without server-side-development, because I don't see any features.我个人不会推荐 Visual Studio(不是代码)用于没有服务器端开发的 HTML/网站项目,因为我看不到任何功能。 Even the intellisense suggests to me sometimes bad HTML Code (it's not the IDE's fault).甚至智能感知有时也会向我建议糟糕的 HTML 代码(这不是 IDE 的错)。

After all web projects are still text files.毕竟 web 项目仍然是文本文件。 You can easily control group projects like this with Version Control.您可以使用版本控制轻松控制这样的组项目。 Visual Studio Code even provides an integrated Git support . Visual Studio Code 甚至提供了集成的Git 支持

Finally folder view has arrived in VS 2017 :)最后文件夹视图已经到达 VS 2017 :)

在此处输入图片说明

You can find more details in here .您可以在此处找到更多详细信息。

Visual Studio Code does not create "project files" that you can open in Visual Studio 2015. Basically, when you open up a Node website in Visual Studio, you need to re-create the folder structure in VS2015 and create a "project file". Visual Studio Code 不会创建你可以在 Visual Studio 2015 中打开的“项目文件”。基本上,当你在 Visual Studio 中打开一个 Node 网站时,你需要在 VS2015 中重新创建文件夹结构并创建一个“项目文件” .

I haven't seen any better ways of doing this, but will be happy when we can open a folder just as easilly as we can with VSCode我还没有看到任何更好的方法来做到这一点,但是当我们可以像使用 VSCode 一样轻松地打开文件夹时会很高兴

I'm sure it's not the best way but..确定这不是最好的方法,但是..

Open an existing .sln with notepad, change the names, save as [name of your project].sln.使用记事本打开现有的 .sln,更改名称,另存为 [您的项目名称].sln。

Open with Visual Studio.使用 Visual Studio 打开。

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

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