Visual Studio 项目与解决方案
作为VS新手,我怎么看待这两个概念,有什么区别?
Being new to VS, how may I think of these two concepts, what is the difference?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
作为VS新手,我怎么看待这两个概念,有什么区别?
Being new to VS, how may I think of these two concepts, what is the difference?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(10)
我在其他答案中发现了一些缺失的信息(至少对于来自其他 IDE(例如 Eclipse)的人来说)。说解决方案是项目的容器只是事情的一部分。 VS 项目的概念特征(决定其“粒度”的因素)是一个项目产生一个输出:通常是可执行文件或库 (dll)。因此,如果您要编写三个使用相关代码的可执行文件,您将创建一个解决方案和至少三个项目 - 可能更多。
I find some missing information in the other answers (at least for people who come from other IDEs like, say, Eclipse) . To say that a solution is a container for projects is only part of the thing. The conceptual feature of a VS project (what determines its 'granularity') is that one project produces one output: typically an executable or a library (dll). So, if you are going to code three executables that uses related code, you'll create one solution and at least three projects - probably more.
解决方案是项目的容器,并跟踪项目之间的依赖关系。
A solution is a container for projects, and tracks dependencies between projects.
只是想出一个比喻......
解决方案就像一座房子,一个项目就像一个房间。每个房间都提供一项功能,而房子作为房间的容器,提供将房间连接在一起并适当组织它们的方法。
有点老套,但我是临时编造的,所以请耐心等待:)
Just to come up with a metaphor..
A solution is like a house, a project like a room. Each room provides a piece of functionality whereas the house, a container of rooms, provides the means to link the rooms together and organize them appropriately.
Kind of corny but I made it up on the fly, so bear with me :)
Visual Studio 似乎让事情变得更加混乱,这无济于事。 “新建项目”实际上创建了一个包含项目的新解决方案。 “打开项目”实际上打开一个包含一个(或多个)项目的解决方案。 (文件菜单显示“打开项目/解决方案”,但它实际上是打开解决方案。没有“关闭项目”,只有“关闭解决方案”,这是准确的。
因此,在 VS 中,您始终在解决方案中工作。许多解决方案只包含一个项目和新的开发人员可能会将它们视为同一件事,但是您可以将其他项目添加到解决方案中。
It doesn't help that Visual Studio seems to make things more confusing. "New Project" actually creates a new SOLUTION containing a project. "Open Project" actually opens a solution containing one (or many) project. (The file menu says "Open Project/Solution" but it really is opening solutions. There is no "Close Project" only "Close Solution" which is accurate.
So, in VS you are always working within a solution. Many solutions contain only one project and newer developers are likely to think of them as the same thing. However you can add other projects into a solution.
如果有人决定向下滚动到目前为止...我认为 MS 文档 在描述差异方面做得非常好。我已在这里复制粘贴(并改写)相关部分:
解决方案具有关联的
.suo
文件,用于存储参与该项目的每个用户的设置、首选项和配置信息。In case anyone decides to scroll down this far... I thought the MS docs did a pretty good job at describing the differences. I've copy pasted (and rephrased) the relevant bits here:
A solution has an associated
.suo
file that stores settings, preferences and configuration information for each user that has worked on the project.一个解决方案可以有多个项目。
该解决方案还可以管理不同项目之间的依赖关系...确保每个项目都按照适当的顺序构建,以便最终解决方案发挥作用。
A Solution can have many Projects.
The Solution can also handle managing the dependencies between its different Projects...making sure that each Project gets Built in the appropriate order for the final Solution to work.
项目包含组成应用程序或应用程序组件的可执行文件和库文件。
解决方案是组成应用程序的逻辑相关项目的占位符。例如,您可以为应用程序的 GUI、数据库访问层等创建单独的项目。这些项目将是程序功能的特定部门,而解决方案将是将所有这些项目统一到一个应用程序下的总括。
A project contains executable and library files that make up an application or component of an application.
A solution is a placeholder for logically related projects that make up an application. For example, you could have separate projects for your application's GUI, database access layer, and so on. The projects would be specific divisions for your program's functionality, and the solution would be the umbrella unifying all of them under one application.
解决方案是一个可读的文本文件,其扩展名为
.sln
,并具有描述其包含的项目的结构化内容。 项目是一个可读的XML格式的文本文件,其扩展名为.vcxproj
,并根据其XML模式具有结构化内容,其主要用途是包含源代码文件名及其依赖项或对其他项目源代码的引用的列表。A solution is a readable text file whose extension is
.sln
and having a structured content that describes the projects that it contains. A project is a readable XML formatted text file whose extension is.vcxproj
and having a structured content according to its XML schema, and whose primary purpose is to contain the listing of source codes filenames and their dependencies or references to other project's source codes as well.解决方案是项目的容器 - 您还可以使用它们来组织在不同相关项目(共享 dll 等)中使用的项目。
Solutions are containers for projects - you can also use them to organize items that are used across different related project (shared dll's and such).
有关更多详细信息,请参阅 - https://learn.microsoft.com /en-us/visualstudio/ide/quickstart-projects-solutions
如果您有 Eclipse 背景,您可能会去构建项目路径并添加对其他项目的依赖项或添加外部 jar。在 VS 中,您可以在一个名为解决方案的容器中执行此操作,其中所有相关项目都分组在一起。
例如。假设您正在 xamrin 中构建 Android 和 iOS 应用程序,那么会有一些通用代码和资源可以放入单独的项目中,然后您的 Android 和 iOS 项目可以依赖于这个通用代码项目。您也可以有项目来测试这些项目等。
For more details refer - https://learn.microsoft.com/en-us/visualstudio/ide/quickstart-projects-solutions
If you are from an Eclipse background you would probably go to build path of a project and add a dependency on other project or add an external jar. In VS you can do that in a single container called solution where all related projects are grouped together.
Eg. Let's say you are build and android and iOS app in xamrin, there would be some common code and resources that could go in a separate project and then your android and iOS projects can depend on this common code project. Also you could have projects to test these projects etc.