Visual Studio Project vs. Solution

2019-01-21 08:56发布

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

10条回答
Viruses.
2楼-- · 2019-01-21 09:03

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:

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.

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

查看更多
Deceive 欺骗
3楼-- · 2019-01-21 09:03

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

查看更多
家丑人穷心不美
4楼-- · 2019-01-21 09:05

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.

查看更多
Rolldiameter
5楼-- · 2019-01-21 09:09

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

查看更多
一夜七次
6楼-- · 2019-01-21 09:11

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.

查看更多
7楼-- · 2019-01-21 09:12

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.

For more details refer - 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.

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.

查看更多
登录 后发表回答