In Visual Studio, the context menu command for adding an element in a WinForms project is different by the one showed for a WPF project. In fact, I can see "Add->Windows Form" in the first and "Add->Window" in the second. By which parameter/configuration VisualStudio can differentiate which kind of project is currently opened? My first bet was the .csproj file but I can see nothing distinctive about the project type.
4 Answers
There is often a ProjectTypeGuids
element in the project file that allows Visual Studio to determine what project type it is. It's also stated in the solution file, referencing the project.
<ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
as an example.
Here's a somewhat old link to a list of project guids, but most are still valid: http://onlinecoder.blogspot.se/2009/09/visual-studio-projects-project-type.html
And here's a blogpost, outlining what it's all about:
http://www.dzimchuk.net/blog/post/ProjectTypeGuids-node-in-VS-project-files.aspx
"On a regular class library project the ‘ProjectTypeGuids’ node was missing at all. It didn’t take long to find what those mysterious GUID’s are about: List of known project type Guids. So the first one says it’s a WPF project and the second one says it’s a C# project."
ProjectTypeGuids
identify the type of project that Visual Studio recognizes. It is contained in the project file and solution file. A project can belong to multiple project types such as C# and VSTO.
WPF has a GUID of {60dc8134-eba5-43b8-bcc9-bb4bc16c2548}
while WinForms has a GUID of {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
with OutputType WinExe
.

- 1
- 1

- 31,051
- 11
- 110
- 173
It is actually a GUID in the .sln
file that identifies the project type.
Project("{PROJECT-TYPE-GUID}") = "OurSolution.Tests.Integration", "OurSolution.Tests.Integration\OurSolution.Tests.Integration.csproj", "{04A96D9A-FF90-4FDC-9265-704CC8D496BE}"

- 5,761
- 33
- 47
-
While, yes, it's in the solution file as well, it's originally in the proj-file if it's anything but a class library. Otherwise it'd be damned difficult to import a project into another solution. =) – J. Steen Jul 24 '12 at 12:55
-
@J. Steen Thank you, didn't know that. I wonder what receives priority when loading using a solution. – Myrtle Jul 24 '12 at 12:56
-
I'd assume the solution file, considering it loads first - but I'm far from certain - so I guess the _actual_ answer to the question "how does VS know" would be, as you've said: the solution file. ;) – J. Steen Jul 24 '12 at 12:57
Almost right, it's in the solution file. Search for the property ProjectTypeGuids.
Here's a list of some GUID's for project types: http://www.mztools.com/articles/2008/mz2008017.aspx
Edit: see this post for answers as well: How do you tell the Visual Studio project type from an existing Visual Studio project