本文整理汇总了C#中PackageManager.IsPackageInstalled方法的典型用法代码示例。如果您正苦于以下问题:C# PackageManager.IsPackageInstalled方法的具体用法?C# PackageManager.IsPackageInstalled怎么用?C# PackageManager.IsPackageInstalled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PackageManager
的用法示例。
在下文中一共展示了PackageManager.IsPackageInstalled方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanDetermineVersionlessPackageIsInstalled
public bool CanDetermineVersionlessPackageIsInstalled(string id, string onDiskVersion, string packageVersion, bool installedUsingMultipleVersion, bool currentlyAllowMultipleVersions, bool exhaustive)
{
var mfs = new Mock<MockFileSystem>() { CallBase = true };
mfs.Setup(m => m.Root).Returns(@"c:\packages");
var installPathResolver = new DefaultPackagePathResolver(mfs.Object, installedUsingMultipleVersion);
var currentPathResolver = new DefaultPackagePathResolver(mfs.Object, currentlyAllowMultipleVersions);
var testPackage = new DataServicePackage()
{
Version = packageVersion,
Id = id
};
var filePackage = new DataServicePackage()
{
Version = onDiskVersion,
Id = id
};
IPackage zipPackage = null;
if (!string.IsNullOrEmpty(onDiskVersion))
{
string baseLocation = installPathResolver.GetInstallPath(filePackage);
string fileName = installPathResolver.GetPackageFileName(filePackage.Id, SemanticVersion.Parse(filePackage.Version));
string filePath = Path.Combine(baseLocation, fileName);
zipPackage = PackageUtility.GetZipPackage(filePackage.Id, filePackage.Version);
mfs.Setup(m => m.FileExists(filePath)).Returns(true);
mfs.Setup(m => m.OpenFile(filePath)).Returns(zipPackage.GetStream());
mfs.Object.AddFile(filePath, zipPackage.GetStream());
}
var pm = new PackageManager(new MockPackageRepository(), currentPathResolver, mfs.Object);
var exists = pm.IsPackageInstalled(testPackage,exhaustive: exhaustive);
//var test = testPackage.IsPackageInstalled(allowMultipleVersions, pm, mfs.Object);
return exists;
}
示例2: InstallPackage
/// <summary>
/// Installs the package.
/// </summary>
/// <param name="packageManager">The package manager.</param>
/// <param name="fileSystem">The file system.</param>
/// <param name="packageId">The package id.</param>
/// <param name="version">The version.</param>
/// <param name="allowPreReleaseVersion"> </param>
/// <returns></returns>
internal bool InstallPackage(PackageManager packageManager, IFileSystem fileSystem, string packageId, SemanticVersion version, Boolean allowPreReleaseVersion = true)
{
if (packageManager.IsPackageInstalled(packageId, version))
{
return false;
}
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: true, removeDependencies: false);
}
}
}
//TODO Will need to expose the last boolean here......
var package = _packageResolutionManager.ResolvePackage(packageManager.LocalRepository, _repository, packageId, version, allowPreReleaseVersion);
packageManager.InstallPackage(package, ignoreDependencies: !IncludeDependencies, allowPrereleaseVersions: allowPreReleaseVersion);
//packageManager.InstallPackage(packageId, version, !IncludeDependencies, allowPreReleaseVersion);
return true;
}