本文整理汇总了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;
}
示例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;
}