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


C# PackageReferenceFile.GetPackageReferences方法代码示例

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


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

示例1: ExecuteCommand

        public override void ExecuteCommand()
        {
            if (string.IsNullOrEmpty(Directory))
            {
                Directory = Environment.CurrentDirectory;
            }

            if (_repository == null)
            {
                _repository = AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(RepositoryFactory, SourceProvider, Source);
            }

            var packageFiles = _fileSystem.GetFiles(Directory, "packages.config", true).ToList();
            Console.WriteLine("Processing : {0} files.",packageFiles.Count);
            Parallel.ForEach(packageFiles, packageFile =>
                {
                    Console.WriteLine("\t{0}", packageFile);
                    var newReferences = new List<PackageReference>();
                    var packageFileDetails = new PackageReferenceFile(_fileSystem, packageFile);
                    foreach (var packageReference in packageFileDetails.GetPackageReferences())
                    {
                        Console.WriteLine("\t\t{0}",packageReference.ToString());
                        var exists = _repository.FindPackage(packageReference.Id, packageReference.Version);
                        if (exists != null)
                        {
                            Console.WriteLine("\t\t\tExists, not changing.");
                            newReferences.Add(packageReference);
                        }
                        else
                        {
                            var package = _repository.FindPackagesById(packageReference.Id).FirstOrDefault();
                            if (package == null)
                            {
                                Console.WriteLine("\t\t\tNot found, no change.");
                                newReferences.Add(packageReference);
                            }
                            else
                            {
                                var newReference = new PackageReference(package.Id, package.Version, new VersionSpec(), new FrameworkName(".NET Framework, Version=4.0"), false);
                                Console.WriteLine("\t\t\tUpdated to {0}", newReference.ToString());
                                newReferences.Add(newReference);
                            }
                        }
                    }

                    //TODO Clear the file (must be an easier way).
                    Console.WriteLine("Clearing existing file...");
                    foreach (var packageReference in packageFileDetails.GetPackageReferences())
                    {
                        packageFileDetails.DeleteEntry(packageReference.Id, packageReference.Version);
                    }

                    //Add the new references.
                    Console.WriteLine("Adding new references...");
                    foreach (var packageReference in newReferences)
                    {
                        packageFileDetails.AddEntry(packageReference.Id, packageReference.Version);
                    }
                });
        }
开发者ID:modulexcite,项目名称:NuGet.Extensions,代码行数:60,代码来源:FixReferences.cs

示例2: OutputPackageConfigFile

        /// <summary>
        /// Outputs a package.config file reflecting the set of packages that provides the requested set of assemblies.
        /// </summary>
        public void OutputPackageConfigFile()
        {
            var packagesConfig = Constants.PackageReferenceFile;
            if (_fileSystem.FileExists(packagesConfig))
                _fileSystem.DeleteFile(packagesConfig);

            if (!_fileSystem.FileExists(packagesConfig))
            {
                var prf = new PackageReferenceFile(_fileSystem, string.Format(".\\{0}", packagesConfig));
                foreach (var assemblyToPackageMapping in ResolvedMappings)
                {
                    IPackage smallestPackage;
                    if (assemblyToPackageMapping.Value.Count > 1)
                    {
                        smallestPackage = assemblyToPackageMapping.Value.OrderBy(l => l.GetFiles().Count()).FirstOrDefault();
                        _console.WriteLine(String.Format("{0} : Choosing {1} from {2} choices.", assemblyToPackageMapping.Key, smallestPackage.Id, assemblyToPackageMapping.Value.Count()));
                    }
                    else
                    {
                        smallestPackage = assemblyToPackageMapping.Value.First();
                    }
                    //Only add if we do not have another instance of the ID, not the id/version combo....
                    if (!prf.GetPackageReferences().Any(p => p.Id == smallestPackage.Id))
                        prf.AddEntry(smallestPackage.Id, smallestPackage.Version);
                }
            }
            else
            {
                _console.WriteError("Please move the existing packages.config file....");
            }
        }
开发者ID:GrahamTheCoder,项目名称:NuGet.Extensions,代码行数:34,代码来源:AssemblyToPackageMapping.cs

示例3: GetPackageReferences

		IEnumerable<PackageReference> GetPackageReferences ()
		{
			if (project.HasPackages ()) {
				var packageReferenceFile = new PackageReferenceFile (project.GetPackagesConfigFilePath ());
				return packageReferenceFile.GetPackageReferences ();
			}
			return new PackageReference [0];
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:8,代码来源:ProjectPackagesFolderNode.cs

示例4: GetPackageReferencesThrowsIfVersionSpecIsInvalid

        public void GetPackageReferencesThrowsIfVersionSpecIsInvalid()
        {
            // Arrange
            var config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""A"" version=""1.3.4"" allowedVersions=""1.23.4$-2.0"" />
</packages>";
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("packages.config", config);
            var packageReferenceFile = new PackageReferenceFile(fileSystem, "packages.config");

            // Act
            var values = packageReferenceFile.GetPackageReferences();

            // Assert
            ExceptionAssert.Throws<InvalidDataException>(() => values.ToList(), "Unable to parse version value '1.23.4$-2.0' from 'packages.config'.");
        }
开发者ID:monoman,项目名称:NugetCracker,代码行数:17,代码来源:PackageReferenceFileTest.cs

示例5: GetPackageReferencesThrowsIfVersionIsInvalid

        public void GetPackageReferencesThrowsIfVersionIsInvalid(string version)
        {
            // Arrange
            var config = String.Format(CultureInfo.InvariantCulture, @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""A"" version=""{0}"" />
</packages>", version);
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("packages.config", config);
            var packageReferenceFile = new PackageReferenceFile(fileSystem, "packages.config");

            // Act
            var values = packageReferenceFile.GetPackageReferences();

            // Assert
            ExceptionAssert.Throws<InvalidDataException>(() => values.ToList(), "Unable to parse version value '" + version + "' from 'packages.config'.");
        }
开发者ID:monoman,项目名称:NugetCracker,代码行数:17,代码来源:PackageReferenceFileTest.cs

示例6: RestorePackages

        public void RestorePackages(Project project)
        {
            string packageReferenceFileFullPath;
            Tuple<string, string> packageReferenceFiles = VsUtility.GetPackageReferenceFileFullPaths(project);
            if (File.Exists(packageReferenceFiles.Item1))
            {
                packageReferenceFileFullPath = packageReferenceFiles.Item1;
            }
            else if (File.Exists(packageReferenceFiles.Item2))
            {
                packageReferenceFileFullPath = packageReferenceFiles.Item2;
            }
            else
            {
                return;
            }

            var packageReferenceFile = new PackageReferenceFile(packageReferenceFileFullPath);
            var packages = packageReferenceFile.GetPackageReferences().ToList();
            if (packages.Count == 0)
            {
                return;
            }

            var repoSettings = ServiceLocator.GetInstance<IRepositorySettings>();
            var fileSystem = new PhysicalFileSystem(repoSettings.RepositoryPath);
            var activePackageSourceRepository = ServiceLocator.GetInstance<IPackageRepository>();
            var repository = new PriorityPackageRepository(NuGet.MachineCache.Default, activePackageSourceRepository);
            IVsPackageManagerFactory packageManagerFactory = ServiceLocator.GetInstance<IVsPackageManagerFactory>();
            var packageManager = packageManagerFactory.CreatePackageManager(repository, useFallbackForDependencies: false);

            foreach (var package in packages)
            {
                if (IsPackageInstalled(fileSystem, package.Id, package.Version))
                {
                    continue;
                }

                using (packageManager.SourceRepository.StartOperation(RepositoryOperationNames.Restore, package.Id, package.Version.ToString()))
                {
                    var resolvedPackage = PackageHelper.ResolvePackage(
                        packageManager.SourceRepository, package.Id, package.Version);
                    NuGet.Common.PackageExtractor.InstallPackage(packageManager, resolvedPackage);
                }
            }
        }
开发者ID:Newtopian,项目名称:nuget,代码行数:46,代码来源:VsPackageRestorer.cs

示例7: GetPackageReferencesThrowsIfVersionIsNotPresent

        public void GetPackageReferencesThrowsIfVersionIsNotPresent()
        {
            // Arrange
            var config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""A"" version="""" />
</packages>";
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("packages.config", config);
            var packageReferenceFile = new PackageReferenceFile(fileSystem, "packages.config");

            // Act
            var values = packageReferenceFile.GetPackageReferences();

            // Assert
            Assert.Empty(values);
        }
开发者ID:themotleyfool,项目名称:NuGet,代码行数:17,代码来源:PackageReferenceFileTest.cs

示例8: ExecuteCommand

        /// <summary>
        /// Executes the command.
        /// </summary>
        public override void ExecuteCommand()
        {
            string inputPackagesConfigPath = GetLatestPackagesConfigPath();
            string outputPackagesConfigPath = GetPackagesConfigPath();

            if (String.IsNullOrEmpty(inputPackagesConfigPath) || String.IsNullOrEmpty(outputPackagesConfigPath))
            {
                throw new CommandLineException();
            }

            if (!File.Exists(inputPackagesConfigPath))
            {
                throw new CommandLineException();
            }

            TryCreateAllDirectories(Path.GetDirectoryName(outputPackagesConfigPath));
            if(!File.Exists(outputPackagesConfigPath))
            {
                File.WriteAllText(outputPackagesConfigPath, @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
</packages>");
            }

            PhysicalFileSystem outputFileSystem = new PhysicalFileSystem(Path.GetDirectoryName(outputPackagesConfigPath));
            PackageReferenceFile outputFile = new PackageReferenceFile(outputFileSystem, Path.GetFileName(outputPackagesConfigPath));

            // Remove all existing references from output file
            Dictionary<string, SemanticVersion> existingReferences = new Dictionary<string,SemanticVersion>();
            foreach (PackageReference packageReference in outputFile.GetPackageReferences())
            {
                existingReferences.Add(packageReference.Id, packageReference.Version);
            }
            foreach (KeyValuePair<string, SemanticVersion> pair in existingReferences)
            {
                outputFile.DeleteEntry(pair.Key, pair.Value);
            }

            PhysicalFileSystem inputFileSystem = new PhysicalFileSystem(Path.GetDirectoryName(inputPackagesConfigPath));
            PackageReferenceFile inputFile = new PackageReferenceFile(inputFileSystem, Path.GetFileName(inputPackagesConfigPath));
            foreach (PackageReference packageReference in inputFile.GetPackageReferences())
            {
                IPackage package = GetLatestPackage(packageReference.Id);
                outputFile.AddEntry(packageReference.Id, package.Version, false, packageReference.TargetFramework);
            }
        }
开发者ID:bluebirdtech,项目名称:NuGet.LatestPackagesExtension,代码行数:48,代码来源:UpdateLatest.cs

示例9: CheckProjectPackages

		public void CheckProjectPackages (IDotNetProject project)
		{
			IPackageManagementProject packageManagementProject = solution.GetProject (registeredRepositories.ActiveRepository, project);

			packageReferenceFile = CreatePackageReferenceFile (project.GetPackagesConfigFilePath ());
			packageReferences = packageReferenceFile.GetPackageReferences ().ToList ();

			compatibilityReport = new ProjectPackagesCompatibilityReport (packageManagementProject.TargetFramework);

			foreach (PackageReference packageReference in packageReferences) {
				IPackage package = packageManagementProject.FindPackage (packageReference.Id);
				if (package != null) {
					if (PackageNeedsReinstall (project, package, packageReference.TargetFramework)) {
						packagesRequiringReinstallation.Add (package);
					}
				}
			}
		}
开发者ID:brantwedel,项目名称:monodevelop,代码行数:18,代码来源:PackageCompatibilityChecker.cs

示例10: GetPackageReturnsReferencesWithEmptyVersionsWhenRequiredVersionIsFalse

        public void GetPackageReturnsReferencesWithEmptyVersionsWhenRequiredVersionIsFalse()
        {
            // Arrange
            var config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""A"" version="""" />
</packages>";
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("packages.config", config);
            var packageReferenceFile = new PackageReferenceFile(fileSystem, "packages.config");

            // Act
            var values = packageReferenceFile.GetPackageReferences(requireVersion: false);

            // Assert
            Assert.Equal(1, values.Count());
            Assert.Equal("A", values.First().Id);
            Assert.Null(values.First().Version);
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:19,代码来源:PackageReferenceFileTest.cs

示例11: GetPackageReferencesNormalizeProjectName

        public void GetPackageReferencesNormalizeProjectName()
        {
            // Arrange
            var config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""luan"" version=""1.0"" />
</packages>";

            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("packages.config", config);
            fileSystem.AddFile("packages.project_with_space.config", config);
            var packageReferenceFile = new PackageReferenceFile(fileSystem, "packages.config", "project with space");

            // Act
            var values = packageReferenceFile.GetPackageReferences().ToArray();

            // Assert
            Assert.Equal(1, values.Length);
            Assert.Equal("luan", values[0].Id);
        }
开发者ID:Newtopian,项目名称:nuget,代码行数:20,代码来源:PackageReferenceFileTest.cs

示例12: GetPackageReferencesReadFromProjectConfigFileIfPresent

        public void GetPackageReferencesReadFromProjectConfigFileIfPresent()
        {
            // Arrange
            var config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""luan"" version=""1.0"" />
</packages>";

            var projectConfig = @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""an"" version=""1.0"" />
</packages>";
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("packages.config", config);
            fileSystem.AddFile("packages.project.config", projectConfig);
            var packageReferenceFile = new PackageReferenceFile(fileSystem, "packages.config", "project");

            // Act
            var values = packageReferenceFile.GetPackageReferences().ToArray();

            // Assert
            Assert.Equal(1, values.Length);
            Assert.Equal("an", values[0].Id);
        }
开发者ID:Newtopian,项目名称:nuget,代码行数:24,代码来源:PackageReferenceFileTest.cs

示例13: GetPackageReferencesParseTargetFrameworkCorrectly

        public void GetPackageReferencesParseTargetFrameworkCorrectly()
        {
            // Arrange
            var config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""A"" version=""1.0"" targetFramework=""sl4"" />
  <package id=""B"" version=""1.0"" targetFramework=""net35-client"" />
  <package id=""C"" version=""1.0"" targetFramework=""winrt45"" />
  <package id=""D"" version=""1.0"" />
</packages>";
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("packages.config", config);
            var packageReferenceFile = new PackageReferenceFile(fileSystem, "packages.config");

            // Act
            var values = packageReferenceFile.GetPackageReferences().ToList();

            // Assert
            Assert.Equal(4, values.Count);
            Assert.Equal(new FrameworkName("Silverlight, Version=4.0"), values[0].TargetFramework);
            Assert.Equal(new FrameworkName(".NETFramework, Version=3.5, Profile=Client"), values[1].TargetFramework);
            Assert.Equal(new FrameworkName(".NETCore, Version=4.5"), values[2].TargetFramework);
            Assert.Null(values[3].TargetFramework);
        }
开发者ID:themotleyfool,项目名称:NuGet,代码行数:24,代码来源:PackageReferenceFileTest.cs

示例14: FinishPackageRestore

        public static void FinishPackageRestore()
        {
            if (!_isRestoring)
                return;

            foreach (var project in DTE.Solution.Projects.OfType<Project>().Where(n => n.IsSupported()))
            {
                var packageReferenceFile = new PackageReferenceFile(project.GetDirectory() + "/coapp.packages.config");

                var packageReferences = packageReferenceFile.GetPackageReferences();

                foreach (var packageReference in packageReferences)
                {
                    var removedLibraries = new List<LibraryReference>();
                    var addedLibraries = new List<LibraryReference>();

                    foreach (var lib in packageReference.Libraries)
                    {
                        removedLibraries.Add(new LibraryReference(lib.Name, project.GetName(), lib.ConfigurationName, false));
                        addedLibraries.Add(new LibraryReference(lib.Name, project.GetName(), lib.ConfigurationName, lib.IsChecked));
                    }

                    ManagePackage(packageReference, new[] { project }, removedLibraries);
                    ManagePackage(packageReference, new[] { project }, addedLibraries);
                }
            }
        }
开发者ID:henjuv,项目名称:coapp-vse,代码行数:27,代码来源:Module.cs

示例15: MarkEntryForReinstallationMarksPackagesProperly

        public void MarkEntryForReinstallationMarksPackagesProperly()
        {
            // Arrange
            var config = @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""A"" version=""1.0"" targetFramework=""net45""/>
  <package id=""B"" version=""1.0"" targetFramework=""net45""/>
</packages>";

            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("packages.config", config);
            var packageReferenceFile = new PackageReferenceFile(fileSystem, "packages.config");

            // Act
            packageReferenceFile.MarkEntryForReinstallation("A", new SemanticVersion("1.0"), new FrameworkName(".NETFramework, Version=4.5"), true);
            var packageReferences = packageReferenceFile.GetPackageReferences().ToList();

            // Assert
            Assert.Equal(2, packageReferences.Count);
            Assert.True(packageReferences[0].RequireReinstallation);
            Assert.False(packageReferences[1].RequireReinstallation);
        }
开发者ID:Newtopian,项目名称:nuget,代码行数:22,代码来源:PackageReferenceFileTest.cs


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