I have a list of Project GUIDs from a sln file.
I need to find the project corresponding to each GUID programatically.
How can I do this?
I have a list of Project GUIDs from a sln file.
I need to find the project corresponding to each GUID programatically.
How can I do this?
Project GUIDs are stored along side the project name inside of the .sln file like so:
Project("{Project Type GUID}") = "MyProject",
"Source\MyProject\MyProject.vbproj",
"{AB5BA87B-77D5-4812-B02C-9B4FB87F4EF6}" EndProject
Theoretically you could preparse the solution file and build up a map of Project-To-GUID associations. Once you have that map established, you should be able to quite easily swap out any references to a project's GUID with the actual project name.
Note: the first GUID you see in the project file is for the project type, NOT the actual project. This helps Visual Studio manage what template to use when opening and working with the file. The one you want in this case is {AB5BA87B-77D5-4812-B02C-9B4FB87F4EF6}.
All Visual Studio setup resides in the registry, in a key like this:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\[Version]
Version can be like "9.0" (VS 2008), "10.0" (VS 2010), "11.0" (VS 2012), but it can also be anything else because Visual Studio can be started with a custom 'hive' key (see the /RootSuffix parameter of the devenv.exe command line).
So, for normal operation, project guids are located here:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\[Version]\Projects
Projects in Visual Studio can be standard projects (C#, VB.NET, etc.) or aggregate projects (the WPF "flavor" over C# or VB.NET).
In general, projects have a "Package" key that contains the guid of the Visual Studio Package (the binaries) containing the type of project.
Packages descriptions are to be found here:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\[Version]\Packages
Native packages (C#, VB.NET, C++, ...) are implemented as native COM servers and the path is defined in the InprocServer32
key. Managed packages define MSCOREE.DLL as the InprocServer32
key and there is also a CodeBase
key is the package is not in the GAC and only an Assembly
key if the package is in the GAC.
I may be very late to answer this question, but in the hopes of helping any other person who wonders over this question. There are several assemblies that you would like to use for parsing solution and project files in C#, they are:
Microsoft.Build.Evaluation
and
Microsoft.Build.Construction
With in the later assembly there is a class called SolutionFile
. Documentation. Within the documentation SolutionFile
contains the property ProjectsByGuid
, on which you can do a linq query on if you already have the GUID. The code to do this would look a little like this:
var guid = "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}"
var pathToSolutionFile = "C:\users\user\source\repos\solution\solution.sln"
var sln = SolutionFile.Parse(pathToSolutionFile);
var projectName = sln.ProjectsByGuid.Where(x => x.key==guid)
.FirstOrDefault().Value?.projectname;
I hope this helps you, or anyone else.