Using NuGet Package Manager Console to get information about your .NET project

Posted: (EET/GMT+2)

 

Visual Studio has the convenient NuGet Package Manager Console window, which allows you to run PowerShell commands for project and NuGet package management tasks. It's great for automation, too.

Now, sometimes you might want to get more information about your current Visual Studio project you are working on. For instance, if it's and ASP.NET project, you might be interested in the current .NET Framework version, or the current browsing URL. Of course, you can get this information interactively from Visual Studio's user interface, but in many cases, automation is the key.

To get project information, try this. First, open the Package Manager Console window using the View/Other Windows/Package Manager Console menu command. Then, at the "PM>" prompt, type in the following variable declaration command:

$proj=get-project NameOfYourProject

Above, replace the "NameOfYourProject" with the name of your Visual Studio code project, such as "WebApplication1". At this point, press Enter, and you have now declared a new variable called "$proj".

Next, you can query properties from the variable, like this:

$proj.Type

This will output the project's compiling type, such as "C#".

Use this command to get the .NET Framework version you are building against:

$proj.Properties["TargetFrameworkMoniker"].Value

This will output a version string such as ".NETFramework,Version=v4.5".

There are many other properties to query, such as:

$proj.Properties["WebApplication.CurrentDebugUrl"].Value

This would return the startup URL of the current ASP.NET application. You can also query for details defined in the AssemblyInfo.cs source file, such as the application version:

$proj.Properties["AssemblyVersion"].Value

To get a full list of supported properties, simply say:

$proj.Properties

Good luck!