本文整理汇总了C#中PackageReferenceFile类的典型用法代码示例。如果您正苦于以下问题:C# PackageReferenceFile类的具体用法?C# PackageReferenceFile怎么用?C# PackageReferenceFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PackageReferenceFile类属于命名空间,在下文中一共展示了PackageReferenceFile类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: 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
示例2: 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
示例3: OutputPackageConfigFile
/// <summary>
/// Outputs a package.config file reflecting the set of packages that provides the requested set of assemblies.
/// </summary>
public void OutputPackageConfigFile()
{
if (fileSystem.FileExists("packages.config"))
fileSystem.DeleteFile("packages.config");
if (!fileSystem.FileExists("packages.config"))
{
var prf = new PackageReferenceFile(fileSystem,".\\packages.config");
foreach (var assemblyToPackageMapping in resolvedAssemblies)
{
if (assemblyToPackageMapping.Value.Count() > 0)
{
IPackage smallestPackage;
if (assemblyToPackageMapping.Value.Count > 1)
{
smallestPackage = assemblyToPackageMapping.Value.OrderBy(l => l.GetFiles().Count()).FirstOrDefault();
Console.WriteLine(String.Format("{0} : Choosing : {1} - {2} to choose from.", 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:kl4w,项目名称:NuGet.Extensions,代码行数:36,代码来源:RepositoryAssemblyResolver.cs
示例4: 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
示例5: CreatePackageConfigs
private static void CreatePackageConfigs(IFileSystem fs, out PackageReferenceFile f1, out PackageReferenceFile f2)
{
f1 = (new PackageReferenceFile(fs, @"c:\test1\packages.config"));
f1.AddEntry("Test", SemanticVersion.Parse("1.0.0.0"));
f1.AddEntry("Test", SemanticVersion.Parse("1.1.0.0"));
f1.AddEntry("Test", SemanticVersion.Parse("1.2.0.0"));
f2 = (new PackageReferenceFile(fs, @"c:\test2\packages.config"));
f2.AddEntry("Test", SemanticVersion.Parse("1.0.0.0"));
f2.AddEntry("Test", SemanticVersion.Parse("1.1.0.0"));
f2.AddEntry("Test", SemanticVersion.Parse("1.2.0.0"));
}
开发者ID:modulexcite,项目名称:NuGet.Extras,代码行数:12,代码来源:PackageEnumeratorTests.cs
示例6: CreatePackagesConfig
private void CreatePackagesConfig(ICollection<IPackage> packagesToAdd, FrameworkName targetFramework = null)
{
_console.WriteLine("Creating {0}", PackageReferenceFilename);
var packagesConfig = new PackageReferenceFile(_projectFileSystem, PackageReferenceFilename);
foreach (var package in packagesToAdd)
{
if (!packagesConfig.EntryExists(package.Id, package.Version)) //Note we don't re-add entries that have the wrong targetFramework set
{
packagesConfig.AddEntry(package.Id, package.Version, false, targetFramework);
}
}
}
开发者ID:GrahamTheCoder,项目名称:NuGet.Extensions,代码行数:12,代码来源:ProjectNugetifier.cs
示例7: ConstructorNormalizeProjectName
public void ConstructorNormalizeProjectName()
{
// Arrange
var fileSystem = new MockFileSystem("x:\\");
fileSystem.AddFile("packages.project_with_space.config", "");
// Act
var packageReferenceFile = new PackageReferenceFile(
fileSystem, "packages.config", "project with space");
// Assert
Assert.Equal("x:\\packages.project_with_space.config", packageReferenceFile.FullPath);
}
开发者ID:Newtopian,项目名称:nuget,代码行数:13,代码来源:PackageReferenceFileTest.cs
示例8: ReferenceToPackageIdNotOnFeedStays
public void ReferenceToPackageIdNotOnFeedStays()
{
var fileSystem = new MockFileSystem(@"d:\");
fileSystem.AddFile(@"d:\test\packages.config",
"<packages>" +
"<package id=\"Missing\" version=\"1.0.0.0\" />" +
"</packages>");
var repository = new MockPackageRepository("http://test.com");
var command = new FixReferences(fileSystem, repository, new Console()) { Directory = @"d:\test" };
command.Execute();
var packageReferences = new PackageReferenceFile(fileSystem, @"d:\test\packages.config").GetPackageReferences().ToList();
Assert.AreEqual("1.0.0.0", packageReferences.First(p => p.Id == "Missing").Version.Version.ToString());
}
开发者ID:modulexcite,项目名称:NuGet.Extensions,代码行数:16,代码来源:FixReferencesTests.cs
示例9: 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
示例10: 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
示例11: 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
示例12: TestablePackageCompatibilityRunner
public TestablePackageCompatibilityRunner (
IDotNetProject project,
IPackageManagementSolution solution,
IRegisteredPackageRepositories registeredRepositories,
IPackageManagementProgressMonitorFactory progressMonitorFactory,
IPackageManagementEvents packageManagementEvents,
IProgressProvider progressProvider)
: base (
project,
solution,
registeredRepositories,
progressMonitorFactory,
packageManagementEvents,
progressProvider)
{
PackageReferenceFile = new PackageReferenceFile (FileSystem, "packages.config");
}
开发者ID:brantwedel,项目名称:monodevelop,代码行数:17,代码来源:TestablePackageCompatibilityRunner.cs
示例13: 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
示例14: 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
示例15: 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
示例16: 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
示例17: 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
示例18: CanDetectMissingVersionAndUpdateToValid
public void CanDetectMissingVersionAndUpdateToValid()
{
var fileSystem = new MockFileSystem(@"d:\");
fileSystem.AddFile(@"d:\test\packages.config",
"<packages>" +
"<package id=\"Test\" version=\"1.0.0.0\" />" +
"<package id=\"Other\" version=\"1.0.0.0\" />" +
"</packages>");
var repository = new MockPackageRepository("http://test.com");
repository.AddPackage(PackageUtility.CreatePackage("Test", "2.0.0.0"));
repository.AddPackage(PackageUtility.CreatePackage("Other", "1.0.0.0"));
var command = new FixReferences(fileSystem, repository, new Console()) {Directory = @"d:\test"};
command.Execute();
var packageReferences = new PackageReferenceFile(fileSystem, @"d:\test\packages.config").GetPackageReferences().ToList();
Assert.AreEqual("2.0.0.0", packageReferences.First(p => p.Id == "Test").Version.Version.ToString());
Assert.AreEqual("1.0.0.0", packageReferences.First(p => p.Id == "Other").Version.Version.ToString());
}
开发者ID:modulexcite,项目名称:NuGet.Extensions,代码行数:20,代码来源:FixReferencesTests.cs
示例19: 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
示例20: 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
注:本文中的PackageReferenceFile类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论