visual-studio Visual Studio 项目与解决方案

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

Visual Studio Project vs. Solution

visual-studioprojects-and-solutionssolutionvisual-studio-project

提问by bmw0128

Being new to VS, how may I think of these two concepts, what is the difference?

VS新手,怎么想到这两个概念,有什么区别?

采纳答案by pzr

A solution is a container for projects, and tracks dependencies between projects.

解决方案是项目的容器,并跟踪项目之间的依赖关系。

回答by leonbloy

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.

我在其他答案中发现了一些缺失的信息(至少对于来自其他 IDE 的人,比如 Eclipse)。说解决方案是项目的容器只是事情的一部分。VS 项目的概念特征(决定其“粒度”的因素)是一个项目产生一个输出:通常是可执行文件或库 (dll)。因此,如果您要编写三个使用相关代码的可执行文件,您将创建一个解决方案和至少三个项目 - 可能更多。

回答by Cody C

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 :)

有点陈词滥调,但我是即时编造的,所以请耐心等待:)

回答by Chryses

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.

Visual Studio 似乎让事情变得更加混乱,这无济于事。“新项目”实际上创建了一个包含项目的新解决方案。“打开项目”实际上是打开一个包含一个(或多个)项目的解决方案。(文件菜单上写着“打开项目/解决方案”,但它确实是打开解决方案。没有“关闭项目”,只有“关闭解决方案”是准确的。

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.

因此,在 VS 中,您总是在解决方案中工作。许多解决方案只包含一个项目,新的开发人员可能会将它们视为同一件事。但是,您可以将其他项目添加到解决方案中。

回答by jrahhali

In case anyone decides to scroll down this far... I thought the MS docsdid a pretty good job at describing the differences. I've copy pasted (and rephrased) the relevant bits here:

如果有人决定向下滚动到这里……我认为MS 文档在描述差异方面做得很好。我在这里复制粘贴(并重新表述)了相关的部分:

When you create an app, application, website, Web App, script, plug-in, etc in Visual Studio, you start with a project. In a logical sense, a project contains of all the source code files, icons, images, data files and anything else that will be compiled into an executable program or web site, or else is needed in order to perform the compilation. A project also contains all the compiler settings and other configuration files that might be needed by various services or components that your program will communicate with.

You don't have to use solutions or projects if you don't want to. You can simply open the files in Visual Studio and start editing your code.

In a literal sense, a project is an XML file (.vbproj, .csproj, .vcxproj) that defines a virtual folder hierarchy along with paths to all the items it "contains" and all the build settings.

In Visual Studio, the project file is used by Solution Explorer to display the project contents and settings. When you compile your project, the MSBuild engine consumes the project file to create the executable. You can also customize projects to product other kinds of output.

A project is contained, in a logical sense and in the file system, within a solution, which may contain one or more projects, along with build information, Visual Studio window settings, and any miscellaneous files that aren't associated with any project. In a literal sense, the solution is a text file with its own unique format; it is generally not intended to be edited by hand.

当您在 Visual Studio 中创建应用程序、应用程序、网站、Web 应用程序、脚本、插件等时,您将从一个项目开始。从逻辑上讲,一个项目包含所有源代码文件、图标、图像、数据文件和任何其他将被编译成可执行程序或网站的东西,或者为了执行编译而需要的任何东西。项目还包含您的程序将与之通信的各种服务或组件可能需要的所有编译器设置和其他配置文件。

如果您不想,您不必使用解决方案或项目。您只需在 Visual Studio 中打开文件并开始编辑代码即可。

从字面上看,项目是一个 XML 文件(.vbproj.csproj.vcxproj),它定义了一个虚拟文件夹层次结构以及它“包含”的所有项目的路径和所有构建设置。

在 Visual Studio 中,解决方案资源管理器使用项目文件来显示项目内容和设置。编译项目时,MSBuild 引擎使用项目文件来创建可执行文件。您还可以自定义项目以生成其他类型的输出。

一个项目在逻辑意义上包含在文件系统中,包含在一个解决方案中,该解决方案可能包含一个或多个项目,以及构建信息、Visual Studio 窗口设置以及与任何项目无关的任何杂项文件。从字面上看,解决方案是一个具有自己独特格式的文本文件;它通常不打算手动编辑。

A solution has an associated .suofile that stores settings, preferences and configuration information for each user that has worked on the project.

解决方案有一个关联.suo文件,用于存储参与该项目的每个用户的设置、首选项和配置信息。

回答by Justin Niessner

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.

解决方案还可以管理其不同项目之间的依赖关系……确保每个项目以适当的顺序构建,以便最终解决方案工作。

回答by David

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.

解决方案是构成应用程序的逻辑相关项目的占位符。例如,您可以为应用程序的 GUI、数据库访问层等设置单独的项目。这些项目将是您程序功能的特定部门,而解决方案将是将所有项目统一到一个应用程序下的保护伞。

回答by typelogic

A solutionis a readable text file whose extension is .slnand having a structured content that describes the projectsthat it contains. A projectis a readable XMLformatted text file whose extension is .vcxprojand 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.

一个解决方案是可读的文本文件,其扩展.sln并具有描述一个结构化内容的项目,它包含的内容。一个项目是可读的XML格式的文本文件,其扩展名是.vcxproj根据它的XML模式具有结构化的内容,其主要目的是包含源代码的文件名和它们的依赖或引用其他项目的源代码,以及上市。

回答by Oded

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).

解决方案是项目的容器 - 您还可以使用它们来组织跨不同相关项目(共享 dll 等)使用的项目。

回答by Aniket Thakur

Solutions are containers used by Visual Studio to organize one or more related projects. When you open a solution in Visual Studio, it will automatically load all the projects it contains.

When you create a new project in Visual Studio, it automatically creates a solution to house the project if there's not a solution already open.

You can set dependencies of projects on other projects in the solution. The dependent project is build after the project it is depending on is built.

解决方案是 Visual Studio 用来组织一个或多个相关项目的容器。当你在 Visual Studio 中打开一个解决方案时,它会自动加载它包含的所有项目。

在 Visual Studio 中创建新项目时,如果尚未打开解决方案,它会自动创建一个解决方案来容纳该项目。

您可以在解决方案中设置项目对其他项目的依赖关系。依赖项目是在它所依赖的项目构建之后构建的。

For more details refer - https://docs.microsoft.com/en-us/visualstudio/ide/quickstart-projects-solutions

有关更多详细信息,请参阅 - https://docs.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.

如果您来自 Eclipse 背景,您可能会去构建项目的路径并添加对其他项目的依赖或添加外部 jar。在 VS 中,您可以在名为解决方案的单个容器中执行此操作,其中所有相关项目都组合在一起。

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.

例如。假设您正在 xamrin 中构建 android 和 iOS 应用程序,会有一些公共代码和资源可以放在单独的项目中,然后您的 android 和 iOS 项目可以依赖于这个公共代码项目。你也可以有项目来测试这些项目等。