sukesh
sukesh

Reputation: 2523

How to find the template of a Visual Studio project

I have a VS Solution with multiple projects of different types.
Is there a quick way to know the VS template used to create a project.

I would like to know if it is a Console app or ASP.NET MVC or ASP.NET Core or Class library etc.

Could not find that in project properties. It only shows "Output type", which can be same for class library/mvc projects and console/.net core projects.

Using VS 2019

Upvotes: 2

Views: 1939

Answers (1)

Adam Vincent
Adam Vincent

Reputation: 3811

The best I could come up with Roslyn is limited to this list

And here's a little Console app that takes in a solution file and spits out some basic info with the OutputKind

// install packages
// - Microsft.Build
// - Microsft.CodeAnalysis.Csharp.Workspaces
// - Microsft.CodeAnalysis.Workspaces.MSBuild
// https://learn.microsoft.com/en-us/dotnet/api/microsoft.codeanalysis.outputkind?view=roslyn-dotnet-4.2.0

using Microsoft.CodeAnalysis.MSBuild;

var solutionFile = @"C:\repos\MySolution.sln";

using var workspace = MSBuildWorkspace.Create();

var solution = await workspace.OpenSolutionAsync(solutionFile);
var projects = solution.Projects;

foreach (var project in projects)
{
    var name = project.Name;
    var language = project.Language;
    var kind = project.CompilationOptions.OutputKind;

    Console.WriteLine($"Project: {name}, Language: {language}, Kind: {kind}");
}

But then, I stumbled on something far more accurate! This list of known project type GUIDs could potentially be parsed from the solution file and matched with a well-known GUID and appears to be the identification you're looking for.

Edit: This list Is way better

Upvotes: 1

Related Questions