public async override Task ExecuteCommand() { CalculateEffectivePackageSaveMode(); string installPath = ResolveInstallPath(); var packageSourceProvider = new NuGet.Configuration.PackageSourceProvider(Settings); var sourceRepositoryProvider = new SourceRepositoryProvider(packageSourceProvider, ResourceProviders); IEnumerable<SourceRepository> primarySources; IEnumerable<SourceRepository> secondarySources; GetEffectiveSources(sourceRepositoryProvider, out primarySources, out secondarySources); if(Arguments.Count == 0) { throw new InvalidOperationException(NuGetResources.InstallCommandPackageIdMustBeProvided); } string packageId = Arguments[0]; NuGetPackageManager packageManager = new NuGetPackageManager(sourceRepositoryProvider, installPath); ResolutionContext resolutionContext = new ResolutionContext(dependencyBehavior: DependencyBehavior, includePrelease: Prerelease); FolderNuGetProject nugetProject = new FolderNuGetProject(installPath); nugetProject.PackageSaveMode = EffectivePackageSaveMode; if (Version == null) { await packageManager.InstallPackageAsync(nugetProject, packageId, resolutionContext, new Common.Console(), primarySources, secondarySources, CancellationToken.None); } else { await packageManager.InstallPackageAsync(nugetProject, new PackageIdentity(packageId, new NuGetVersion(Version)), resolutionContext, new Common.Console(), primarySources, secondarySources, CancellationToken.None); } }
public async Task TestPackageRestoredEvent() { // Arrange var testSolutionManager = new TestSolutionManager(); var projectA = testSolutionManager.AddNewMSBuildProject(); var projectB = testSolutionManager.AddNewMSBuildProject(); var packageIdentity = Packages[0]; var testNuGetProjectContext = new TestNuGetProjectContext(); var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider(); var testSettings = NullSettings.Instance; var resolutionContext = new ResolutionContext(); var token = CancellationToken.None; var nuGetPackageManager = new NuGetPackageManager(sourceRepositoryProvider, testSettings, testSolutionManager); await nuGetPackageManager.InstallPackageAsync(projectA, packageIdentity, resolutionContext, new TestNuGetProjectContext(), sourceRepositoryProvider.GetRepositories().First(), null, token); await nuGetPackageManager.InstallPackageAsync(projectB, packageIdentity, resolutionContext, new TestNuGetProjectContext(), sourceRepositoryProvider.GetRepositories().First(), null, token); var packageRestoreManager = new PackageRestoreManager(sourceRepositoryProvider, testSettings, testSolutionManager); var restoredPackages = new List<PackageIdentity>(); packageRestoreManager.PackageRestoredEvent += delegate(object sender, PackageRestoredEventArgs args) { if(args.Restored) { restoredPackages.Add(args.Package); } }; Assert.True(nuGetPackageManager.PackageExistsInPackagesFolder(packageIdentity)); // Delete packages folder Directory.Delete(Path.Combine(testSolutionManager.SolutionDirectory, "packages"), recursive: true); Assert.False(nuGetPackageManager.PackageExistsInPackagesFolder((packageIdentity))); // Act await packageRestoreManager.RestoreMissingPackagesInSolutionAsync(CancellationToken.None); Assert.Equal(1, restoredPackages.Count); Assert.True(nuGetPackageManager.PackageExistsInPackagesFolder((packageIdentity))); }
public async Task UnzippedPackageInstall_Basic() { // Arrange var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider(); var testSolutionManager = new TestSolutionManager(); var testSettings = new NullSettings(); var nuGetPackageManager = new NuGetPackageManager(sourceRepositoryProvider, testSettings, testSolutionManager); var packagesFolderPath = PackagesFolderPathUtility.GetPackagesFolderPath(testSolutionManager, testSettings); var randomPackagesConfigFolderPath = TestFilesystemUtility.CreateRandomTestFolder(); var randomPackagesConfigPath = Path.Combine(randomPackagesConfigFolderPath, "packages.config"); var token = CancellationToken.None; var projectTargetFramework = NuGetFramework.Parse("net45"); var msBuildNuGetProjectSystem = new TestMSBuildNuGetProjectSystem(projectTargetFramework, new TestNuGetProjectContext()); var msBuildNuGetProject = new MSBuildNuGetProject(msBuildNuGetProjectSystem, packagesFolderPath, randomPackagesConfigPath); var packageIdentity = NoDependencyLibPackages[0]; // Pre-Assert // Check that the packages.config file does not exist Assert.False(File.Exists(randomPackagesConfigPath)); // Check that there are no packages returned by PackagesConfigProject var packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(0, packagesInPackagesConfig.Count); Assert.Equal(0, msBuildNuGetProjectSystem.References.Count); // Act await nuGetPackageManager.InstallPackageAsync(msBuildNuGetProject, packageIdentity, new ResolutionContext(), new TestNuGetProjectContext(), sourceRepositoryProvider.GetRepositories().First(), null, token); // Assert // Check that the packages.config file exists after the installation Assert.True(File.Exists(randomPackagesConfigPath)); // Check the number of packages and packages returned by PackagesConfigProject after the installation packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(1, packagesInPackagesConfig.Count); Assert.Equal(packageIdentity, packagesInPackagesConfig[0].PackageIdentity); Assert.Equal(projectTargetFramework, packagesInPackagesConfig[0].TargetFramework); // Clean-up TestFilesystemUtility.DeleteRandomTestFolders(testSolutionManager.SolutionDirectory, randomPackagesConfigFolderPath); }
public async Task Install(IReadOnlyList<SourceRepository> remoteRepositories, NuGetPackageManager packageManager) { if (_versionMatch == null) { return; } IReadOnlyList<SourceRepository> sourceRepositories = GetSourceRepositories(remoteRepositories); Trace.Verbose($"Installing package {_packageId} {_versionMatch.Version}"); ResolutionContext resolutionContext = new ResolutionContext( DependencyBehavior.Lowest, _allowPrereleaseVersions, _allowUnlisted, VersionConstraints.None); INuGetProjectContext projectContext = new NuGetProjectContext(); await packageManager.InstallPackageAsync(packageManager.PackagesFolderNuGetProject, new PackageIdentity(_packageId, _versionMatch), resolutionContext, projectContext, sourceRepositories, Array.Empty<SourceRepository>(), CancellationToken.None); Trace.Verbose($"Installed package {_packageId} {_versionMatch.Version}"); }
public async Task TestPacManInstallLowerSpecificVersionOfDependencyPackage() { // Arrange var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider(); var testSolutionManager = new TestSolutionManager(); var testSettings = new NullSettings(); var token = CancellationToken.None; var resolutionContext = new ResolutionContext(DependencyBehavior.Highest); var testNuGetProjectContext = new TestNuGetProjectContext(); var nuGetPackageManager = new NuGetPackageManager(sourceRepositoryProvider, testSettings, testSolutionManager); var packagesFolderPath = PackagesFolderPathUtility.GetPackagesFolderPath(testSolutionManager, testSettings); var packagePathResolver = new PackagePathResolver(packagesFolderPath); var projectA = testSolutionManager.AddNewMSBuildProject(); var packageIdentity0 = PackageWithDependents[0]; var dependentPackage = PackageWithDependents[2]; var latestVersion = await NuGetPackageManager.GetLatestVersionAsync(packageIdentity0.Id, resolutionContext, sourceRepositoryProvider.GetRepositories().First(), token); var packageLatest = new PackageIdentity(packageIdentity0.Id, latestVersion); // Act await nuGetPackageManager.InstallPackageAsync(projectA, dependentPackage, resolutionContext, testNuGetProjectContext, sourceRepositoryProvider.GetRepositories().First(), null, token); // Assert var projectAInstalled = (await projectA.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(2, projectAInstalled.Count); Assert.Equal(packageLatest, projectAInstalled[0].PackageIdentity); Assert.True(File.Exists(packagePathResolver.GetInstalledPackageFilePath(packageLatest))); Assert.Equal(dependentPackage, projectAInstalled[1].PackageIdentity); Assert.True(File.Exists(packagePathResolver.GetInstalledPackageFilePath(dependentPackage))); Assert.False(File.Exists(packagePathResolver.GetInstalledPackageFilePath(packageIdentity0))); // Main Act await nuGetPackageManager.InstallPackageAsync(projectA, packageIdentity0, resolutionContext, testNuGetProjectContext, sourceRepositoryProvider.GetRepositories().First(), null, token); // Assert projectAInstalled = (await projectA.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(2, projectAInstalled.Count); Assert.Equal(packageIdentity0, projectAInstalled[0].PackageIdentity); Assert.Equal(dependentPackage, projectAInstalled[1].PackageIdentity); Assert.True(File.Exists(packagePathResolver.GetInstalledPackageFilePath(dependentPackage))); Assert.False(File.Exists(packagePathResolver.GetInstalledPackageFilePath(packageLatest))); Assert.True(File.Exists(packagePathResolver.GetInstalledPackageFilePath(packageIdentity0))); // Clean-up TestFilesystemUtility.DeleteRandomTestFolders(testSolutionManager.SolutionDirectory); }
public async Task TestPacManInstallPackageWhichUsesExistingDependency() { // Arrange var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider(); var testSolutionManager = new TestSolutionManager(); var testSettings = new NullSettings(); var token = CancellationToken.None; var resolutionContext = new ResolutionContext(); var testNuGetProjectContext = new TestNuGetProjectContext(); var nuGetPackageManager = new NuGetPackageManager(sourceRepositoryProvider, testSettings, testSolutionManager); var packagesFolderPath = PackagesFolderPathUtility.GetPackagesFolderPath(testSolutionManager, testSettings); var packagePathResolver = new PackagePathResolver(packagesFolderPath); var projectA = testSolutionManager.AddNewMSBuildProject(); var packageIdentity0 = PackageWithDependents[0]; var packageIdentity1 = PackageWithDependents[1]; var packageIdentity2 = PackageWithDependents[2]; var packageIdentity3 = PackageWithDependents[3]; // Act await nuGetPackageManager.InstallPackageAsync(projectA, packageIdentity3, resolutionContext, testNuGetProjectContext, sourceRepositoryProvider.GetRepositories().First(), null, token); // Assert var projectAInstalled = (await projectA.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(2, projectAInstalled.Count); Assert.Equal(packageIdentity1, projectAInstalled[0].PackageIdentity); Assert.Equal(packageIdentity3, projectAInstalled[1].PackageIdentity); Assert.True(File.Exists(packagePathResolver.GetInstalledPackageFilePath(packageIdentity1))); Assert.True(File.Exists(packagePathResolver.GetInstalledPackageFilePath(packageIdentity3))); // Main Act await nuGetPackageManager.InstallPackageAsync(projectA, packageIdentity2, resolutionContext, testNuGetProjectContext, sourceRepositoryProvider.GetRepositories().First(), null, token); // Assert projectAInstalled = (await projectA.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(3, projectAInstalled.Count); Assert.Equal(packageIdentity1, projectAInstalled[0].PackageIdentity); Assert.Equal(packageIdentity2, projectAInstalled[2].PackageIdentity); Assert.Equal(packageIdentity3, projectAInstalled[1].PackageIdentity); Assert.False(File.Exists(packagePathResolver.GetInstalledPackageFilePath(packageIdentity0))); Assert.True(File.Exists(packagePathResolver.GetInstalledPackageFilePath(packageIdentity1))); Assert.True(File.Exists(packagePathResolver.GetInstalledPackageFilePath(packageIdentity2))); Assert.True(File.Exists(packagePathResolver.GetInstalledPackageFilePath(packageIdentity3))); // Clean-up TestFilesystemUtility.DeleteRandomTestFolders(testSolutionManager.SolutionDirectory); }
public async Task TestPacManPreviewUninstallDependencyPackage() { // Arrange var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider(); var testSolutionManager = new TestSolutionManager(); var testSettings = new NullSettings(); var token = CancellationToken.None; var resolutionContext = new ResolutionContext(); var testNuGetProjectContext = new TestNuGetProjectContext(); var packagesFolderPath = PackagesFolderPathUtility.GetPackagesFolderPath(testSolutionManager, testSettings); var nuGetPackageManager = new NuGetPackageManager(sourceRepositoryProvider, testSettings, testSolutionManager); var randomPackagesConfigFolderPath = TestFilesystemUtility.CreateRandomTestFolder(); var randomPackagesConfigPath = Path.Combine(randomPackagesConfigFolderPath, "packages.config"); var projectTargetFramework = NuGetFramework.Parse("net45"); var msBuildNuGetProjectSystem = new TestMSBuildNuGetProjectSystem(projectTargetFramework, new TestNuGetProjectContext()); var msBuildNuGetProject = new MSBuildNuGetProject(msBuildNuGetProjectSystem, packagesFolderPath, randomPackagesConfigPath); var packageIdentity = PackageWithDependents[2]; // Pre-Assert // Check that the packages.config file does not exist Assert.False(File.Exists(randomPackagesConfigPath)); // Check that there are no packages returned by PackagesConfigProject var packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(0, packagesInPackagesConfig.Count); Assert.Equal(0, msBuildNuGetProjectSystem.References.Count); // Act await nuGetPackageManager.InstallPackageAsync(msBuildNuGetProject, packageIdentity, resolutionContext, testNuGetProjectContext, sourceRepositoryProvider.GetRepositories().First(), null, token); // Assert // Check that the packages.config file exists after the installation Assert.True(File.Exists(randomPackagesConfigPath)); // Check the number of packages and packages returned by PackagesConfigProject after the installation packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(2, packagesInPackagesConfig.Count); Assert.Equal(packageIdentity, packagesInPackagesConfig[1].PackageIdentity); Assert.Equal(projectTargetFramework, packagesInPackagesConfig[1].TargetFramework); Assert.Equal(PackageWithDependents[0], packagesInPackagesConfig[0].PackageIdentity); Assert.Equal(projectTargetFramework, packagesInPackagesConfig[0].TargetFramework); // Main Act Exception exception = null; try { var uninstallationContext = new UninstallationContext(); var packageActions = await nuGetPackageManager.PreviewUninstallPackageAsync(msBuildNuGetProject, "jQuery", uninstallationContext, testNuGetProjectContext, token); } catch (InvalidOperationException ex) { exception = ex; } catch (AggregateException ex) { exception = ExceptionUtility.Unwrap(ex); } Assert.NotNull(exception); Assert.True(exception is InvalidOperationException); Assert.Equal("Unable to uninstall 'jQuery.1.4.4' because 'jQuery.Validation.1.13.1' depends on it.", exception.Message); // Clean-up TestFilesystemUtility.DeleteRandomTestFolders(testSolutionManager.SolutionDirectory, randomPackagesConfigFolderPath); }
public async Task TestPacManUninstallPackageOnMultipleProjects() { // Arrange var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider(); var testSolutionManager = new TestSolutionManager(); var testSettings = new NullSettings(); var token = CancellationToken.None; var resolutionContext = new ResolutionContext(); var testNuGetProjectContext = new TestNuGetProjectContext(); var nuGetPackageManager = new NuGetPackageManager(sourceRepositoryProvider, testSettings, testSolutionManager); var packagesFolderPath = PackagesFolderPathUtility.GetPackagesFolderPath(testSolutionManager, testSettings); var packagePathResolver = new PackagePathResolver(packagesFolderPath); var projectA = testSolutionManager.AddNewMSBuildProject(); var projectB = testSolutionManager.AddNewMSBuildProject(); var packageIdentity = NoDependencyLibPackages[0]; // Act await nuGetPackageManager.InstallPackageAsync(projectA, packageIdentity, resolutionContext, testNuGetProjectContext, sourceRepositoryProvider.GetRepositories().First(), null, token); await nuGetPackageManager.InstallPackageAsync(projectB, packageIdentity, resolutionContext, testNuGetProjectContext, sourceRepositoryProvider.GetRepositories().First(), null, token); // Assert var projectAInstalled = (await projectA.GetInstalledPackagesAsync(token)).ToList(); var projectBInstalled = (await projectB.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(1, projectAInstalled.Count); Assert.Equal(1, projectBInstalled.Count); // Main Act var uninstallationContext = new UninstallationContext(); await nuGetPackageManager.UninstallPackageAsync(projectA, packageIdentity.Id, uninstallationContext, testNuGetProjectContext, token); // Assert projectAInstalled = (await projectA.GetInstalledPackagesAsync(token)).ToList(); projectBInstalled = (await projectB.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(0, projectAInstalled.Count); Assert.Equal(1, projectBInstalled.Count); Assert.True(File.Exists(packagePathResolver.GetInstalledPackageFilePath(packageIdentity))); // Clean-up TestFilesystemUtility.DeleteRandomTestFolders(testSolutionManager.SolutionDirectory); }
public async Task<NuGetInstallResult> InstallPackage( string packageId, NuGetVersion version, bool prerelease) { var installPath = Path.Combine(Path.GetTempPath(), "testnuget"); var projectContext = new EmptyNuGetProjectContext { PackageExtractionContext = new PackageExtractionContext() }; var references = new List<string>(); var frameworkReferences = new List<string>(); var projectSystem = new DelegateNuGetProjectSystem(projectContext, (reference, isFrameworkReference) => { if (isFrameworkReference) frameworkReferences.Add(reference); else references.Add(reference); }); var project = new MSBuildNuGetProject(projectSystem, installPath, installPath); OverrideProject(project); var packageManager = new NuGetPackageManager(_sourceRepositoryProvider, _settings, installPath); var primaryRepositories = _packageSources.Select(_sourceRepositoryProvider.CreateRepository).ToArray(); var resolutionContext = new ResolutionContext( DependencyBehavior.Lowest, includePrelease: prerelease, includeUnlisted: true, versionConstraints: VersionConstraints.None); if (version == null) { // Find the latest version using NuGetPackageManager version = await NuGetPackageManager.GetLatestVersionAsync( packageId, project, resolutionContext, primaryRepositories, NullLogger.Instance, CancellationToken.None).ConfigureAwait(false); if (version == null) { throw new Exception("Unable to find package"); } } var packageIdentity = new PackageIdentity(packageId, version); await packageManager.InstallPackageAsync( project, packageIdentity, resolutionContext, projectContext, primaryRepositories, Enumerable.Empty<SourceRepository>(), CancellationToken.None).ConfigureAwait(false); return new NuGetInstallResult(references.AsReadOnly(), frameworkReferences.AsReadOnly()); }
public async Task TestPacManGetInstalledPackagesByDependencyOrder() { // Arrange var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider(); var testSolutionManager = new TestSolutionManager(); var testSettings = new NullSettings(); var token = CancellationToken.None; var nuGetPackageManager = new NuGetPackageManager(sourceRepositoryProvider, testSettings, testSolutionManager); var packagesFolderPath = PackagesFolderPathUtility.GetPackagesFolderPath(testSolutionManager, testSettings); var randomPackagesConfigFolderPath = TestFilesystemUtility.CreateRandomTestFolder(); var randomPackagesConfigPath = Path.Combine(randomPackagesConfigFolderPath, "packages.config"); var testNuGetProjectContext = new TestNuGetProjectContext(); var projectTargetFramework = NuGetFramework.Parse("net45"); var msBuildNuGetProjectSystem = new TestMSBuildNuGetProjectSystem(projectTargetFramework, testNuGetProjectContext); var msBuildNuGetProject = new MSBuildNuGetProject(msBuildNuGetProjectSystem, packagesFolderPath, randomPackagesConfigPath); var packageIdentity = PackageWithDeepDependency[6]; // WindowsAzure.Storage.4.3.0 // Pre-Assert // Check that the packages.config file does not exist Assert.False(File.Exists(randomPackagesConfigPath)); // Check that there are no packages returned by PackagesConfigProject var packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(0, packagesInPackagesConfig.Count); Assert.Equal(0, msBuildNuGetProjectSystem.References.Count); // Act await nuGetPackageManager.InstallPackageAsync(msBuildNuGetProject, packageIdentity, new ResolutionContext(), testNuGetProjectContext, sourceRepositoryProvider.GetRepositories().First(), null, token); // Assert // Check that the packages.config file exists after the installation Assert.True(File.Exists(randomPackagesConfigPath)); // Check the number of packages and packages returned by PackagesConfigProject after the installation packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(7, packagesInPackagesConfig.Count); var installedPackages = PackageWithDeepDependency.OrderBy(f => f.Id).ToList(); for (int i = 0; i < 7; i++) { Assert.True(installedPackages[i].Equals(packagesInPackagesConfig[i].PackageIdentity)); Assert.Equal(projectTargetFramework, packagesInPackagesConfig[i].TargetFramework); } // Main Assert List<PackageIdentity> installedPackagesInDependencyOrder = (await nuGetPackageManager.GetInstalledPackagesInDependencyOrder (msBuildNuGetProject, testNuGetProjectContext, token)).ToList(); Assert.Equal(7, installedPackagesInDependencyOrder.Count); for (int i = 0; i < 7; i++) { Assert.Equal(PackageWithDeepDependency[i], installedPackagesInDependencyOrder[i], PackageIdentity.Comparer); } // Clean-up TestFilesystemUtility.DeleteRandomTestFolders(testSolutionManager.SolutionDirectory, randomPackagesConfigFolderPath); }
public async Task TestPacManPreviewInstallPackageThrowsDependencyDowngrade() { // Arrange var packageIdentityA = new PackageIdentity("DotNetOpenAuth.OAuth.Core", new NuGetVersion("4.3.2.13293")); var packageIdentityB1 = new PackageIdentity("DotNetOpenAuth.Core", new NuGetVersion("4.3.2.13293")); var packageIdentityB2 = new PackageIdentity("DotNetOpenAuth.Core", new NuGetVersion("4.3.4.13329")); var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV2OnlySourceRepositoryProvider(); var testSolutionManager = new TestSolutionManager(); var testSettings = new NullSettings(); var token = CancellationToken.None; var nuGetPackageManager = new NuGetPackageManager(sourceRepositoryProvider, testSettings, testSolutionManager); var packagesFolderPath = PackagesFolderPathUtility.GetPackagesFolderPath(testSolutionManager, testSettings); var randomPackagesConfigFolderPath = TestFilesystemUtility.CreateRandomTestFolder(); var randomPackagesConfigPath = Path.Combine(randomPackagesConfigFolderPath, "packages.config"); var projectTargetFramework = NuGetFramework.Parse("net45"); var msBuildNuGetProjectSystem = new TestMSBuildNuGetProjectSystem(projectTargetFramework, new TestNuGetProjectContext()); var msBuildNuGetProject = new MSBuildNuGetProject(msBuildNuGetProjectSystem, packagesFolderPath, randomPackagesConfigPath); var testNuGetProjectContext = new TestNuGetProjectContext(); var primarySourceRepository = sourceRepositoryProvider.GetRepositories().First(); // Pre-Assert // Check that the packages.config file does not exist Assert.False(File.Exists(randomPackagesConfigPath)); // Check that there are no packages returned by PackagesConfigProject var packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(0, packagesInPackagesConfig.Count); Assert.Equal(0, msBuildNuGetProjectSystem.References.Count); // Act await nuGetPackageManager.InstallPackageAsync(msBuildNuGetProject, packageIdentityB2, new ResolutionContext(DependencyBehavior.Lowest, includePrelease: true), testNuGetProjectContext, primarySourceRepository, null, token); // Check that the packages.config file does not exist Assert.True(File.Exists(randomPackagesConfigPath)); // Check that there are no packages returned by PackagesConfigProject packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(2, packagesInPackagesConfig.Count); Exception exception = null; try { var packageActions = (await nuGetPackageManager.PreviewInstallPackageAsync(msBuildNuGetProject, packageIdentityA, new ResolutionContext(), testNuGetProjectContext, primarySourceRepository, null, token)).ToList(); } catch (Exception ex) { exception = ex; } Assert.NotNull(exception); Assert.True(exception is InvalidOperationException); Assert.Equal("Already referencing a newer version of '" + packageIdentityB1.Id + "'..", exception.Message); // Clean-up TestFilesystemUtility.DeleteRandomTestFolders(testSolutionManager.SolutionDirectory, randomPackagesConfigFolderPath); }
public async Task TestPacManUninstallWithRemoveDependenciesWithVDependency() { // Arrange var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider(); var testSolutionManager = new TestSolutionManager(); var testSettings = new NullSettings(); var token = CancellationToken.None; var resolutionContext = new ResolutionContext(); var testNuGetProjectContext = new TestNuGetProjectContext(); var nuGetPackageManager = new NuGetPackageManager(sourceRepositoryProvider, testSettings, testSolutionManager); var packagesFolderPath = PackagesFolderPathUtility.GetPackagesFolderPath(testSolutionManager, testSettings); var packagePathResolver = new PackagePathResolver(packagesFolderPath); var projectA = testSolutionManager.AddNewMSBuildProject(); var packageIdentity0 = PackageWithDependents[0]; var packageIdentity1 = PackageWithDependents[1]; var packageIdentity2 = PackageWithDependents[2]; var packageIdentity3 = PackageWithDependents[3]; // Act await nuGetPackageManager.InstallPackageAsync(projectA, packageIdentity2, resolutionContext, testNuGetProjectContext, sourceRepositoryProvider.GetRepositories().First(), null, token); // Assert var projectAInstalled = (await projectA.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(2, projectAInstalled.Count); Assert.Equal(packageIdentity0, projectAInstalled[0].PackageIdentity); Assert.Equal(packageIdentity2, projectAInstalled[1].PackageIdentity); Assert.True(File.Exists(packagePathResolver.GetInstalledPackageFilePath(packageIdentity0))); Assert.True(File.Exists(packagePathResolver.GetInstalledPackageFilePath(packageIdentity2))); // Main Act await nuGetPackageManager.InstallPackageAsync(projectA, packageIdentity3, resolutionContext, testNuGetProjectContext, sourceRepositoryProvider.GetRepositories().First(), null, token); // Assert projectAInstalled = (await projectA.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(3, projectAInstalled.Count); Assert.Equal(packageIdentity1, projectAInstalled[0].PackageIdentity); Assert.Equal(packageIdentity2, projectAInstalled[2].PackageIdentity); Assert.Equal(packageIdentity3, projectAInstalled[1].PackageIdentity); Assert.False(File.Exists(packagePathResolver.GetInstalledPackageFilePath(packageIdentity0))); Assert.True(File.Exists(packagePathResolver.GetInstalledPackageFilePath(packageIdentity1))); Assert.True(File.Exists(packagePathResolver.GetInstalledPackageFilePath(packageIdentity2))); Assert.True(File.Exists(packagePathResolver.GetInstalledPackageFilePath(packageIdentity3))); // Main Act Exception exception = null; try { var uninstallationContext = new UninstallationContext(removeDependencies: true); await nuGetPackageManager.UninstallPackageAsync(projectA, packageIdentity2.Id, uninstallationContext, testNuGetProjectContext, token); } catch (InvalidOperationException ex) { exception = ex; } catch (AggregateException ex) { exception = ExceptionUtility.Unwrap(ex); } Assert.NotNull(exception); Assert.True(exception is InvalidOperationException); Assert.Equal("Unable to uninstall 'jQuery.1.6.4' because 'jQuery.UI.Combined.1.11.2' depends on it.", exception.Message); // Clean-up TestFilesystemUtility.DeleteRandomTestFolders(testSolutionManager.SolutionDirectory); }
public async Task TestPacManReinstallPackages() { // Arrange var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV2OnlySourceRepositoryProvider(); var testSolutionManager = new TestSolutionManager(); var testSettings = new NullSettings(); var token = CancellationToken.None; var nuGetPackageManager = new NuGetPackageManager(sourceRepositoryProvider, testSettings, testSolutionManager); var packagesFolderPath = PackagesFolderPathUtility.GetPackagesFolderPath(testSolutionManager, testSettings); var packagePathResolver = new PackagePathResolver(packagesFolderPath); var randomPackagesConfigFolderPath = TestFilesystemUtility.CreateRandomTestFolder(); var randomPackagesConfigPath = Path.Combine(randomPackagesConfigFolderPath, "packages.config"); var projectTargetFramework = NuGetFramework.Parse("net45"); var msBuildNuGetProjectSystem = new TestMSBuildNuGetProjectSystem(projectTargetFramework, new TestNuGetProjectContext()); var msBuildNuGetProject = new MSBuildNuGetProject(msBuildNuGetProjectSystem, packagesFolderPath, randomPackagesConfigPath); var folderNuGetProject = msBuildNuGetProject.FolderNuGetProject; var packageIdentity = MorePackageWithDependents[3]; // Microsoft.Net.Http.2.2.22 // Pre-Assert // Check that the packages.config file does not exist Assert.False(File.Exists(randomPackagesConfigPath)); // Check that there are no packages returned by PackagesConfigProject var packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(0, packagesInPackagesConfig.Count); Assert.Equal(0, msBuildNuGetProjectSystem.References.Count); // Act await nuGetPackageManager.InstallPackageAsync(msBuildNuGetProject, packageIdentity, new ResolutionContext(), new TestNuGetProjectContext(), sourceRepositoryProvider.GetRepositories().First(), null, token); // Assert // Check that the packages.config file exists after the installation Assert.True(File.Exists(randomPackagesConfigPath)); // Check the number of packages and packages returned by PackagesConfigProject after the installation packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(3, packagesInPackagesConfig.Count); Assert.Equal(packageIdentity, packagesInPackagesConfig[2].PackageIdentity); Assert.Equal(projectTargetFramework, packagesInPackagesConfig[2].TargetFramework); Assert.Equal(MorePackageWithDependents[0], packagesInPackagesConfig[1].PackageIdentity); Assert.Equal(projectTargetFramework, packagesInPackagesConfig[1].TargetFramework); Assert.Equal(MorePackageWithDependents[2], packagesInPackagesConfig[0].PackageIdentity); Assert.Equal(projectTargetFramework, packagesInPackagesConfig[0].TargetFramework); var installedPackageIdentities = (await msBuildNuGetProject.GetInstalledPackagesAsync(token)) .Select(pr => pr.PackageIdentity); // Act var packageActions = (await nuGetPackageManager.PreviewReinstallPackagesAsync(installedPackageIdentities, msBuildNuGetProject, new ResolutionContext(DependencyBehavior.Highest), new TestNuGetProjectContext(), sourceRepositoryProvider.GetRepositories().First(), null, token)).ToList(); // Assert var singlePackageSource = sourceRepositoryProvider.GetRepositories().Single().PackageSource.Source; Assert.Equal(6, packageActions.Count); Assert.True(MorePackageWithDependents[3].Equals(packageActions[0].PackageIdentity)); Assert.Equal(NuGetProjectActionType.Uninstall, packageActions[0].NuGetProjectActionType); Assert.True(MorePackageWithDependents[2].Equals(packageActions[1].PackageIdentity)); Assert.Equal(NuGetProjectActionType.Uninstall, packageActions[1].NuGetProjectActionType); Assert.True(MorePackageWithDependents[0].Equals(packageActions[2].PackageIdentity)); Assert.Equal(NuGetProjectActionType.Uninstall, packageActions[2].NuGetProjectActionType); Assert.True(MorePackageWithDependents[0].Equals(packageActions[3].PackageIdentity)); Assert.Equal(NuGetProjectActionType.Install, packageActions[3].NuGetProjectActionType); Assert.Equal(singlePackageSource, packageActions[3].SourceRepository.PackageSource.Source); Assert.True(MorePackageWithDependents[2].Equals(packageActions[4].PackageIdentity)); Assert.Equal(NuGetProjectActionType.Install, packageActions[4].NuGetProjectActionType); Assert.Equal(singlePackageSource, packageActions[4].SourceRepository.PackageSource.Source); Assert.True(MorePackageWithDependents[3].Equals(packageActions[5].PackageIdentity)); Assert.Equal(NuGetProjectActionType.Install, packageActions[5].NuGetProjectActionType); Assert.Equal(singlePackageSource, packageActions[5].SourceRepository.PackageSource.Source); // Main Act await nuGetPackageManager.ExecuteNuGetProjectActionsAsync(msBuildNuGetProject, packageActions, new TestNuGetProjectContext(), token); // Check that the packages.config file exists after the installation Assert.True(File.Exists(randomPackagesConfigPath)); // Check the number of packages and packages returned by PackagesConfigProject after the installation packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(3, packagesInPackagesConfig.Count); Assert.Equal(packageIdentity, packagesInPackagesConfig[2].PackageIdentity); Assert.Equal(projectTargetFramework, packagesInPackagesConfig[2].TargetFramework); Assert.Equal(MorePackageWithDependents[0], packagesInPackagesConfig[1].PackageIdentity); Assert.Equal(projectTargetFramework, packagesInPackagesConfig[1].TargetFramework); Assert.Equal(MorePackageWithDependents[2], packagesInPackagesConfig[0].PackageIdentity); Assert.Equal(projectTargetFramework, packagesInPackagesConfig[0].TargetFramework); Assert.True(File.Exists(folderNuGetProject.GetInstalledPackageFilePath(packageIdentity))); Assert.True(File.Exists(folderNuGetProject.GetInstalledPackageFilePath(MorePackageWithDependents[0]))); Assert.True(File.Exists(folderNuGetProject.GetInstalledPackageFilePath(MorePackageWithDependents[2]))); // Clean-up TestFilesystemUtility.DeleteRandomTestFolders(testSolutionManager.SolutionDirectory, randomPackagesConfigFolderPath); }
public async Task TestPacManOpenReadmeFile() { // Arrange var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider(); var testSolutionManager = new TestSolutionManager(); var testSettings = new NullSettings(); var token = CancellationToken.None; var nuGetPackageManager = new NuGetPackageManager(sourceRepositoryProvider, testSettings, testSolutionManager); var packagesFolderPath = PackagesFolderPathUtility.GetPackagesFolderPath(testSolutionManager, testSettings); var packagePathResolver = new PackagePathResolver(packagesFolderPath); var randomPackagesConfigFolderPath = TestFilesystemUtility.CreateRandomTestFolder(); var randomPackagesConfigPath = Path.Combine(randomPackagesConfigFolderPath, "packages.config"); var testNuGetProjectContext = new TestNuGetProjectContext(); var projectTargetFramework = NuGetFramework.Parse("net45"); var msBuildNuGetProjectSystem = new TestMSBuildNuGetProjectSystem(projectTargetFramework, testNuGetProjectContext); var msBuildNuGetProject = new MSBuildNuGetProject(msBuildNuGetProjectSystem, packagesFolderPath, randomPackagesConfigPath); var packageIdentity = new PackageIdentity("elmah", new NuGetVersion("1.2.2")); // Pre-Assert // Check that the packages.config file does not exist Assert.False(File.Exists(randomPackagesConfigPath)); // Check that there are no packages returned by PackagesConfigProject var packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(0, packagesInPackagesConfig.Count); Assert.Equal(0, msBuildNuGetProjectSystem.References.Count); // Act // Set the direct install on the execution context of INuGetProjectContext before installing a package testNuGetProjectContext.TestExecutionContext = new TestExecutionContext(packageIdentity); await nuGetPackageManager.InstallPackageAsync(msBuildNuGetProject, packageIdentity, new ResolutionContext(), testNuGetProjectContext, sourceRepositoryProvider.GetRepositories().First(), null, token); // Assert // Check that the packages.config file exists after the installation Assert.True(File.Exists(randomPackagesConfigPath)); // Check the number of packages and packages returned by PackagesConfigProject after the installation packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(2, packagesInPackagesConfig.Count); Assert.Equal(packageIdentity, packagesInPackagesConfig[0].PackageIdentity); Assert.Equal(projectTargetFramework, packagesInPackagesConfig[0].TargetFramework); Assert.Equal(1, testNuGetProjectContext.TestExecutionContext.FilesOpened.Count); Assert.True(String.Equals(Path.Combine(packagePathResolver.GetInstallPath(packageIdentity), "ReadMe.txt"), testNuGetProjectContext.TestExecutionContext.FilesOpened.First(), StringComparison.OrdinalIgnoreCase)); // Clean-up TestFilesystemUtility.DeleteRandomTestFolders(testSolutionManager.SolutionDirectory, randomPackagesConfigFolderPath); }
public async Task TestPacManPreviewUpdatePackagesSimple() { // Arrange var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV2OnlySourceRepositoryProvider(); var testSolutionManager = new TestSolutionManager(); var testSettings = new NullSettings(); var token = CancellationToken.None; var nuGetPackageManager = new NuGetPackageManager(sourceRepositoryProvider, testSettings, testSolutionManager); var packagesFolderPath = PackagesFolderPathUtility.GetPackagesFolderPath(testSolutionManager, testSettings); var randomPackagesConfigFolderPath = TestFilesystemUtility.CreateRandomTestFolder(); var randomPackagesConfigPath = Path.Combine(randomPackagesConfigFolderPath, "packages.config"); var projectTargetFramework = NuGetFramework.Parse("net45"); var msBuildNuGetProjectSystem = new TestMSBuildNuGetProjectSystem(projectTargetFramework, new TestNuGetProjectContext()); var msBuildNuGetProject = new MSBuildNuGetProject(msBuildNuGetProjectSystem, packagesFolderPath, randomPackagesConfigPath); var packageIdentity0 = PackageWithDependents[0]; // jQuery.1.4.4 var resolutionContext = new ResolutionContext(); var latestVersion = await NuGetPackageManager.GetLatestVersionAsync(packageIdentity0.Id, new ResolutionContext(), sourceRepositoryProvider.GetRepositories().First(), token); var packageLatest = new PackageIdentity(packageIdentity0.Id, latestVersion); // Pre-Assert // Check that the packages.config file does not exist Assert.False(File.Exists(randomPackagesConfigPath)); // Check that there are no packages returned by PackagesConfigProject var packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(0, packagesInPackagesConfig.Count); Assert.Equal(0, msBuildNuGetProjectSystem.References.Count); // Act await nuGetPackageManager.InstallPackageAsync(msBuildNuGetProject, packageIdentity0, resolutionContext, new TestNuGetProjectContext(), sourceRepositoryProvider.GetRepositories().First(), null, token); // Assert // Check that the packages.config file exists after the installation Assert.True(File.Exists(randomPackagesConfigPath)); // Check the number of packages and packages returned by PackagesConfigProject after the installation packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(1, packagesInPackagesConfig.Count); Assert.Equal(packageIdentity0, packagesInPackagesConfig[0].PackageIdentity); Assert.Equal(projectTargetFramework, packagesInPackagesConfig[0].TargetFramework); var installedPackageIds = (await msBuildNuGetProject.GetInstalledPackagesAsync(token)) .Select(pr => pr.PackageIdentity.Id); // Main Act var packageActions = (await nuGetPackageManager.PreviewUpdatePackagesAsync(installedPackageIds, msBuildNuGetProject, new ResolutionContext(DependencyBehavior.Highest), new TestNuGetProjectContext(), sourceRepositoryProvider.GetRepositories().First(), null, token)).ToList(); // Assert Assert.Equal(2, packageActions.Count); Assert.True(packageIdentity0.Equals(packageActions[0].PackageIdentity)); Assert.Equal(NuGetProjectActionType.Uninstall, packageActions[0].NuGetProjectActionType); Assert.True(packageLatest.Equals(packageActions[1].PackageIdentity)); Assert.Equal(NuGetProjectActionType.Install, packageActions[1].NuGetProjectActionType); Assert.Equal(sourceRepositoryProvider.GetRepositories().Single().PackageSource.Source, packageActions[1].SourceRepository.PackageSource.Source); // Clean-up TestFilesystemUtility.DeleteRandomTestFolders(testSolutionManager.SolutionDirectory, randomPackagesConfigFolderPath); }
public async Task TestPacManInstallMvcTargetingNet45() { // Arrange var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider(); var testSolutionManager = new TestSolutionManager(); var testSettings = new NullSettings(); var token = CancellationToken.None; var nuGetPackageManager = new NuGetPackageManager(sourceRepositoryProvider, testSettings, testSolutionManager); var packagesFolderPath = PackagesFolderPathUtility.GetPackagesFolderPath(testSolutionManager, testSettings); var randomPackagesConfigFolderPath = TestFilesystemUtility.CreateRandomTestFolder(); var randomPackagesConfigPath = Path.Combine(randomPackagesConfigFolderPath, "packages.config"); var projectTargetFramework = NuGetFramework.Parse("net45"); var msBuildNuGetProjectSystem = new TestMSBuildNuGetProjectSystem(projectTargetFramework, new TestNuGetProjectContext()); var msBuildNuGetProject = new MSBuildNuGetProject(msBuildNuGetProjectSystem, packagesFolderPath, randomPackagesConfigPath); var packageIdentity = LatestAspNetPackages[0]; // Microsoft.AspNet.Mvc.6.0.0-beta3 // Pre-Assert // Check that the packages.config file does not exist Assert.False(File.Exists(randomPackagesConfigPath)); // Check that there are no packages returned by PackagesConfigProject var packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(0, packagesInPackagesConfig.Count); Assert.Equal(0, msBuildNuGetProjectSystem.References.Count); var resolutionContext = new ResolutionContext(DependencyBehavior.Lowest, includePrelease: true); Exception exception = null; try { // Act await nuGetPackageManager.InstallPackageAsync(msBuildNuGetProject, packageIdentity, resolutionContext, new TestNuGetProjectContext(), sourceRepositoryProvider.GetRepositories().First(), null, token); } catch (Exception ex) { exception = ex; } Assert.NotNull(exception); Assert.True(exception is InvalidOperationException); var errorMessage = String.Format(CultureInfo.CurrentCulture, Strings.UnableToFindCompatibleItems, packageIdentity.Id + " " + packageIdentity.Version.ToNormalizedString(), projectTargetFramework); Assert.Equal(errorMessage, exception.Message); // Clean-up TestFilesystemUtility.DeleteRandomTestFolders(randomPackagesConfigPath, randomPackagesConfigFolderPath); }
public async Task TestPacManPreviewUninstallPackageWithDeepDependency() { // Arrange var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider(); var testSolutionManager = new TestSolutionManager(); var testSettings = new NullSettings(); var token = CancellationToken.None; var nuGetPackageManager = new NuGetPackageManager(sourceRepositoryProvider, testSettings, testSolutionManager); var packagesFolderPath = PackagesFolderPathUtility.GetPackagesFolderPath(testSolutionManager, testSettings); var randomPackagesConfigFolderPath = TestFilesystemUtility.CreateRandomTestFolder(); var randomPackagesConfigPath = Path.Combine(randomPackagesConfigFolderPath, "packages.config"); var projectTargetFramework = NuGetFramework.Parse("net45"); var msBuildNuGetProjectSystem = new TestMSBuildNuGetProjectSystem(projectTargetFramework, new TestNuGetProjectContext()); var msBuildNuGetProject = new MSBuildNuGetProject(msBuildNuGetProjectSystem, packagesFolderPath, randomPackagesConfigPath); var packageIdentity = PackageWithDeepDependency[6]; // WindowsAzure.Storage.4.3.0 // Pre-Assert // Check that the packages.config file does not exist Assert.False(File.Exists(randomPackagesConfigPath)); // Check that there are no packages returned by PackagesConfigProject var packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(0, packagesInPackagesConfig.Count); Assert.Equal(0, msBuildNuGetProjectSystem.References.Count); // Act await nuGetPackageManager.InstallPackageAsync(msBuildNuGetProject, packageIdentity, new ResolutionContext(), new TestNuGetProjectContext(), sourceRepositoryProvider.GetRepositories().First(), null, token); // Assert // Check that the packages.config file exists after the installation Assert.True(File.Exists(randomPackagesConfigPath)); // Check the number of packages and packages returned by PackagesConfigProject after the installation packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(7, packagesInPackagesConfig.Count); Assert.Equal(packageIdentity, packagesInPackagesConfig[6].PackageIdentity); Assert.Equal(projectTargetFramework, packagesInPackagesConfig[6].TargetFramework); // Main Act var packageActions = (await nuGetPackageManager.PreviewUninstallPackageAsync(msBuildNuGetProject, PackageWithDeepDependency[6], new UninstallationContext(removeDependencies: true), new TestNuGetProjectContext(), token)).ToList(); Assert.Equal(7, packageActions.Count); var soleSourceRepository = sourceRepositoryProvider.GetRepositories().Single(); Assert.Equal(PackageWithDeepDependency[6], packageActions[0].PackageIdentity); Assert.Equal(NuGetProjectActionType.Uninstall, packageActions[0].NuGetProjectActionType); Assert.Equal(PackageWithDeepDependency[2], packageActions[1].PackageIdentity); Assert.Equal(NuGetProjectActionType.Uninstall, packageActions[1].NuGetProjectActionType); Assert.Equal(PackageWithDeepDependency[5], packageActions[2].PackageIdentity); Assert.Equal(NuGetProjectActionType.Uninstall, packageActions[2].NuGetProjectActionType); Assert.Equal(PackageWithDeepDependency[4], packageActions[3].PackageIdentity); Assert.Equal(NuGetProjectActionType.Uninstall, packageActions[3].NuGetProjectActionType); Assert.Equal(PackageWithDeepDependency[1], packageActions[4].PackageIdentity); Assert.Equal(NuGetProjectActionType.Uninstall, packageActions[4].NuGetProjectActionType); Assert.Equal(PackageWithDeepDependency[3], packageActions[5].PackageIdentity); Assert.Equal(NuGetProjectActionType.Uninstall, packageActions[5].NuGetProjectActionType); Assert.Equal(PackageWithDeepDependency[0], packageActions[6].PackageIdentity); Assert.Equal(NuGetProjectActionType.Uninstall, packageActions[6].NuGetProjectActionType); // Clean-up TestFilesystemUtility.DeleteRandomTestFolders(testSolutionManager.SolutionDirectory, randomPackagesConfigFolderPath); }
/// <summary> /// Core install method. All installs from the VS API and template wizard end up here. /// </summary> internal async Task InstallInternal(Project project, List<PackageIdentity> packages, ISourceRepositoryProvider repoProvider, VSAPIProjectContext projectContext, bool ignoreDependencies, CancellationToken token) { // store expanded node state IDictionary<string, ISet<VsHierarchyItem>> expandedNodes = VsHierarchyHelper.GetAllExpandedNodes(_solutionManager); try { DependencyBehavior depBehavior = ignoreDependencies ? DependencyBehavior.Ignore : DependencyBehavior.Lowest; bool includePrerelease = false; ResolutionContext resolution = new ResolutionContext(depBehavior, includePrerelease, false); NuGetPackageManager packageManager = new NuGetPackageManager(repoProvider, _settings, _solutionManager); // find the project NuGetProject nuGetProject = PackageManagementHelpers.GetProject(_solutionManager, project, projectContext); // install the package foreach (PackageIdentity package in packages) { if (package.Version == null) { if (!_packageServices.IsPackageInstalled(project, package.Id)) { await packageManager.InstallPackageAsync(nuGetProject, package.Id, resolution, projectContext, repoProvider.GetRepositories(), Enumerable.Empty<SourceRepository>(), token); } } else { if (!_packageServices.IsPackageInstalledEx(project, package.Id, package.Version.ToString())) { await packageManager.InstallPackageAsync(nuGetProject, package, resolution, projectContext, repoProvider.GetRepositories(), Enumerable.Empty<SourceRepository>(), token); } } } } finally { // collapse nodes VsHierarchyHelper.CollapseAllNodes(_solutionManager, expandedNodes); } }
public async Task TestPacManPreviewInstallWithAllowedVersionsConstraint() { // Arrange var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV2OnlySourceRepositoryProvider(); var testSolutionManager = new TestSolutionManager(); var testSettings = new NullSettings(); var token = CancellationToken.None; var nuGetPackageManager = new NuGetPackageManager(sourceRepositoryProvider, testSettings, testSolutionManager); var packagesFolderPath = PackagesFolderPathUtility.GetPackagesFolderPath(testSolutionManager, testSettings); var randomPackagesConfigFolderPath = TestFilesystemUtility.CreateRandomTestFolder(); var randomPackagesConfigPath = Path.Combine(randomPackagesConfigFolderPath, "packages.config"); var projectTargetFramework = NuGetFramework.Parse("net45"); var msBuildNuGetProjectSystem = new TestMSBuildNuGetProjectSystem(projectTargetFramework, new TestNuGetProjectContext()); var msBuildNuGetProject = new MSBuildNuGetProject(msBuildNuGetProjectSystem, packagesFolderPath, randomPackagesConfigPath); var newtonsoftJsonPackageId = "newtonsoft.json"; var newtonsoftJsonPackageIdentity = new PackageIdentity(newtonsoftJsonPackageId, NuGetVersion.Parse("4.5.11")); var primarySourceRepository = sourceRepositoryProvider.GetRepositories().Single(); var resolutionContext = new ResolutionContext(); var testNuGetProjectContext = new TestNuGetProjectContext(); // Act await nuGetPackageManager.InstallPackageAsync(msBuildNuGetProject, newtonsoftJsonPackageIdentity, resolutionContext, testNuGetProjectContext, primarySourceRepository, null, token); // Assert // Check that the packages.config file exists after the installation Assert.True(File.Exists(randomPackagesConfigPath)); // Check the number of packages and packages returned by PackagesConfigProject after the installation var packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(1, packagesInPackagesConfig.Count); Assert.Equal(newtonsoftJsonPackageIdentity, packagesInPackagesConfig[0].PackageIdentity); Assert.Equal(projectTargetFramework, packagesInPackagesConfig[0].TargetFramework); var installedPackages = await msBuildNuGetProject.GetInstalledPackagesAsync(token); var newtonsoftJsonPackageReference = installedPackages.Where(pr => pr.PackageIdentity.Equals(newtonsoftJsonPackageIdentity)).FirstOrDefault(); Assert.Null(newtonsoftJsonPackageReference.AllowedVersions); const string newPackagesConfig = @"<?xml version='1.0' encoding='utf-8'?> <packages> <package id='Newtonsoft.Json' version='4.5.11' allowedVersions='[4.0,5.0)' targetFramework='net45' /> </packages> "; File.WriteAllText(randomPackagesConfigPath, newPackagesConfig); // Check that the packages.config file exists after the installation Assert.True(File.Exists(randomPackagesConfigPath)); // Check the number of packages and packages returned by PackagesConfigProject after the installation packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(1, packagesInPackagesConfig.Count); Assert.Equal(newtonsoftJsonPackageIdentity, packagesInPackagesConfig[0].PackageIdentity); Assert.Equal(projectTargetFramework, packagesInPackagesConfig[0].TargetFramework); installedPackages = await msBuildNuGetProject.GetInstalledPackagesAsync(token); newtonsoftJsonPackageReference = installedPackages.Where(pr => pr.PackageIdentity.Equals(newtonsoftJsonPackageIdentity)).FirstOrDefault(); Assert.NotNull(newtonsoftJsonPackageReference.AllowedVersions); Exception exception = null; try { // Main Act await nuGetPackageManager.PreviewInstallPackageAsync(msBuildNuGetProject, newtonsoftJsonPackageId, resolutionContext, testNuGetProjectContext, primarySourceRepository, null, token); } catch (Exception ex) { exception = ex; } Assert.NotNull(exception); }
public async Task TestPacManThrowsLatestVersionNotFound() { // Arrange var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider(); var testSolutionManager = new TestSolutionManager(); var testSettings = new NullSettings(); var token = CancellationToken.None; var nuGetPackageManager = new NuGetPackageManager(sourceRepositoryProvider, testSettings, testSolutionManager); var packagesFolderPath = PackagesFolderPathUtility.GetPackagesFolderPath(testSolutionManager, testSettings); var randomPackagesConfigFolderPath = TestFilesystemUtility.CreateRandomTestFolder(); var randomPackagesConfigPath = Path.Combine(randomPackagesConfigFolderPath, "packages.config"); var projectTargetFramework = NuGetFramework.Parse("net45"); var msBuildNuGetProjectSystem = new TestMSBuildNuGetProjectSystem(projectTargetFramework, new TestNuGetProjectContext()); var msBuildNuGetProject = new MSBuildNuGetProject(msBuildNuGetProjectSystem, packagesFolderPath, randomPackagesConfigPath); var packageIdentity = "DoesNotExist"; // Pre-Assert // Check that the packages.config file does not exist Assert.False(File.Exists(randomPackagesConfigPath)); // Check that there are no packages returned by PackagesConfigProject var packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(0, packagesInPackagesConfig.Count); Assert.Equal(0, msBuildNuGetProjectSystem.References.Count); // Act Exception exception = null; try { await nuGetPackageManager.InstallPackageAsync(msBuildNuGetProject, packageIdentity, new ResolutionContext(), new TestNuGetProjectContext(), sourceRepositoryProvider.GetRepositories().First(), null, token); } catch (Exception ex) { exception = ex; } Assert.NotNull(exception); Assert.True(exception is InvalidOperationException); Assert.Equal("No latest version found for the 'DoesNotExist' for the given source repositories and resolution context", exception.Message); // Clean-up TestFilesystemUtility.DeleteRandomTestFolders(testSolutionManager.SolutionDirectory, randomPackagesConfigFolderPath); }
public async Task TestPacManPreviewUpdateWithAllowedVersionsConstraint() { // Arrange var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV2OnlySourceRepositoryProvider(); var testSolutionManager = new TestSolutionManager(); var testSettings = new NullSettings(); var token = CancellationToken.None; var nuGetPackageManager = new NuGetPackageManager(sourceRepositoryProvider, testSettings, testSolutionManager); var packagesFolderPath = PackagesFolderPathUtility.GetPackagesFolderPath(testSolutionManager, testSettings); var randomPackagesConfigFolderPath = TestFilesystemUtility.CreateRandomTestFolder(); var randomPackagesConfigPath = Path.Combine(randomPackagesConfigFolderPath, "packages.config"); var projectTargetFramework = NuGetFramework.Parse("net45"); var msBuildNuGetProjectSystem = new TestMSBuildNuGetProjectSystem(projectTargetFramework, new TestNuGetProjectContext()); var msBuildNuGetProject = new MSBuildNuGetProject(msBuildNuGetProjectSystem, packagesFolderPath, randomPackagesConfigPath); var newtonsoftJsonPackageId = "newtonsoft.json"; var newtonsoftJsonPackageIdentity = new PackageIdentity(newtonsoftJsonPackageId, NuGetVersion.Parse("4.5.11")); var primarySourceRepository = sourceRepositoryProvider.GetRepositories().Single(); var resolutionContext = new ResolutionContext(DependencyBehavior.Highest); var testNuGetProjectContext = new TestNuGetProjectContext(); // Act await nuGetPackageManager.InstallPackageAsync(msBuildNuGetProject, newtonsoftJsonPackageIdentity, resolutionContext, testNuGetProjectContext, primarySourceRepository, null, token); await nuGetPackageManager.InstallPackageAsync(msBuildNuGetProject, new PackageIdentity("Microsoft.Web.Infrastructure", new NuGetVersion("1.0.0.0")), resolutionContext, testNuGetProjectContext, primarySourceRepository, null, token); // Assert // Check that the packages.config file exists after the installation Assert.True(File.Exists(randomPackagesConfigPath)); // Check the number of packages and packages returned by PackagesConfigProject after the installation var packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(2, packagesInPackagesConfig.Count); Assert.Equal(newtonsoftJsonPackageIdentity, packagesInPackagesConfig[1].PackageIdentity); Assert.Equal(projectTargetFramework, packagesInPackagesConfig[1].TargetFramework); var installedPackages = await msBuildNuGetProject.GetInstalledPackagesAsync(token); var newtonsoftJsonPackageReference = installedPackages.Where(pr => pr.PackageIdentity.Equals(newtonsoftJsonPackageIdentity)).FirstOrDefault(); Assert.Null(newtonsoftJsonPackageReference.AllowedVersions); const string newPackagesConfig = @"<?xml version='1.0' encoding='utf-8'?> <packages> <package id='Microsoft.Web.Infrastructure' version='1.0.0.0' targetFramework='net45' /> <package id='Newtonsoft.Json' version='4.5.11' allowedVersions='[4.0,5.0)' targetFramework='net45' /> </packages> "; File.WriteAllText(randomPackagesConfigPath, newPackagesConfig); // Check that the packages.config file exists after the installation Assert.True(File.Exists(randomPackagesConfigPath)); // Check the number of packages and packages returned by PackagesConfigProject after the installation packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(2, packagesInPackagesConfig.Count); Assert.Equal(newtonsoftJsonPackageIdentity, packagesInPackagesConfig[1].PackageIdentity); Assert.Equal(projectTargetFramework, packagesInPackagesConfig[1].TargetFramework); installedPackages = await msBuildNuGetProject.GetInstalledPackagesAsync(token); newtonsoftJsonPackageReference = installedPackages.Where(pr => pr.PackageIdentity.Equals(newtonsoftJsonPackageIdentity)).FirstOrDefault(); Assert.NotNull(newtonsoftJsonPackageReference.AllowedVersions); // Main Act var nuGetProjectActions = (await nuGetPackageManager.PreviewUpdatePackagesAsync(new List<string>() { newtonsoftJsonPackageId, "Microsoft.Web.Infrastructure" }, msBuildNuGetProject, resolutionContext, testNuGetProjectContext, primarySourceRepository, null, token)).ToList(); // Microsoft.Web.Infrastructure has no updates. However, newtonsoft.json has updates but does not satisfy the version range // Hence, no nuget project actions to perform Assert.Equal(0, nuGetProjectActions.Count); }
public async Task TestPacManUpdateDependencyToPrereleaseVersion() { // Arrange var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider(); var testSolutionManager = new TestSolutionManager(); var testSettings = new NullSettings(); var token = CancellationToken.None; var nuGetPackageManager = new NuGetPackageManager(sourceRepositoryProvider, testSettings, testSolutionManager); var packagesFolderPath = PackagesFolderPathUtility.GetPackagesFolderPath(testSolutionManager, testSettings); var randomPackagesConfigFolderPath = TestFilesystemUtility.CreateRandomTestFolder(); var randomPackagesConfigPath = Path.Combine(randomPackagesConfigFolderPath, "packages.config"); var primarySourceRepository = sourceRepositoryProvider.GetRepositories().First(); var projectTargetFramework = NuGetFramework.Parse("net45"); var msBuildNuGetProjectSystem = new TestMSBuildNuGetProjectSystem(projectTargetFramework, new TestNuGetProjectContext()); var msBuildNuGetProject = new MSBuildNuGetProject(msBuildNuGetProjectSystem, packagesFolderPath, randomPackagesConfigPath); var webgreasePackageIdentity = new PackageIdentity("WebGrease", new NuGetVersion("1.6.0")); var resolutionContext = new ResolutionContext(DependencyBehavior.Lowest, includePrelease: true); var newtonsoftJsonPackageId = "newtonsoft.json"; // Act NuGetVersion latestNewtonsoftPrereleaseVersion = await NuGetPackageManager.GetLatestVersionAsync(newtonsoftJsonPackageId, resolutionContext, primarySourceRepository, CancellationToken.None); var newtonsoftJsonLatestPrereleasePackageIdentity = new PackageIdentity(newtonsoftJsonPackageId, latestNewtonsoftPrereleaseVersion); await nuGetPackageManager.InstallPackageAsync(msBuildNuGetProject, webgreasePackageIdentity, resolutionContext, new TestNuGetProjectContext(), primarySourceRepository, null, CancellationToken.None); // Assert // Check that the packages.config file exists after the installation Assert.True(File.Exists(randomPackagesConfigPath)); // Check the number of packages and packages returned by PackagesConfigProject after the installation var packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(3, packagesInPackagesConfig.Count); // Main Act - Update newtonsoft.json to latest pre-release await nuGetPackageManager.InstallPackageAsync(msBuildNuGetProject, newtonsoftJsonLatestPrereleasePackageIdentity, resolutionContext, new TestNuGetProjectContext(), primarySourceRepository, null, CancellationToken.None); }
public async Task TestPacManInstallPackageBindingRedirectsDisabledWithDeepDependency() { // Arrange var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider(); var testSolutionManager = new TestSolutionManager(); var testSettings = new NullSettings(); var token = CancellationToken.None; var nuGetPackageManager = new NuGetPackageManager(sourceRepositoryProvider, testSettings, testSolutionManager); var packagesFolderPath = PackagesFolderPathUtility.GetPackagesFolderPath(testSolutionManager, testSettings); var randomPackagesConfigFolderPath = TestFilesystemUtility.CreateRandomTestFolder(); var randomPackagesConfigPath = Path.Combine(randomPackagesConfigFolderPath, "packages.config"); var projectTargetFramework = NuGetFramework.Parse("net45"); var msBuildNuGetProjectSystem = new TestMSBuildNuGetProjectSystem(projectTargetFramework, new TestNuGetProjectContext()); var msBuildNuGetProject = new MSBuildNuGetProject(msBuildNuGetProjectSystem, packagesFolderPath, randomPackagesConfigPath); var packageIdentity = PackageWithDeepDependency[6]; // WindowsAzure.Storage.4.3.0 // Pre-Assert // Check that the packages.config file does not exist Assert.False(File.Exists(randomPackagesConfigPath)); // Check that there are no packages returned by PackagesConfigProject var packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(0, packagesInPackagesConfig.Count); Assert.Equal(0, msBuildNuGetProjectSystem.References.Count); // Act await nuGetPackageManager.InstallPackageAsync(msBuildNuGetProject, packageIdentity, new ResolutionContext(), new TestNuGetProjectContext() { BindingRedirectsDisabled = true }, sourceRepositoryProvider.GetRepositories().First(), null, token); // Assert // Check that the packages.config file exists after the installation Assert.True(File.Exists(randomPackagesConfigPath)); // Check the number of packages and packages returned by PackagesConfigProject after the installation packagesInPackagesConfig = (await msBuildNuGetProject.PackagesConfigNuGetProject.GetInstalledPackagesAsync(token)).ToList(); Assert.Equal(7, packagesInPackagesConfig.Count); Assert.Equal(0, msBuildNuGetProjectSystem.BindingRedirectsCallCount); }