Home: How can I detect the Nuget Version used by Visual Studio 2015 programmatically?

Created on 3 Aug 2017  路  4Comments  路  Source: NuGet/Home

Details about Problem

NuGet product used (NuGet.exe | VS UI | Package Manager Console | dotnet.exe): VS UI, MSBuild

NuGet version (x.x.x.xxx):

dotnet.exe --version (if appropriate):

VS version (if appropriate): 14.0.25431.01 Update 3

OS version (i.e. win10 v1607 (14393.321)): Windows 8.1 (6.3.9600)

Worked before? If so, with which NuGet version:

What I know how to do

Help => About in Visual Studio 2015 shows the NuGet Package Manager version.

image

What I'm looking for

I would like to retrieve Nuget Package Manager version used by Visual Studio 2015 programatically.

Why I would like this

There are issues in earlier versions of the Visual Studio 2015 Nuget Package Manager that affect our build. #5654 is one such bug. I would like to add to our prerequisites check scripts a test for the Visual Studio 2015 Nuget Package Manager version to avoid inadvertently using older versions of Nuget. To do so, I need to programatically retrieve the Nuget Package Manager version used by Visual Studio.

Question

All 4 comments

You could search for nuget dlls in the VS 2015 install folder to find the VSIX location, then look at the assembly version.

From an extension in VS you could import IVsPackageInstaller and then check which assembly the instance returned came from, then check the assembly metadata on that.

@alx9r Does the above answer satisfy your needs?
Thanks.

@nkolev92 It sounds promising, but I haven't had a chance to test it yet.

This seems to work:

Describe 'Visual Studio 2015 Nuget Package Management Version' {
    $h = @{}
    It 'find latest installed version' {
        $h.NugetPmVersion = Get-ChildItem "${Env:ProgramFiles(x86)}\Microsoft Visual Studio 14.0\Common7\IDE\Extensions" -Filter NuGet.PackageManagement.UI.dll -Recurse |
            % { $_.VersionInfo.FileVersion } |
            Sort -Descending |
            Select -First 1
        $h.NugetPmVersion | Should not beNullOrEmpty
    }
    It 'latest installed version is at least version 3.5' {
        $h.NugetPmVersion | Should BeGreaterThan '3.5'
    }
}

Thanks for the guidance @emgarten.

Was this page helpful?
0 / 5 - 0 ratings