visual-studio Visual Studio 中的“添加现有项目...”是如何工作的?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1212056/
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:49:44  来源:igfitidea点击:

How is "Add Existing Item..." in Visual Studio meant to work?

visual-studio

提问by Edward Tanguay

I never use "Add existing item..."feature in Visual Studio's Solution Explorer because it is confusing:

我从不使用Visual Studio 的解决方案资源管理器中的“添加现有项目...”功能,因为它令人困惑:

  • it seems to me the way it should work is that if you have a Customer.cs file in Models directory, that you could choose "Add existing item", it would then show you which items exist in that directoryan allow you to choose one. Instead, it opens a file dialogue to some seemingly random directory on your hard drive, and I'm not sure if it is going to make a copyof that file, or use it outsidethe solution, etc.
  • instead, if I want to "add an existimg item", I go into windows explorer, click file, CTRL-C, click folder in solution explorer, ctrl-v, and it is clear
  • 在我看来,它应该工作的方式是,如果您在 Models 目录中有一个 Customer.cs 文件,您可以选择“添加现有项目”,然后它会显示该目录中存在哪些项目并允许您选择一个. 相反,它会打开一个文件对话框,指向您硬盘驱动器上某个看似随机的目录,我不确定它是要制作该文件的副本,还是在解决方案之外使用它,等等。
  • 相反,如果我想“添加一个existimg项目”,我进入Windows资源管理器,单击文件,CTRL-C,单击解决方案资源管理器中的文件夹,ctrl-v,很明显

Do others do it differently? Am I missing something about how "add existing item" in solution explorer is supposed to work?

其他人的做法不同吗?我是否缺少有关解决方案资源管理器中“添加现有项目”应该如何工作的信息?

回答by Marc Gravell

The folder opens where-ever you last left it...

该文件夹会在您上次离开的地方打开...

As for using this feature; by default(Add) it does IMO the least useful thing; copythe file. But if you notice, the add button is actually a drop-down; hit the down arrow and you can add a linkto the file - i.e. leave it where it is and reference it by location (Add As Link).

至于使用这个功能;由默认的Add),它IMO确实是最有用的东西; 复制文件。但是如果您注意到,添加按钮实际上是一个下拉菜单;点击向下箭头,您可以添加指向该文件的链接- 即,将其保留在原处并按位置 ( Add As Link)引用它。

回答by Chris Shaffer

The quick and easy way to do what you are trying to do (add an existing file that already exists within the folder in your project) is:

执行您正在尝试执行的操作(添加项目中文件夹中已存在的现有文件)的快速简便方法是:

  • At the top of the Solution Explorer window is an icon/button for "Show All Files", enable it (if it is already enabled and the file you are looking for is not shown, click "Refresh"). Note that this setting is enabled on a per project basis.
  • Right click on the file that you want to include and select "Include in Project".
  • 在解决方案资源管理器窗口的顶部是“显示所有文件”的图标/按钮,启用它(如果它已经启用并且您要查找的文件未显示,请单击“刷新”)。请注意,此设置是基于每个项目启用的。
  • 右键单击要包含的文件,然后选择“包含在项目中”。

回答by Aamir

Add Existing file adds the file to the project. Keeping it in the project directory is something different and making it a part of the project is something different. By making it a part of the project, its entry is made in .csproj/.vcproj/etc and then further properties can be set of this file such as specifying a custom build step etc.

添加现有文件将文件添加到项目中。将它保存在项目目录中是不同的,而使其成为项目的一部分是不同的。通过使其成为项目的一部分,其条目在 .csproj/.vcproj/etc 中,然后可以设置此文件的更多属性,例如指定自定义构建步骤等。

And No, it doesn't create a copy of the file in your current project's directory in case of a Visual C++ project. In case of a CSharp Project, it does create a copy.

不,如果是 Visual C++ 项目,它不会在当前项目的目录中创建文件的副本。如果是 CSharp 项目,它会创建一个副本。

e.g., I use this when I need to add a bitmap/png file in my project which I have gotten from an external source. I just copy the file to my project directory and then use Add Existing File to add this to the project.

例如,当我需要在我的项目中添加一个位图/png 文件时,我会使用它,该文件是从外部来源获得的。我只是将文件复制到我的项目目录,然后使用添加现有文件将其添加到项目中。

回答by Arnis Lapsa

I'm using it. I even didn't know it's possible to ctrl+c ctrl+v in solution explorer.

我正在使用它。我什至不知道可以在解决方案资源管理器中按 ctrl+c ctrl+v 。

It's particulary handy, if you want to add something 'as link'.

如果您想添加“作为链接”的内容,它特别方便。

回答by Josip Medved

I do use it but often I just add file as a link. That make it easier to maintain some common classes if you do not want to make full assembly out of them.

我确实使用它,但通常我只是将文件添加为链接。如果您不想完全组装它们,那么维护一些公共类会更容易。

回答by Steven

As far as my experience goes using this function, it does the same copy and paste that you are describing.

就我使用此功能的经验而言,它执行的复制和粘贴操作与您所描述的相同。