Edit

NuGet API in Visual Studio

In addition to the Package Manager UI and Console in Visual Studio, NuGet also exports some useful services that other extensions can use. These interfaces allow other components in Visual Studio to interact with NuGet, which can be used to install and uninstall packages, and to obtain information about installed packages.

NuGet provides services via two different technologies, each of which have their interfaces defined in a different NuGet package. NuGet's older services are available via the Managed Extensibility Framework (MEF), which are available in the package NuGet.VisualStudio (go to NuGet's MEF services). There are newer APIs, designed to be usable with async code, available in the package NuGet.VisualStudio.Contracts, using a Visual Studio's IServiceBroker (go to NuGet's Brokered Services).

Package Versions

NuGet's product follows Visual Studio's version, but is 11.0 versions behind. For example, NuGet 6.0 corresponds to Visual Studio 2022 17.0, NuGet 5.11 corresponds to Visual Studio 2019 16.11, and so on.

Starting from Visual Studio 17.1, NuGet's Visual Studio extensibility API packages match the version of Visual Studio that the APIs are targeting. For example, NuGet.VisualStudio and NuGet.VisualStudio.Contracts package version 17.1.0 should be used when your extension targets Visual Studio 17.1 and higher. In Visual Studio 17.0 and earlier, NuGet's package versions are the same as NuGet's product version. For example, if your extension targets Visual Studio 2022 version 17.0, you should use version 6.0 of NuGet's Visual Studio extensibility packages.

NuGet Client SDK in Visual Studio Extensions

Only the APIs in NuGet.VisualStudio and NuGet.VisualStudio.Contracts are supported in Visual Studio extensions. NuGet provides binding redirects for these assemblies, so these assemblies do not need to be included in your extension.

Using NuGet Client SDK packages, for example NuGet.Protocol, is not supported in Visual Studio extensions. NuGet does not provide binding redirects for these assemblies. See the NuGet Client SDK support policy for more information.

Services List

Brokered Services

These services are available in the package NuGet.VisualStudio.Contracts.

MEF Services

From NuGet 6.0, all of these APIs are available in the package NuGet.VisualStudio. In NuGet 5.11 and earlier, the APIs in the namespace NuGet.VisualStudio are available in the package NuGet.VisualStudio, and APIs in the namespace NuGet.SolutionRestoreManager are available in the package NuGet.SolutionRestoreManager.Interop.

NuGet.VisualStudio

NuGet.SolutionRestoreManager

These interfaces are designed for project systems to interact with NuGet, allowing the project system to notify NuGet of changes to PackageReferences, and orchestrate batch updates. Visual Studio extensions that are not project systems probably will not benefit from these APIs.

Using NuGet Services

Warning

Do not use any other types besides the public interfaces in your code, and do not reference any other NuGet assemblies, such as NuGet.Protocol.dll, NuGet.Frameworks.dll, and so on.

In order to maximize the backwards compatibility promises we make, but also providing ourselves the flexibility to implement new features, performance improvements, and bug fixes in Visual Studio, we do not support the NuGet Client SDK being used in Visual Studio, and we do not provide binding redirects in devenv.exe.config to assemblies other than our VS extensibility contracts.

If you would like a new NuGet related API in Visual Studio, please search NuGet's Home repo and upvote any existing issues if you find a similar one. If you can't find an existing feature request to upvote, please create one.

Brokered Services

  1. Install the NuGet.VisualStudio.Contracts package into your project, as well as Microsoft.VisualStudio.SDK.

  2. Use the IAsyncServiceProvider to get Visual Studio's service broker, and use that to get NuGet's service. Note that AsyncPackage extends IVsAsyncServiceProvider2, so your class that implements AsyncPackage can be used as the IAsyncServiceProvider. Also see the docs on IBrokeredServiceContainer and IServiceBroker

    // Your AsyncPackage implements IAsyncServiceProvider
    IAsyncServiceProvider asyncServiceProvider = this;
    var brokeredServiceContainer = await asyncServiceProvider.GetServiceAsync();
    var serviceBroker = brokeredServiceContainer.GetFullAccessServiceBroker();
    var nugetProjectService = await serviceBroker.GetProxyAsync(NuGetServices.NuGetProjectServiceV1);
    
  3. When your code no longer needs NuGet's brokered service, dispose it. For example, if you only need NuGet's brokered service during a single method call, you can wrap it in a C#using statement:

    InstalledPackagesResult installedPackagesResult;
    using (nugetProjectService as IDisposable)
    {
        installedPackagesResult = await nugetProjectService.GetInstalledPackages(projectGuid, cancellationToken);
    }
    

MEF Services

  1. Install the NuGet.VisualStudio package into your project, which contains the NuGet.VisualStudio.dll assembly.

    In NuGet 5.11 and earlier, the package automatically sets the Embed Interop Types property of the assembly reference to True. Visual Studio 2022 policy regarding embed interop types changed, so NuGet.VisualStudio package version 6.0.0 and above no longer use this.

  2. To use a service, import it through the MEF Import attribute, or through the IComponentModel service.

    //Using the Import attribute
    [Import(typeof(IVsPackageInstaller2))]
    public IVsPackageInstaller2 packageInstaller;
    packageInstaller.InstallLatestPackage(null, currentProject,
        "Newtonsoft.Json", false, false);
    
    //Using the IComponentModel service
    var componentModel = (IComponentModel)GetService(typeof(SComponentModel));
    IVsPackageInstallerServices installerServices =
        componentModel.GetService();
    
    var installedPackages = installerServices.GetInstalledPackages();
    

For reference, the source code for NuGet.VisualStudio is contained within the NuGet.Clients repository.

Understanding the .NET project systems

When SDK style projects were added for .NET Core 1.0, it was designed to be more asynchronous than previous Visual Studio project systems. This has an impact on how all other Visual Studio components interact with it directly, or though other components such as NuGet. This is most noticeable on solution load and project load, where projects are not fully available some time after Visual Studio's older synchronous API notifications have already fired.

During solution load, NuGet ignores IVsSolutionEvents.OnAfterProjectLoad, in order to avoid delaying the synchronous part of solution load. NuGet will synchronize its internal data structures after the synchronous part of solution load has completed. This is also true for non-SDK style projects.

Even after all IVsSolutionEvents.OnAfterSolutionLoad event handlers finish, this only signals the end of the synchronous part of solution load. The asynchronous part of solution load is still in progress. Therefore, if your extension calls NuGet APIs like GetInstalledPackagesAsync or InstallPackage soon after project or solution load, NuGet might throw an InvalidOperationException with message similar to "The operation failed as details for project {project name} could not be loaded.".

When a solution contains at least one SDK style project, NuGet will automatically perform a restore after solution load, and you should not call any Nuget APIs until this is complete. You can use IVsNuGetProjectUpdateEvents to get a notification when the solution restore, or when specific project restores, complete. If a solution does not contain any SDK style projects, then restore will not be scheduled automatically, and may not happen until a build is scheduled.

In order to determine whether a project uses NuGet's asynchronous flow (SDK style project), use PackageUtilities.IsCapabilityMatch with the expression CPS + PackageReference.

INuGetProjectService interface

    /// Service to interact with projects in a solution
    /// This interface should not be implemented. New methods may be added over time.
    public interface INuGetProjectService
    {
        /// Gets the list of packages installed in a project.
        /// Project ID (GUID).
        /// Cancellation token.
        /// The list of packages in the project.
        Task GetInstalledPackagesAsync(Guid projectId, CancellationToken cancellationToken);
    }

IRegistryKey interface

/// 
/// Specifies methods for manipulating a key in the Windows registry.
/// 
public interface IRegistryKey
    {
    /// 
    /// Retrieves the specified subkey for read or read/write access.
    /// 
    /// The name or path of the subkey to create or open.
    /// The subkey requested, or null if the operation failed.
    IRegistryKey OpenSubKey(string name);


    /// 
    /// Retrieves the value associated with the specified name.
    /// 
    /// The name of the value to retrieve. This string is not case-sensitive.
    /// The value associated with name, or null if name is not found.
    object GetValue(string name);


    /// 
    /// Closes the key and flushes it to disk if its contents have been modified.
    /// 
    void Close();
}

IVsCredentialProvider interface

    /// 
    /// Contains methods to get credentials for NuGet operations.
    /// 
    public interface IVsCredentialProvider
    {
        /// 
        /// Get credentials for the supplied package source Uri.
        /// 
        /// The NuGet package source Uri for which credentials are being requested. Implementors are
        /// expected to first determine if this is a package source for which they can supply credentials.
        /// If not, then Null should be returned.
        /// Web proxy to use when comunicating on the network.  Null if there is no proxy
        /// authentication configured.
        /// True if if this request is to get proxy authentication
        /// credentials. If the implementation is not valid for acquiring proxy credentials, then
        /// null should be returned.
        /// True if credentials were previously acquired for this uri, but
        /// the supplied credentials did not allow authorized access.
        /// If true, then interactive prompts must not be allowed.
        /// This cancellation token should be checked to determine if the
        /// operation requesting credentials has been cancelled.
        /// Credentials acquired by this provider for the given package source uri.
        /// If the provider does not handle requests for the input parameter set, then null should be returned.
        /// If the provider does handle the request, but cannot supply credentials, an exception should be thrown.
        Task GetCredentialsAsync(Uri uri,
            IWebProxy proxy,
            bool isProxyRequest,
            bool isRetry,
            bool nonInteractive,
            CancellationToken cancellationToken);
    }

IVsFrameworkCompatibility interface

    /// 
    /// Contains methods to discover frameworks and compatibility between frameworks.
    /// 
    public interface IVsFrameworkCompatibility
    {
        /// 
        /// Gets all .NETStandard frameworks currently supported, in ascending order by version.
        /// 
        /// This API is free-threaded.
        IEnumerable GetNetStandardFrameworks();

        /// 
        /// Gets frameworks that support packages of the provided .NETStandard version.
        /// 
        /// 
        /// The result list is not exhaustive as it is meant to human-readable. For example,
        /// equivalent frameworks are not returned. Additionally, a framework name with version X
        /// in the result implies that framework names with versions greater than or equal to X
        /// but having the same  are also supported.
        ///
        /// This API is free-threaded.
        /// 
        /// The .NETStandard version to get supporting frameworks for.
        [Obsolete("This API does not support .NET 5 and higher target frameworks with platforms. Use IVsFrameworkCompatibility3 instead.")]
        IEnumerable GetFrameworksSupportingNetStandard(FrameworkName frameworkName);

        /// 
        /// Selects the framework from  that is nearest
        /// to the , according to NuGet's framework
        /// compatibility rules. null is returned of none of the frameworks
        /// are compatible.
        /// 
        /// This API is free-threaded.
        /// The target framework.
        /// The list of frameworks to choose from.
        /// If any of the arguments are null.
        /// The nearest framework.
        [Obsolete("This API does not support .NET 5 and higher target frameworks with platforms. Use IVsFrameworkCompatibility3 instead.")]
        FrameworkName GetNearest(FrameworkName targetFramework, IEnumerable frameworks);
    }

IVsFrameworkCompatibility2 interface

    /// 
    /// Contains methods to discover frameworks and compatibility between frameworks.
    /// 
    [Obsolete("This API does not support .NET 5 and higher target frameworks with platforms. Use IVsFrameworkCompatibility3 instead.")]
    public interface IVsFrameworkCompatibility2 : IVsFrameworkCompatibility
    {
        /// 
        /// Selects the framework from  that is nearest
        /// to the , according to NuGet's framework
        /// compatibility rules. null is returned of none of the frameworks
        /// are compatible.
        /// 
        /// This API is free-threaded.
        /// The target framework.
        /// 
        /// Target frameworks to use if the provided  is not compatible.
        /// These fallback frameworks are attempted in sequence after .
        /// 
        /// The list of frameworks to choose from.
        /// If any of the arguments are null.
        /// The nearest framework.
        [Obsolete("This API does not support .NET 5 and higher target frameworks with platforms. Use IVsFrameworkCompatibility3 instead.")]
        FrameworkName GetNearest(
            FrameworkName targetFramework,
            IEnumerable fallbackTargetFrameworks,
            IEnumerable frameworks);
    }

IVsFrameworkCompatibility3 interface

    /// 
    /// Contains methods to discover frameworks and compatibility between frameworks.
    /// 
    public interface IVsFrameworkCompatibility3
    {
        /// 
        /// Selects the framework from  that is nearest
        /// to the , according to NuGet's framework
        /// compatibility rules. null is returned of none of the frameworks
        /// are compatible.
        /// 
        /// The target framework.
        /// The list of frameworks to choose from.
        /// If any of the arguments are null.
        /// If any of the frameworks cannot be parsed.
        /// The nearest framework.
        /// This API is free-threaded.
        IVsNuGetFramework GetNearest(IVsNuGetFramework targetFramework, IEnumerable frameworks);

        /// 
        /// Selects the framework from  that is nearest
        /// to the , according to NuGet's framework
        /// compatibility rules. null is returned of none of the frameworks
        /// are compatible.
        /// 
        /// The target framework.
        /// 
        /// Target frameworks to use if the provided  is not compatible.
        /// These fallback frameworks are attempted in sequence after .
        /// 
        /// The list of frameworks to choose from.
        /// If any of the arguments are null.
        /// If any of the frameworkscannot be parsed.
        /// The nearest framework.
        /// This API is free-threaded.
        IVsNuGetFramework GetNearest(
            IVsNuGetFramework targetFramework,
            IEnumerable fallbackTargetFrameworks,
            IEnumerable frameworks);
    }

IVsFrameworkParser interface

    /// 
    /// An interface for dealing with the conversion between strings and 
    /// instances.
    /// 
    [Obsolete("This API does not support .NET 5 and higher target frameworks with platforms. Use IVsFrameworkParser2 instead.")]
    public interface IVsFrameworkParser
    {
        /// 
        /// Parses a short framework name (e.g. "net45") or a full framework name
        /// (e.g. ".NETFramework,Version=v4.5") into a 
        /// instance.
        /// 
        /// This API is free-threaded.
        /// The framework string.
        /// If the provided string is null.
        /// If the provided string cannot be parsed.
        /// The parsed framework.
        [Obsolete("This API does not support .NET 5 and higher target frameworks with platforms. Use IVsFrameworkParser2 instead.")]
        FrameworkName ParseFrameworkName(string shortOrFullName);

        /// 
        /// Gets the shortened version of the framework name from a 
        /// instance.
        /// 
        /// 
        /// For example, ".NETFramework,Version=v4.5" is converted to "net45". This is the value
        /// used inside of .nupkg folder structures as well as in project.json files.
        /// This API is free-threaded.
        /// 
        /// The framework name.
        /// If the input is null.
        /// 
        /// If the provided framework name cannot be converted to a short name.
        /// 
        /// The short framework name. 
        [Obsolete("This API does not support .NET 5 and higher target frameworks with platforms. Use IVsFrameworkParser2 instead.")]
        string GetShortFrameworkName(FrameworkName frameworkName);
    }

IVsFrameworkParser2 interface

    /// An interface to parse .NET Framework strings. See http://aka.ms/NuGet-IVsFrameworkParser.
    public interface IVsFrameworkParser2
    {
        /// 
        /// Parses a short framework name (e.g. "net45") or a full Target Framework Moniker
        /// (e.g. ".NETFramework,Version=v4.5") into a 
        /// instance.
        /// 
        /// The framework string
        /// The resulting . If the method returns false, this return NuGet's "Unsupported" framework details.
        /// A boolean to specify whether the input could be parsed into a valid  object.
        /// This API is not needed to get framework information about loaded projects, and should not be used to parse the project's TargetFramework property. See http://aka.ms/NuGet-IVsFrameworkParser.
/// This API is free-threaded.
bool TryParse(string input, out IVsNuGetFramework nuGetFramework); }

IVsPackageInstaller interface

    /// 
    /// Contains methods to install packages into a project within the current solution.
    /// 
    [ComImport]
    [Guid("4F3B122B-A53B-432C-8D85-0FAFB8BE4FF4")]
    public interface IVsPackageInstaller
    {
        /// 
        /// Installs a single package from the specified package source.
        /// 
        /// Can be called from a background thread, if the UI thread is not blocked waiting for this to finish.
        /// See https://github.com/nuget/home/issues/11476
        /// 
        /// The package source to install the package from. This value can be null
        /// to indicate that the user's configured sources should be used. Otherwise,
        /// this should be the source path as a string. If the user has credentials
        /// configured for a source, this value must exactly match the configured source
        /// value.
        /// 
        /// The target project for package installation.
        /// The package ID of the package to install.
        /// 
        /// The version of the package to install. null can be provided to
        /// install the latest version of the package.
        /// 
        /// 
        /// A boolean indicating whether or not to ignore the package's dependencies
        /// during installation.
        /// 
        [Obsolete("System.Version does not support SemVer pre-release versions. Use the overload with string version instead.")]
        void InstallPackage(string source, Project project, string packageId, Version version, bool ignoreDependencies);

        /// 
        /// Installs a single package from the specified package source.
        /// 
        /// Can be called from a background thread, if the UI thread is not blocked waiting for this to finish.
        /// See https://github.com/nuget/home/issues/11476
        /// 
        /// The package source to install the package from. This value can be null
        /// to indicate that the user's configured sources should be used. Otherwise,
        /// this should be the source path as a string. If the user has credentials
        /// configured for a source, this value must exactly match the configured source
        /// value.
        /// 
        /// The target project for package installation.
        /// The package ID of the package to install.
        /// 
        /// The version of the package to install. null can be provided to
        /// install the latest version of the package.
        /// 
        /// 
        /// A boolean indicating whether or not to ignore the package's dependencies
        /// during installation.
        /// 
        void InstallPackage(string source, Project project, string packageId, string version, bool ignoreDependencies);

        /// 
        /// Installs a single package from the specified package source.
        /// 
        /// The package repository to install the package from.
        /// The target project for package installation.
        /// The package id of the package to install.
        /// 
        /// The version of the package to install. null can be provided to
        /// install the latest version of the package.
        /// 
        /// 
        /// A boolean indicating whether or not to ignore the package's dependencies
        /// during installation.
        /// 
        /// 
        /// A boolean indicating if assembly references from the package should be
        /// skipped.
        /// 
        [Obsolete]
        void InstallPackage(IPackageRepository repository, Project project, string packageId, string version, bool ignoreDependencies, bool skipAssemblyReferences);

        /// 
        /// Installs one or more packages that exist on disk in a folder defined in the registry.
        /// 
        /// 
        /// The registry key name (under NuGet's repository key) that defines the folder on disk
        /// containing the packages.
        /// 
        /// 
        /// A boolean indicating whether the folder contains packages that are
        /// pre-unzipped.
        /// 
        /// 
        /// A boolean indicating whether the assembly references from the packages
        /// should be skipped.
        /// 
        /// The target project for package installation.
        /// 
        /// A dictionary of packages/versions to install where the key is the package id
        /// and the value is the version.
        /// 
        /// 
        /// If any version of the package is already installed, no action will be taken.
        /// 
        /// Dependencies are always ignored.
        /// 
        /// Can be called from a background thread, if the UI thread is not blocked waiting for this to finish.
        /// See https://github.com/nuget/home/issues/11476
        /// 
        void InstallPackagesFromRegistryRepository(string keyName, bool isPreUnzipped, bool skipAssemblyReferences, Project project, IDictionary packageVersions);

        /// 
        /// Installs one or more packages that exist on disk in a folder defined in the registry.
        /// 
        /// 
        /// The registry key name (under NuGet's repository key) that defines the folder on disk
        /// containing the packages.
        /// 
        /// 
        /// A boolean indicating whether the folder contains packages that are
        /// pre-unzipped.
        /// 
        /// 
        /// A boolean indicating whether the assembly references from the packages
        /// should be skipped.
        /// 
        /// A boolean indicating whether the package's dependencies should be ignored
        /// The target project for package installation.
        /// 
        /// A dictionary of packages/versions to install where the key is the package id
        /// and the value is the version.
        /// 
        /// 
        /// If any version of the package is already installed, no action will be taken.
        /// Can be called from a background thread, if the UI thread is not blocked waiting for this to finish.
        /// See https://github.com/nuget/home/issues/11476
        /// 
        void InstallPackagesFromRegistryRepository(string keyName, bool isPreUnzipped, bool skipAssemblyReferences, bool ignoreDependencies, Project project, IDictionary packageVersions);

        /// 
        /// Installs one or more packages that are embedded in a Visual Studio Extension Package.
        /// 
        /// The Id of the Visual Studio Extension Package.
        /// 
        /// A boolean indicating whether the folder contains packages that are
        /// pre-unzipped.
        /// 
        /// 
        /// A boolean indicating whether the assembly references from the packages
        /// should be skipped.
        /// 
        /// The target project for package installation
        /// 
        /// A dictionary of packages/versions to install where the key is the package id
        /// and the value is the version.
        /// 
        /// 
        /// If any version of the package is already installed, no action will be taken.
        /// 
        /// Dependencies are always ignored.
        /// 
        /// Can be called from a background thread, if the UI thread is not blocked waiting for this to finish.
        /// See https://github.com/nuget/home/issues/11476
        /// 
        void InstallPackagesFromVSExtensionRepository(string extensionId, bool isPreUnzipped, bool skipAssemblyReferences, Project project, IDictionary packageVersions);

        /// 
        /// Installs one or more packages that are embedded in a Visual Studio Extension Package.
        /// 
        /// The Id of the Visual Studio Extension Package.
        /// 
        /// A boolean indicating whether the folder contains packages that are
        /// pre-unzipped.
        /// 
        /// 
        /// A boolean indicating whether the assembly references from the packages
        /// should be skipped.
        /// 
        /// A boolean indicating whether the package's dependencies should be ignored
        /// The target project for package installation
        /// 
        /// A dictionary of packages/versions to install where the key is the package id
        /// and the value is the version.
        /// 
        /// 
        /// If any version of the package is already installed, no action will be taken.
        /// Can be called from a background thread, if the UI thread is not blocked waiting for this to finish.
        /// See https://github.com/nuget/home/issues/11476
        /// 
        void InstallPackagesFromVSExtensionRepository(string extensionId, bool isPreUnzipped, bool skipAssemblyReferences, bool ignoreDependencies, Project project, IDictionary packageVersions);
    }

IVsPackageinstaller2 interface


    /// 
    /// Contains method to install latest version of a single package into a project within the current solution.
    /// 
    public interface IVsPackageInstaller2 : IVsPackageInstaller
    {
        /// 
        /// Installs the latest version of a single package from the specified package source.
        /// 
        /// Can be called from a background thread, if the UI thread is not blocked waiting for this to finish.
        /// See https://github.com/nuget/home/issues/11476
        /// 
        /// The package source to install the package from. This value can be null
        /// to indicate that the user's configured sources should be used. Otherwise,
        /// this should be the source path as a string. If the user has credentials
        /// configured for a source, this value must exactly match the configured source
        /// value.
        /// 
        /// The target project for package installation.
        /// The package ID of the package to install.
        /// 
        /// Whether or not to consider prerelease versions when finding the latest version
        /// to install.
        /// 
        /// 
        /// A boolean indicating whether or not to ignore the package's dependencies
        /// during installation.
        /// 
        /// 
        /// Thrown when  is false and no stable version
        /// of the package exists.
        /// 
        void InstallLatestPackage(
            string source,
            Project project,
            string packageId,
            bool includePrerelease,
            bool ignoreDependencies);
    }

IVsPackageInstallerEvents interface

Note

These events are only raised for packages.config projects. To get updates for both packages.config and PackageReference use IVsNuGetProjectUpdateEvents instead.

    /// 
    /// Contains events which are raised when packages are installed or uninstalled from projects and the current
    /// solution.
    /// 
    public interface IVsPackageInstallerEvents
    {
        /// 
        /// Raised when a package is about to be installed into the current solution.
        /// 
        event VsPackageEventHandler PackageInstalling;

        /// 
        /// Raised after a package has been installed into the current solution.
        /// 
        event VsPackageEventHandler PackageInstalled;

        /// 
        /// Raised when a package is about to be uninstalled from the current solution.
        /// 
        event VsPackageEventHandler PackageUninstalling;

        /// 
        /// Raised after a package has been uninstalled from the current solution.
        /// 
        event VsPackageEventHandler PackageUninstalled;

        /// 
        /// Raised after a package has been installed into a project within the current solution.
        /// 
        event VsPackageEventHandler PackageReferenceAdded;

        /// 
        /// Raised after a package has been uninstalled from a project within the current solution.
        /// 
        event VsPackageEventHandler PackageReferenceRemoved;
    }

IVsPackageInstallerProjectEvents interface

Note

These events are only raised for packages.config projects. To get updates for both packages.config and PackageReference use IVsNuGetProjectUpdateEvents instead.

    /// 
    /// Contains batch events which are raised when packages are installed or uninstalled from projects with packages.config
    /// and the current solution.
    /// 
    public interface IVsPackageInstallerProjectEvents
    {
        /// 
        /// Raised before any IVsPackageInstallerEvents events are raised for a project.
        /// 
        event VsPackageProjectEventHandler BatchStart;

        /// 
        /// Raised after all IVsPackageInstallerEvents events are raised for a project.
        /// 
        event VsPackageProjectEventHandler BatchEnd;

    }

IVsPackageInstallerServices interface

    /// 
    /// Contains methods to query for installed packages within the current solution.
    /// 
    [Obsolete("Use INuGetProjectService in the NuGet.VisualStudio.Contracts package instead.")]
    public interface IVsPackageInstallerServices
    {
        /// 
        /// Get the list of NuGet packages installed in the current solution.
        /// 
        [Obsolete("This method can cause UI delays if called on the UI thread. Use INuGetProjectService.GetInstalledPackagesAsync in the NuGet.VisualStudio.Contracts package instead, and iterate all projects in the solution")]
        IEnumerable GetInstalledPackages();

        /// 
        /// Checks if a NuGet package with the specified Id is installed in the specified project.
        /// 
        /// The project to check for NuGet package.
        /// The id of the package to check.
        /// true if the package is install. false otherwise.
        /// A "project not nominated" exception will be thrown if the project system has not yet told NuGet about the project.
        /// You can use  or Microsoft.VisualStudio.OperationProgress to be notified when the project is ready.
        [Obsolete("This method can cause UI delays if called on the UI thread. Use INuGetProjectService.GetInstalledPackagesAsync in the NuGet.VisualStudio.Contracts package instead, and check the specific package you're interested in")]
        bool IsPackageInstalled(Project project, string id);

        /// 
        /// Checks if a NuGet package with the specified Id and version is installed in the specified project.
        /// 
        /// The project to check for NuGet package.
        /// The id of the package to check.
        /// The version of the package to check.
        /// true if the package is install. false otherwise.
        /// A "project not nominated" exception will be thrown if the project system has not yet told NuGet about the project.
        /// You can use  or Microsoft.VisualStudio.OperationProgress to be notified when the project is ready.
        [Obsolete("This method can cause UI delays if called on the UI thread. Use INuGetProjectService.GetInstalledPackagesAsync in the NuGet.VisualStudio.Contracts package instead, and check the specific package you're interested in")]
        bool IsPackageInstalled(Project project, string id, SemanticVersion version);

        /// 
        /// Checks if a NuGet package with the specified Id and version is installed in the specified project.
        /// 
        /// The project to check for NuGet package.
        /// The id of the package to check.
        /// The version of the package to check.
        /// true if the package is install. false otherwise.
        /// 
        /// The reason this method is named IsPackageInstalledEx, instead of IsPackageInstalled, is that
        /// when client project compiles against this assembly, the compiler would attempt to bind against
        /// the other overload which accepts SemanticVersion and would require client project to reference NuGet.Core.
        /// 
        /// A "project not nominated" exception will be thrown if the project system has not yet told NuGet about the project.
        /// You can use  or Microsoft.VisualStudio.OperationProgress to be notified when the project is ready.
        [Obsolete("This method can cause UI delays if called on the UI thread. Use INuGetProjectService.GetInstalledPackagesAsync in the NuGet.VisualStudio.Contracts package instead, and check the specific package you're interested in")]
        bool IsPackageInstalledEx(Project project, string id, string versionString);

        /// 
        /// Get the list of NuGet packages installed in the specified project.
        /// 
        /// The project to get NuGet packages from.
        /// A "project not nominated" exception will be thrown if the project system has not yet told NuGet about the project.
        /// You can use  or Microsoft.VisualStudio.OperationProgress to be notified when the project is ready.
        [Obsolete("This method can cause UI delays if called on the UI thread. Use INuGetProjectService.GetInstalledPackagesAsync in the NuGet.VisualStudio.Contracts package instead")]
        IEnumerable GetInstalledPackages(Project project);
    }

IVsPackageRestorer interface


    /// 
    /// Contains methods to restore packages installed in a project within the current solution.
    /// 
    public interface IVsPackageRestorer
    {
        /// 
        /// Returns a value indicating whether the user consent to download NuGet packages
        /// has been granted.
        /// 
        /// Can be called from a background thread.
        /// true if the user consent has been granted; otherwise, false.
        bool IsUserConsentGranted();

        /// 
        /// Restores NuGet packages installed in the given project within the current solution.
        /// 
        /// Can be called from a background thread.
        /// The project whose NuGet packages to restore.
        void RestorePackages(Project project);
    }

IVsPackageSourceProvider interface

    /// 
    /// A public API for retrieving the list of NuGet package sources.
    /// 
    public interface IVsPackageSourceProvider
    {
        /// 
        /// Provides the list of package sources.
        /// 
        /// Can be called from a background thread.
        /// Unofficial sources will be included in the results
        /// Disabled sources will be included in the results
        /// Does not require the UI thread.
        /// Thrown if a NuGet configuration file is invalid.
        /// Thrown if a NuGet configuration file is invalid.
        /// Thrown if a NuGet configuration file is invalid.
        /// Thrown if a NuGet configuration file is invalid.
        /// Key: source name Value: source URI
        IEnumerable> GetSources(bool includeUnOfficial, bool includeDisabled);

        /// 
        /// Raised when sources are added, removed, disabled, or modified.
        /// 
        event EventHandler SourcesChanged;
    }

IVsPackageUninstaller interface

    /// 
    /// Contains methods to uninstall packages from a project within the current solution.
    /// 
    public interface IVsPackageUninstaller
    {
        /// 
        /// Uninstall the specified package from a project and specify whether to uninstall its dependency packages
        /// too.
        /// 
        /// Can be called from a background thread, if the UI thread is not blocked waiting for this to finish.
        /// See https://github.com/nuget/home/issues/11476
        /// The project from which the package is uninstalled.
        /// The package to be uninstalled
        /// 
        /// A boolean to indicate whether the dependency packages should be
        /// uninstalled too.
        /// 
        void UninstallPackage(Project project, string packageId, bool removeDependencies);
    }

IVsPathContext interface

    /// 
    /// NuGet path information specific to the current context (e.g. project context).
    /// Represents captured snapshot associated with current project/solution settings.
    /// Should be discarded immediately after all queries are done.
    /// 
    public interface IVsPathContext
    {
        /// 
        /// User package folder directory. The path returned is an absolute path.
        /// 
        string UserPackageFolder { get; }

        /// 
        /// Fallback package folder locations. The paths (if any) in the returned list are absolute paths. If no
        /// fallback package folders are configured, an empty list is returned. The item type of this sequence is
        /// .
        /// 
        /// Can be called from a background thread.
        IEnumerable FallbackPackageFolders { get; }

        /// 
        /// Fetch a package directory containing the provided asset path.
        /// 
        /// Absolute path to package asset file.
        /// Full path to a package directory. 
        /// null if returned falue is false.
        /// 
        /// true when a package containing the given file was found, false - otherwise.
        /// 
        /// 
        /// Suppose the project is a packages.config project and the following asset paths are provided:
        /// 
        /// - C:\src\MyProject\packages\NuGet.Versioning.3.5.0-rc1-final\lib\net45\NuGet.Versioning.dll
        /// - C:\path\to\non\package\assembly\Newtonsoft.Json.dll
        /// - C:\src\MyOtherProject\packages\NuGet.Core.2.12.0\lib\net40\NuGet.Core.dll
        /// - C:\src\MyProject\packages\Autofac.3.5.2\lib\net40\Autofac.dll
        /// - C:\src\MyProject\packages\Autofac.3.5.2\lib\net40\Autofac.Fake.dll
        /// 
        /// The result will be:
        /// 
        /// - C:\src\MyProject\packages\NuGet.Versioning.3.5.0-rc1-final
        /// - null
        /// - null
        /// - C:\src\MyProject\packages\Autofac.3.5.2
        /// - C:\src\MyProject\packages\Autofac.3.5.2
        /// 
        bool TryResolvePackageAsset(string packageAssetPath, out string packageDirectoryPath);
    }

IVsPathContext2 interface

    /// 
    /// NuGet path information specific to the current context (e.g. project context) or solution context
    /// Represents captured snapshot associated with current project/solution settings.
    /// Should be discarded immediately after all queries are done.
    /// 
    public interface IVsPathContext2 : IVsPathContext
    {
        /// 
        /// Solution packages folder directory. This will always be set irrespective if folder actually exists or not.
        /// The path returned is an absolute path.
        /// 
        string SolutionPackageFolder { get; }
    }

IVsPathContextProvider interface

    /// 
    /// A factory to initialize  instances.
    /// 
    public interface IVsPathContextProvider
    {
        /// 
        /// Attempts to create an instance of .
        /// 
        /// Can be called from a background thread.
        /// 
        /// Unique identificator of the project. Should be a full path to project file.
        /// 
        /// The path context associated with given project.
        /// 
        /// True if operation has succeeded and context was created.
        /// False, otherwise, e.g. when provided project is not managed by NuGet.
        /// 
        /// 
        /// ArgumentNullException if projectUniqueName is passed as null.
        /// InvalidOperationException when it fails to create a context and return appropriate error message.
        /// 
        bool TryCreateContext(string projectUniqueName, out IVsPathContext context);
    }

IVsPathContextProvider2 interface

    /// 
    /// A factory to initialize  instances.
    /// 
    public interface IVsPathContextProvider2 : IVsPathContextProvider
    {
        /// 
        /// Attempts to create an instance of  for the solution.
        /// 
        /// This API is free-threaded, but APIs on the returned IVsPathContext2 may not be.
        /// The path context associated with this solution.
        /// 
        /// True if operation has succeeded and context was created.
        /// False otherwise.
        /// 
        /// 
        /// InvalidOperationException when it fails to create a context and return appropriate error message.
        /// 
        bool TryCreateSolutionContext(out IVsPathContext2 context);

        /// 
        /// Attempts to create an instance of  for the solution.
        /// 
        /// This API is free-threaded, but APIs on the returned IVsPathContext2 may not be.
        /// 
        /// path to the solution directory. Must be an absolute path.
        /// It will be performant to pass the solution directory if it's available.
        /// 
        /// The path context associated with this solution.
        /// 
        /// True if operation has succeeded and context was created.
        /// False otherwise.
        /// 
        /// 
        /// ArgumentNullException if solutionDirectory is passed as null.
        /// InvalidOperationException when it fails to create a context and return appropriate error message.
        /// 
        bool TryCreateSolutionContext(string solutionDirectory, out IVsPathContext2 context);

        /// 
        /// Attempts to create an instance of  containing only the user wide and machine wide configurations.
        /// If a solution is loaded, note that the values in the path context might not be the actual effective values for the solution.
        /// If a customer has overriden the `globalPackagesFolder` key or cleared the `fallbackPackageFolders`, these values will be incorrect.
        /// It is important to keep this scenario in mind when working with this path. To predict differences you can call this in combination with .
        /// 
        /// 
        /// True if operation has succeeded and context was created.
        /// False otherwise.
        /// 
        /// 
        /// This method can be safely invoked from a background thread. Do note that this method might switch to the UI thread internally, so be mindful of blocking the UI thread on this.
        /// 
        bool TryCreateNoSolutionContext(out IVsPathContext vsPathContext);
    }

IVsProjectJsonToPackageReferenceMigrator interface

    /// 
    /// Contains methods to migrate a project.json based legacy project to PackageReference based project.
    /// 
    public interface IVsProjectJsonToPackageReferenceMigrator
    {
        /// 
        /// Migrates a legacy Project.json based project to Package Reference based project. The result 
        /// should be casted to type 
        /// The backup of the original project file and project.json file is created in the Backup folder
        /// in the root of the project directory.
        /// 
        /// The full path to the project that needs to be migrated
        Task MigrateProjectJsonToPackageReferenceAsync(string projectUniqueName);

    }

IVsSemanticVersionComparer interface

    /// 
    /// An interface for comparing two opaque version strings by treating them as NuGet semantic
    /// versions.
    /// 
    public interface IVsSemanticVersionComparer
    {
        /// 
        /// Compares two version strings as if they were NuGet semantic version
        /// strings. Returns a number less than zero if 
        /// is less than . Returns zero if the two versions 
        /// are equivalent. Returns a number greater than zero if 
        /// is greater than .
        /// 
        /// This API is free-threaded.
        /// The first version string.
        /// The second version string.
        /// If either version string is null.
        /// If either string cannot be parsed.
        /// 
        /// A standard comparison integer based on the relationship between the
        /// two provided versions.
        /// 
        int Compare(string versionA, string versionB);
    }

IVsNuGetProjectUpdateEvents interface

    /// 
    /// NuGet project update events.
    /// This API provides means of tracking project updates by NuGet.
    /// In particular, for PackageReference projects, updates to the assets file and nuget generated props/targets.
    /// For packages.config projects, package installations will be tracked.
    /// All events are fired from a threadpool thread.
    /// 
    public interface IVsNuGetProjectUpdateEvents
    {
        /// 
        /// Raised when solution restore starts with the list of projects that will be restored.
        /// The list will not include all projects. Some projects may have been skipped in earlier up to date check, and other projects may no-op.
        /// 
        /// 
        /// Just because a project is being restored that doesn't necessarily mean any actual updates will happen.
        /// No heavy computation should happen in any of these methods as it'll block the NuGet progress.
        /// 
        event SolutionRestoreEventHandler SolutionRestoreStarted;

        /// 
        /// Raised when solution restore finishes with the list of projects that were restored.
        /// The list will not include all projects. Some projects may have been skipped in earlier up to date check, and other projects may no-op.
        /// 
        /// 
        /// Just because a project is being restored that doesn't necessarily mean any actual updates will happen.
        /// No heavy computation should happen in any of these methods as it'll block the NuGet progress.
        /// 
        event SolutionRestoreEventHandler SolutionRestoreFinished;

        /// 
        /// Raised when particular project is about to be updated.
        /// For PackageReference projects, this means an assets file or a nuget temp msbuild file write (nuget.g.props or nuget.g.targets). The list of updated files will include the aforementioned.
        /// If a project was restored, but no file updates happen, this event will not be fired.
        /// For packages.config projects, this means that the project file was changed.
        /// 
        /// 
        /// No heavy computation should happen in any of these methods as it'll block the NuGet progress.
        /// 
        event ProjectUpdateEventHandler ProjectUpdateStarted;

        /// 
        /// Raised when particular project update has been completed.
        /// For PackageReference projects, this means an assets file or a nuget temp msbuild file write (nuget.g.props or nuget.g.targets). The list of updated files will include the aforementioned.
        /// If a project was restored, but no file updates happen, this event will not be fired.
        /// For packages.config projects, this means that the project file was changed.
        /// 
        /// 
        /// No heavy computation should happen in any of these methods as it'll block the NuGet progress.
        /// 
        event ProjectUpdateEventHandler ProjectUpdateFinished;
    }

    /// 
    /// Defines an event handler delegate for solution restore start and end.
    /// 
    /// List of projects that will run restore. Never .
    public delegate void SolutionRestoreEventHandler(IReadOnlyList projects);

    /// 
    /// Defines an event handler delegate for project updates.
    /// 
    /// Project full path. Never . 
    /// NuGet output files that may be updated. Never .
    public delegate void ProjectUpdateEventHandler(string projectUniqueName, IReadOnlyList updatedFiles);
}

IVsSolutionRestoreService interface

    /// 
    /// Represents a package restore service API for integration with a project system.
    /// 
    public interface IVsSolutionRestoreService
    {
        /// 
        /// A task providing last/current restore operation status.
        /// Could be null if restore has not started yet.
        /// 
        /// 
        /// This task is a reflection of the current state of the current-restore-operation or
        /// recently-completed-restore. The usage of this property will be to continue,
        /// e.g. to build solution or something) on completion of this task.
        /// Also, on completion, if the task returns false then it means the restore failed and
        /// the build task will be terminated.
        /// 
        Task CurrentRestoreOperation { get; }

        /// 
        /// An entry point used by CPS to indicate given project needs to be restored.
        /// 
        /// 
        /// Unique identifier of the project. Should be a full path to project file.
        /// 
        /// Metadata  needed for restoring the project.
        /// Cancellation token.
        /// 
        /// Returns a restore task corresponding to the nominated project request.
        /// NuGet will batch restore requests so it's possible the same restore task will be returned for multiple projects.
        /// When the requested restore operation for the given project completes the task will indicate operation success or failure.
        /// 
        /// Thrown if  is not the path of a project file.
        /// Thrown if  is null.
        /// Thrown if  is cancelled.
        [Obsolete("Use IVsSolutionRestoreService5 instead")]
        Task NominateProjectAsync(string projectUniqueName, IVsProjectRestoreInfo projectRestoreInfo, CancellationToken token);
    }

IVsSolutionRestoreService2 interface

    /// 
    /// Represents a package restore service API for integration with a project system.
    /// 
    public interface IVsSolutionRestoreService2
    {
        /// 
        /// An entry point which allows non-NETCore SDK based projects to indicate given project needs to be restored.
        /// 
        /// 
        /// Unique identificator of the project. Should be a full path to project file.
        /// 
        /// Cancellation token.
        /// 
        /// Returns a restore task corresponding to the nominated project request.
        /// NuGet will batch restore requests so it's possible the same restore task will be returned for multiple projects.
        /// When the requested restore operation for the given project completes the task will indicate operation success or failure.
        /// 
        Task NominateProjectAsync(string projectUniqueName, CancellationToken token);
    }

IVsSolutionRestoreService3 interface

    /// 
    /// Represents a package restore service API for integration with a project system.
    /// 
    public interface IVsSolutionRestoreService3
    {
        /// 
        /// A task providing last/current restore operation status.
        /// Could be null if restore has not started yet.
        /// 
        /// 
        /// This task is a reflection of the current state of the current-restore-operation or
        /// recently-completed-restore. The usage of this property will be to continue,
        /// e.g. to build solution or something) on completion of this task.
        /// Also, on completion, if the task returns false then it means the restore failed and
        /// the build task will be terminated.
        /// 
        Task CurrentRestoreOperation { get; }

        /// 
        /// An entry point used by CPS to indicate given project needs to be restored.
        /// This entry point also handles PackageDownload items
        /// 
        /// 
        /// Unique identifier of the project. Should be a full path to project file.
        /// 
        /// Metadata  needed for restoring the project.
        /// Cancellation token.
        /// 
        /// Returns a restore task corresponding to the nominated project request.
        /// NuGet will batch restore requests so it's possible the same restore task will be returned for multiple projects.
        /// When the requested restore operation for the given project completes the task will indicate operation success or failure.
        /// 
        /// Thrown if  is not the path of a project file.
        /// Thrown if  is null.
        /// Thrown if  is cancelled.
        [Obsolete("Use IVsSolutionRestoreService5 instead")]
        Task NominateProjectAsync(string projectUniqueName, IVsProjectRestoreInfo2 projectRestoreInfo, CancellationToken token);
    }

IVsSolutionRestoreService4 interface

    /// 
    /// Represents a package restore service API for integration with a project system.
    /// Implemented by NuGet.
    /// 
    public interface IVsSolutionRestoreService4 : IVsSolutionRestoreService3
    {
        /// 
        /// A project system can call this service (optionally) to register itself to coordinate restore. 
/// Each project can only register once. NuGet will call into the source to wait for nominations for restore.
/// NuGet will remove the registered object when a project is unloaded. ///
/// Represents a project specific info source /// Cancellation token. /// If the project has already been registered. /// If is null. /// If 's is . Task RegisterRestoreInfoSourceAsync(IVsProjectRestoreInfoSource restoreInfoSource, CancellationToken cancellationToken); }

IVsSolutionRestoreService5 interface

    /// 
    /// Represents a package restore service API for integration with a project system.
    /// Implemented by NuGet.
    /// 
    public interface IVsSolutionRestoreService5 : IVsSolutionRestoreService4
    {
        /// 
        /// An entry point used by CPS to indicate given project needs to be restored.
        /// 
        /// 
        /// The full path to the project file. In the VS SDK's IVsSolution, this is also known as the unique name.
        /// 
        /// Metadata  needed for restoring the project.
        /// Cancellation token.
        /// 
        /// Returns a restore task corresponding to the nominated project request.
        /// NuGet will batch restore requests so it's possible the same restore task will be returned for multiple projects.
        /// When the requested restore operation for the given project completes the task will indicate operation success or failure.
        /// 
        /// Thrown if  is not the path of a project file,
        /// or if  has some basic validation errors.
        /// Thrown if  is .
        /// Thrown if  is cancelled.
        Task NominateProjectAsync(string projectUniqueName, IVsProjectRestoreInfo3 projectRestoreInfo, CancellationToken token);
    }

IVsProjectRestoreInfoSource interface

    /// 
    /// Represents a package restore service API for integration with a project system.
    /// Implemented by the project-system.
    /// 
    public interface IVsProjectRestoreInfoSource
    {
        /// 
        /// Project Unique Name.
        /// Must be equivalent to the name provided in the  or equivalent.
        /// 
        /// Never .
        string Name { get; }

        /// 
        /// Whether the source needs to do some work that could lead to a nomination. 
/// Called frequently, so it should be very efficient. ///
bool HasPendingNomination { get; } /// /// NuGet calls this method to wait on a potential nomination.
/// If the project has no pending restore data, it will return a completed task.
/// Otherwise, the task will be completed once the project nominates.
/// The task will be cancelled, if the source decide it no longer needs to nominate (for example: the restore state has no change)
/// The task will be failed, if the source runs into a problem, and it cannot get the correct data to nominate (for example: DT build failed)
///
/// Cancellation token. Task WhenNominated(CancellationToken cancellationToken); }

IVsSolutionRestoreStatusProvider interface

    /// 
    /// Provides the status of IVsSolutionRestore.
    /// 
    public interface IVsSolutionRestoreStatusProvider
    {
        /// 
        /// IsRestoreCompleteAsync indicates whether or not automatic package restore has pending work.
        /// Automatic package restore applies for both packages.config and PackageReference projects.
        ///
        /// Returns true if all projects in the solution that require nomination have been nominated for restore and all pending restores have completed.
        /// The result does not indicate that restore completed successfully, a failed restore will still return true.
        /// 
        /// 
        /// Special cases:
        /// * An empty solution will return true.
        /// * If no solution is open this will true.
        /// * An invalid project that does not provide restore details will cause this to return false since restore will not run for that project.
        ///
        /// Restores running due to Install/Update/Uninstall operations are NOT included in this status. Status here is limited to IVsSolutionRestoreService.
        /// 
        Task IsRestoreCompleteAsync(CancellationToken token);
    }