本文整理汇总了C#中PackageManager.InstallPackage方法的典型用法代码示例。如果您正苦于以下问题:C# PackageManager.InstallPackage方法的具体用法?C# PackageManager.InstallPackage怎么用?C# PackageManager.InstallPackage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PackageManager
的用法示例。
在下文中一共展示了PackageManager.InstallPackage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InstallPackage
/// <summary>
/// Install package
/// </summary>
/// <param name="pkgId"></param>
public static bool InstallPackage(string pkgId)
{
try
{
// if package already installed - uninstall it
if (BlogService.InstalledFromGalleryPackages() != null)
{
if(BlogService.InstalledFromGalleryPackages().Find(p => p.PackageId == pkgId) != null)
{
UninstallPackage(pkgId);
}
}
var packageManager = new PackageManager( _repository,
new DefaultPackagePathResolver(BlogConfig.GalleryFeedUrl),
new PhysicalFileSystem(HttpContext.Current.Server.MapPath(Utils.ApplicationRelativeWebRoot + "App_Data/packages"))
);
var package = _repository.FindPackage(pkgId);
packageManager.InstallPackage(package, false, true);
var iPkg = new InstalledPackage { PackageId = package.Id, Version = package.Version.ToString() };
BlogService.InsertPackage(iPkg);
var packageFiles = FileSystem.InstallPackage(package);
BlogService.InsertPackageFiles(packageFiles);
Blog.CurrentInstance.Cache.Remove(Constants.CacheKey);
CustomFieldsParser.ClearCache();
Utils.Log(string.Format("Installed package {0} by {1}", pkgId, Security.CurrentUser.Identity.Name));
}
catch (Exception ex)
{
Utils.Log("BlogEngine.Core.Packaging.Installer.InstallPackage(" + pkgId + ")", ex);
UninstallPackage(pkgId);
throw;
}
return true;
}
示例2: InstallPackage
/// <summary>
/// Install package
/// </summary>
/// <param name="pkgId"></param>
public static JsonResponse InstallPackage(string pkgId)
{
try
{
if(BlogService.InstalledFromGalleryPackages() != null &&
BlogService.InstalledFromGalleryPackages().Find(p => p.PackageId == pkgId) != null)
UninstallPackage(pkgId);
var packageManager = new PackageManager(
_repository,
new DefaultPackagePathResolver(BlogSettings.Instance.GalleryFeedUrl),
new PhysicalFileSystem(HttpContext.Current.Server.MapPath(Utils.ApplicationRelativeWebRoot + "App_Data/packages"))
);
var package = _repository.FindPackage(pkgId);
packageManager.InstallPackage(package, false, true);
var iPkg = new InstalledPackage { PackageId = package.Id, Version = package.Version.ToString() };
BlogService.InsertPackage(iPkg);
var packageFiles = FileSystem.InstallPackage(package.Id, package.Version.ToString());
BlogService.InsertPackageFiles(packageFiles);
Blog.CurrentInstance.Cache.Remove(Constants.CacheKey);
Utils.Log(string.Format("Installed package {0} by {1}", pkgId, Security.CurrentUser.Identity.Name));
}
catch (Exception ex)
{
Utils.Log("BlogEngine.Core.Packaging.Installer.InstallPackage(" + pkgId + ")", ex);
try
{
UninstallPackage(pkgId);
}
catch (Exception)
{
// just trying to clean up if package did not installed properly
}
return new JsonResponse { Success = false, Message = "Error installing package, see logs for details" };
}
return new JsonResponse { Success = true, Message = "Package successfully installed" };
}
示例3: InstallingPackageWithUnknownDependencyAndIgnoreDepencenciesInstallsPackageWithoutDependencies
public void InstallingPackageWithUnknownDependencyAndIgnoreDepencenciesInstallsPackageWithoutDependencies()
{
// Arrange
var localRepository = new MockPackageRepository();
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var packageManager = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
IPackage packageA = PackageUtility.CreatePackage("A", "1.0",
dependencies: new List<PackageDependency> {
new PackageDependency("C")
});
IPackage packageC = PackageUtility.CreatePackage("C", "1.0");
sourceRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageC);
// Act
packageManager.InstallPackage("A", version: null, ignoreDependencies: true, allowPrereleaseVersions: true);
// Assert
Assert.True(localRepository.Exists(packageA));
Assert.False(localRepository.Exists(packageC));
}
示例4: InstallPackageThrowsIfDependencyIsPrereleaseAndFlagIsNotSet
public void InstallPackageThrowsIfDependencyIsPrereleaseAndFlagIsNotSet()
{
// Arrange
var localRepository = new MockPackageRepository();
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var packageManager = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
IPackage packageA = PackageUtility.CreatePackage("A", "1.0.0",
dependencies: new[] {
new PackageDependency("C")
});
IPackage packageC = PackageUtility.CreatePackage("C", "1.0.0-RC-1");
sourceRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageC);
// Act and Assert
ExceptionAssert.Throws<InvalidOperationException>(
() => packageManager.InstallPackage("A", version: null, ignoreDependencies: false, allowPrereleaseVersions: false),
"Unable to resolve dependency 'C'.");
}
示例5: InstallPackageDisregardTargetFrameworkOfDependencies
public void InstallPackageDisregardTargetFrameworkOfDependencies()
{
// Arrange
var localRepository = new MockPackageRepository();
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var packageManager = new PackageManager(
sourceRepository,
new DefaultPackagePathResolver(projectSystem),
projectSystem,
localRepository);
IPackage packageA = PackageUtility.CreatePackage("A", "1.0.0",
dependencies: new[] {
new PackageDependency("C", null)
});
IPackage packageC = PackageUtility.CreatePackage("C", "1.0.0");
sourceRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageC);
// Act
packageManager.InstallPackage("A", version: null, ignoreDependencies: false, allowPrereleaseVersions: true);
// Assert
Assert.True(localRepository.Exists(packageA));
Assert.True(localRepository.Exists(packageC));
}
示例6: InstallPackageThrowsExceptionPackageIsNotInstalled
public void InstallPackageThrowsExceptionPackageIsNotInstalled()
{
// Arrange
var localRepository = new MockPackageRepository();
var sourceRepository = new MockPackageRepository();
var projectSystem = new Mock<IProjectSystem>();
projectSystem.Setup(m => m.AddFile(@"A.1.0\content\file", It.IsAny<Stream>())).Throws<UnauthorizedAccessException>();
projectSystem.Setup(m => m.Root).Returns("FakeRoot");
PackageManager packageManager = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem.Object), projectSystem.Object, localRepository);
IPackage packageA = PackageUtility.CreatePackage("A", "1.0", new[] { "file" });
sourceRepository.AddPackage(packageA);
// Act
ExceptionAssert.Throws<UnauthorizedAccessException>(() => packageManager.InstallPackage("A"));
// Assert
Assert.False(packageManager.LocalRepository.Exists(packageA));
}
示例7: ReInstallingPackageAfterUninstallingDependencyShouldReinstallAllDependencies
public void ReInstallingPackageAfterUninstallingDependencyShouldReinstallAllDependencies()
{
// Arrange
var localRepository = new MockPackageRepository();
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
PackageManager packageManager = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
IPackage packageA = PackageUtility.CreatePackage("A", "1.0",
dependencies: new List<PackageDependency> {
new PackageDependency("B")
});
IPackage packageB = PackageUtility.CreatePackage("B", "1.0",
dependencies: new List<PackageDependency> {
new PackageDependency("C")
});
var packageC = PackageUtility.CreatePackage("C", "1.0");
localRepository.AddPackage(packageA);
localRepository.AddPackage(packageB);
sourceRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageB);
sourceRepository.AddPackage(packageC);
// Act
packageManager.InstallPackage("A");
// Assert
Assert.True(localRepository.Exists(packageA));
Assert.True(localRepository.Exists(packageB));
Assert.True(localRepository.Exists(packageC));
}
示例8: UninstallingSatellitePackageRemovesCollidingRuntimeFiles
public void UninstallingSatellitePackageRemovesCollidingRuntimeFiles()
{
// Arrange
// Create a runtime package and a satellite package that has a dependency on the runtime package, and uses the
// local suffix convention.
var runtimePackage = PackageUtility.CreatePackage("foo", "1.0.0",
assemblyReferences: new[] { @"lib\ja-jp\collision.txt" });
var satellitePackage = PackageUtility.CreatePackage("foo.ja-jp", "1.0.0", language: "ja-jp",
satelliteAssemblies: new[] { @"lib\ja-jp\collision.txt" },
dependencies: new[] { new PackageDependency("foo", VersionUtility.ParseVersionSpec("[1.0.0]")) });
var projectSystem = new MockProjectSystem();
var localRepository = new MockPackageRepository();
var sourceRepository = new MockPackageRepository();
var packageManager = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
sourceRepository.AddPackage(runtimePackage);
sourceRepository.AddPackage(satellitePackage);
// Act
packageManager.InstallPackage("foo");
packageManager.InstallPackage("foo.ja-jp");
packageManager.UninstallPackage("foo.ja-jp");
// Assert
Assert.Equal(0, projectSystem.Paths.Count);
Assert.False(projectSystem.FileExists(@"foo.1.0.0\lib\ja-jp\collision.txt"));
}
示例9: ExecuteCommand
public override void ExecuteCommand()
{
var feedUrl = DefaultFeedUrl;
if (!String.IsNullOrEmpty(Source)) {
feedUrl = Source;
}
IPackageRepository packageRepository = RepositoryFactory.CreateRepository(new PackageSource(feedUrl));
// Use the passed in install path if any, and default to the current dir
string installPath = OutputDirectory ?? Directory.GetCurrentDirectory();
var packageManager = new PackageManager(packageRepository,
new DefaultPackagePathResolver(installPath, useSideBySidePaths: !ExcludeVersion),
new PhysicalFileSystem(installPath));
packageManager.Logger = Console;
// If the first argument is a packages.config file, install everything it lists
// Otherwise, treat the first argument as a package Id
if (Path.GetFileName(Arguments[0]).Equals(PackageReferenceRepository.PackageReferenceFile, StringComparison.OrdinalIgnoreCase)) {
InstallPackagesFromConfigFile(packageManager, installPath);
}
else {
string packageId = Arguments[0];
Version version = Version != null ? new Version(Version) : null;
packageManager.InstallPackage(packageId, version);
}
}
示例10: InstallPackageNotifiesBatchProcessorWhenExpandingPackageFiles
public void InstallPackageNotifiesBatchProcessorWhenExpandingPackageFiles()
{
// Arrange
var package = PackageUtility.CreatePackage("B", "0.5.0", content: new[] { "content.txt" }, assemblyReferences: new[] { "Ref.dll" });
var localRepository = new MockPackageRepository();
var sourceRepository = new MockPackageRepository();
var fileSystem = new Mock<MockFileSystem> { CallBase = true };
var batchProcessor = fileSystem.As<IBatchProcessor<string>>();
batchProcessor.Setup(s => s.BeginProcessing(It.IsAny<IEnumerable<string>>(), PackageAction.Install))
.Callback((IEnumerable<string> files, PackageAction _) => Assert.Equal(new[] { PathFixUtility.FixPath(@"content\content.txt"), "Ref.dll" }, files))
.Verifiable();
batchProcessor.Setup(s => s.EndProcessing()).Verifiable();
var packageManager = new PackageManager(sourceRepository, new DefaultPackagePathResolver(fileSystem.Object), fileSystem.Object, localRepository);
sourceRepository.AddPackage(package);
// Act
packageManager.InstallPackage("B");
// Assert
Assert.True(localRepository.Exists(package));
batchProcessor.Verify();
}
示例11: InstallingSatellitePackageCopiesFilesIntoRuntimePackageFolderWhenRuntimeIsAlreadyInstalled
public void InstallingSatellitePackageCopiesFilesIntoRuntimePackageFolderWhenRuntimeIsAlreadyInstalled()
{
// Arrange
// Create a runtime package and a satellite package that has a dependency on the runtime package, and uses the
// local suffix convention.
var runtimePackage = PackageUtility.CreatePackage("foo", "1.0.0", assemblyReferences: new[] { @"lib\foo.dll" });
var satellitePackage = PackageUtility.CreatePackage("foo.ja-jp", "1.0.0", language: "ja-jp",
satelliteAssemblies: new[] { @"lib\ja-jp\foo.resources.dll", @"lib\ja-jp\foo.xml" },
dependencies: new[] { new PackageDependency("foo", VersionUtility.ParseVersionSpec("[1.0.0]")) });
var projectSystem = new MockProjectSystem();
var localRepository = new MockPackageRepository();
var sourceRepository = new MockPackageRepository();
var packageManager = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
sourceRepository.AddPackage(runtimePackage);
sourceRepository.AddPackage(satellitePackage);
// Act
packageManager.InstallPackage("foo");
packageManager.InstallPackage("foo.ja-jp");
// Assert
Assert.Equal(5, projectSystem.Paths.Count);
Assert.True(projectSystem.FileExists(@"foo.1.0.0\lib\foo.dll"));
Assert.True(projectSystem.FileExists(@"foo.1.0.0\lib\ja-jp\foo.resources.dll"));
Assert.True(projectSystem.FileExists(@"foo.1.0.0\lib\ja-jp\foo.xml"));
Assert.True(projectSystem.FileExists(@"foo.ja-jp.1.0.0\lib\ja-jp\foo.resources.dll"));
Assert.True(projectSystem.FileExists(@"foo.ja-jp.1.0.0\lib\ja-jp\foo.xml"));
}
示例12: InstallPackageAddsAllFilesToFileSystem
public void InstallPackageAddsAllFilesToFileSystem()
{
// Arrange
var projectSystem = new MockProjectSystem();
var sourceRepository = new MockPackageRepository();
var pathResolver = new DefaultPackagePathResolver(projectSystem);
var packageManager = new PackageManager(sourceRepository, pathResolver, projectSystem, new LocalPackageRepository(pathResolver, projectSystem));
IPackage packageA = PackageUtility.CreatePackage("A", "1.0",
new[] { "contentFile", @"sub\contentFile" },
new[] { @"lib\reference.dll" },
new[] { @"readme.txt" });
sourceRepository.AddPackage(packageA);
// Act
packageManager.InstallPackage("A");
// Assert
Assert.Equal(0, projectSystem.References.Count);
Assert.Equal(5, projectSystem.Paths.Count);
Assert.True(projectSystem.FileExists(@"A.1.0\content\contentFile"));
Assert.True(projectSystem.FileExists(@"A.1.0\content\sub\contentFile"));
Assert.True(projectSystem.FileExists(@"A.1.0\lib\reference.dll"));
Assert.True(projectSystem.FileExists(@"A.1.0\tools\readme.txt"));
Assert.True(projectSystem.FileExists(@"A.1.0\A.1.0.nupkg"));
}
示例13: InstallPackageDoesNotPerformWalkInfoCheckWhenPassingTheFlag
public void InstallPackageDoesNotPerformWalkInfoCheckWhenPassingTheFlag()
{
// In this test, we simulate installing a solution-level package which depends on
// a project-level package. Under normal condition, this is disallowed by NuGet.
// However, if passing the 'ignoreWalkInfo' parameter with value of 'true',
// NuGet will happily accept that. Hence the installation will succeed.
// This is used by the package restore mode.
var localRepository = new MockPackageRepository();
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var packageManager = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
// A is solution-level package
IPackage packageA = PackageUtility.CreatePackage("A", "1.0.0",
tools: new string[] { "init.ps1"},
dependencies: new[] {
new PackageDependency("C")
});
IPackage packageC = PackageUtility.CreatePackage("C", "1.0.0-RC-1", content: new string[] { "a.txt" } );
sourceRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageC);
// Act
packageManager.InstallPackage(packageA, ignoreDependencies: false, allowPrereleaseVersions: true, ignoreWalkInfo: true);
// Assert
Assert.True(localRepository.Exists(packageA));
Assert.True(localRepository.Exists(packageC));
}
示例14: ResolvePackage
private IEnumerable<ITaskItem> ResolvePackage(ITaskItem package)
{
string id = package.ItemSpec;
string version = package.GetMetadata("Version");
Log.LogMessage(MessageImportance.Normal, "Resolving Package Reference {0} {1}...", id, version);
// Initial version just searches a machine-level repository
var localFs = new PhysicalFileSystem(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NuGet", "Lib"));
var defaultResolver = new DefaultPackagePathResolver(localFs);
var machineRepo = new LocalPackageRepository(defaultResolver, localFs);
var buildRepo = new BuildPackageRepository();
var remoteRepo = new DataServicePackageRepository(new Uri("https://nuget.org/api/v2"));
var project = new BuildProjectSystem(ProjectDirectory, new FrameworkName(TargetFramework), CurrentReferences);
var manager = new PackageManager(remoteRepo, defaultResolver, localFs, machineRepo);
var projectManager = new ProjectManager(remoteRepo, defaultResolver, project, buildRepo);
// Install the package
var ver = new SemanticVersion(version);
manager.PackageInstalling += manager_PackageInstalling;
manager.InstallPackage(id, ver);
projectManager.AddPackageReference(id, ver);
return project.OutputReferences.Select(item =>
{
var name = AssemblyName.GetAssemblyName(item);
return new TaskItem(name.FullName, new Dictionary<string, string>() {
{"HintPath", item },
{"Private", "true"}
});
});
}
示例15: InstallPackageInstallsLowerReleaseVersionIfPrereleaseFlagIsNotSet
public void InstallPackageInstallsLowerReleaseVersionIfPrereleaseFlagIsNotSet()
{
// Arrange
var localRepository = new MockPackageRepository();
var sourceRepository = new MockPackageRepository();
var projectSystem = new MockProjectSystem();
var packageManager = new PackageManager(sourceRepository, new DefaultPackagePathResolver(projectSystem), projectSystem, localRepository);
IPackage packageA = PackageUtility.CreatePackage("A", "1.0.0",
dependencies: new[] {
new PackageDependency("C")
});
IPackage packageC_RC = PackageUtility.CreatePackage("C", "1.0.0-RC-1");
IPackage packageC = PackageUtility.CreatePackage("C", "0.9");
sourceRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageC);
sourceRepository.AddPackage(packageC_RC);
// Act
packageManager.InstallPackage("A", version: null, ignoreDependencies: false, allowPrereleaseVersions: false);
// Assert
Assert.True(localRepository.Exists(packageA));
Assert.True(localRepository.Exists(packageC));
}