当前位置: 首页>>代码示例>>C#>>正文


C# IPackageManager.UninstallPackage方法代码示例

本文整理汇总了C#中IPackageManager.UninstallPackage方法的典型用法代码示例。如果您正苦于以下问题:C# IPackageManager.UninstallPackage方法的具体用法?C# IPackageManager.UninstallPackage怎么用?C# IPackageManager.UninstallPackage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IPackageManager的用法示例。


在下文中一共展示了IPackageManager.UninstallPackage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PackageInstallNeeded

        /// <summary>
        /// Returns true if package install is needed.
        /// Package install is not needed if 
        /// - AllowMultipleVersions is false;
        /// - there is an existing package, and its version is newer than or equal to the 
        /// package to be installed.
        /// </summary>
        /// <param name="packageManager">The pacakge manager.</param>
        /// <param name="packageId">The id of the package to install.</param>
        /// <param name="version">The version of the package to install.</param>
        /// <returns>True if package install is neede; otherwise, false.</returns>
        private bool PackageInstallNeeded(
            IPackageManager packageManager,
            string packageId,
            SemanticVersion version)
        {
            if (AllowMultipleVersions)
            {
                return true;
            }

            var installedPackage = packageManager.LocalRepository.FindPackage(packageId);
            if (installedPackage == null)
            {
                return true;
            }

            if (version == null)
            {
                // need to query the source repository to get the version to be installed.
                IPackage package = packageManager.SourceRepository.FindPackage(
                    packageId, 
                    version,
                    NullConstraintProvider.Instance,
                    allowPrereleaseVersions: Prerelease, 
                    allowUnlisted: false);
                if (package == null)
                {
                    return false;
                }

                version = package.Version;
            }

            if (installedPackage.Version >= version)
            {
                // If the installed pacakge has newer version, no install is needed.
                return false;
            }

            // install is needed. In this case, uninstall the existing pacakge.
            packageManager.UninstallPackage(installedPackage, forceRemove: false, removeDependencies: true);
            return true;
        }
开发者ID:riteshparekh,项目名称:NuGet,代码行数:54,代码来源:InstallCommand.cs

示例2: InstallPackage

 internal bool InstallPackage(IPackageManager packageManager, IFileSystem fileSystem, string packageId, SemanticVersion version, bool ignoreDependencies)
 {
     if (AllowMultipleVersions && IsPackageInstalled(packageId, version, packageManager, fileSystem))
     {
         // Use a fast check to verify if the package is already installed. We'll do this by checking if the package directory exists on disk.
         return false;
     }
     else if (!AllowMultipleVersions)
     {
         var installedPackage = packageManager.LocalRepository.FindPackage(packageId);
         if (installedPackage != null)
         {
             if (version != null && installedPackage.Version >= version)
             {
                 // If the package is already installed (or the version being installed is lower), then we do not need to do anything. 
                 return false;
             }
             else if (packageManager.SourceRepository.Exists(packageId, version))
             {
                 // If the package is already installed, but
                 // (a) the version we require is different from the one that is installed, 
                 // (b) side-by-side is disabled
                 // we need to uninstall it.
                 // However, before uninstalling, make sure the package exists in the source repository. 
                 packageManager.UninstallPackage(installedPackage, forceRemove: false, removeDependencies: true);
             }
         }
     }
     packageManager.InstallPackage(packageId, version, ignoreDependencies: ignoreDependencies, allowPrereleaseVersions: Prerelease);
     return true;
 }
开发者ID:monoman,项目名称:NugetCracker,代码行数:31,代码来源:InstallCommand.cs


注:本文中的IPackageManager.UninstallPackage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。