Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list all target frameworks of all projects for a given solution inside Visual Studio?

Given an opened solution in Visual Studio, how do I quickly check which target frameworks the various projects in the solution have? Is there a solution-wide view somewhere that shows which target framework each project targets, or an aggregate view of how many projects target each framework version?

I'm aware I can check each project individually (either on properties window or on the csproj file itself), however in a solution with 100+ projects this is not feasible.

Additionally, I know I could probably do some sort of regex search inside csproj files in the root folder, but I was wondering if there was something built-in in Visual Studio to provide this data.

like image 672
julealgon Avatar asked Jan 29 '26 02:01

julealgon


1 Answers

You could get MSBuild to print this out for you.

Add a Directory.Build.targets file at the top level of your code that prints out the TargetFramework value.

This does the trick for me:

<Project>

  <Target Name="LogTargetFramework" AfterTargets="CoreCompile">
    <Message
      Importance="high"
      Text="Project $(MSBuildProjectName): $(TargetFramework)"/>
  </Target>

</Project>

Adding that to, for example, the MetadataExtractor solution and rebuilding it produces:

1>Project MetadataExtractor: net35
1>Project MetadataExtractor: net45
1>Project MetadataExtractor: netstandard2.0
1>Project MetadataExtractor: netstandard1.3
3>Project MetadataExtractor.PowerShell: net40
2>Project MetadataExtractor.Samples: net48
5>Project MetadataExtractor.Tools.JpegSegmentExtractor: net6.0
4>Project MetadataExtractor.Benchmarks: net461
7>Project MetadataExtractor.Tests: net472
6>Project MetadataExtractor.Tools.FileProcessor: net6.0
7>Project MetadataExtractor.Tests: net6.0

Using MSBuild to get this data means you'll get correct results. Parsing XML is no substitute for actually running the build, as property values can be overridden in any number of ways.

like image 98
Drew Noakes Avatar answered Jan 31 '26 22:01

Drew Noakes