public void CanFindAssemblyInSinglePackage(int numberOfRepeatedAssemblies) { var fileList = new List<string>() { AssemblyCommonDll }; var packages = new List<IPackage> { PackageUtility.CreatePackage(AssemblyCommon, "1.0",assemblyReferences: fileList) }; var assemblies = Enumerable.Repeat(AssemblyCommonDll, numberOfRepeatedAssemblies).ToList(); var assemblyResolver = new RepositoryAssemblyResolver(assemblies, packages.AsQueryable(), new Mock<MockFileSystem>().Object, new Mock<IConsole>().Object); var resolved = assemblyResolver.GetAssemblyToPackageMapping(false).ResolvedMappings; Assert.AreEqual(1, resolved[AssemblyCommonDll].Count); }
public void CanFindSingleAssemblyInSinglePackage() { var fileList = new List<string>() { "Assembly.Common.dll" }; var packages = new List<IPackage> { PackageUtility.CreatePackage("Assembly.Common", "1.0",assemblyReferences: fileList) }; var assemblies = new List<string>() { "Assembly.Common.dll" }; var assemblyResolver = new RepositoryAssemblyResolver(assemblies, packages.AsQueryable(), new Mock<MockFileSystem>().Object, new Mock<IConsole>().Object); var resolved = assemblyResolver.ResolveAssemblies(false); Assert.AreEqual(1, resolved["Assembly.Common.dll"].Count); }
public void CanFindMultipleAssembliesInSinglePackage() { var fileList = new List<string>() { AssemblyCommonDll, AssemblyDataDll }; var packages = new List<IPackage> { PackageUtility.CreatePackage(AssemblyCommon, "1.2", assemblyReferences: fileList, isLatest: true), }; var assemblies = new List<string>() { AssemblyCommonDll, AssemblyDataDll }; var assemblyResolver = new RepositoryAssemblyResolver(assemblies, packages.AsQueryable(), new Mock<MockFileSystem>().Object, new Mock<IConsole>().Object); var resolved = assemblyResolver.GetAssemblyToPackageMapping(true).ResolvedMappings; Assert.AreEqual(1, resolved[AssemblyCommonDll].Count); Assert.AreEqual(1, resolved[AssemblyDataDll].Count); }
public void NonExhaustiveSearchStopsAfterResolvingOnePackagePerAssembly() { var willThrowErrorIfManipulatedAsPath = new List<string>() { "c:\\temp c:\\windows" }; var packages = new List<IPackage> { PackageUtility.CreatePackage("Assembly.Common", "1.2", assemblyReferences: new[]{AssemblyCommonDll}, isLatest: true), PackageUtility.CreatePackage("Assembly.Data", "1.1", assemblyReferences: new[]{AssemblyDataDll}, isLatest: false), PackageUtility.CreatePackage("Assembly.Common", "1.0", assemblyReferences: willThrowErrorIfManipulatedAsPath, isLatest: false) }; var assemblies = new List<string>() { AssemblyCommonDll, AssemblyDataDll }; var assemblyResolver = new RepositoryAssemblyResolver(assemblies, packages.AsQueryable(), new Mock<MockFileSystem>().Object, new Mock<IConsole>().Object); var resolved = assemblyResolver.GetAssemblyToPackageMapping(false).ResolvedMappings; Assert.AreEqual(1, resolved[AssemblyCommonDll].Count); Assert.AreEqual(1, resolved[AssemblyDataDll].Count); }
public void CanFindMultipleAssembliesInMultiplePackagesExhaustively() { var fileList = new List<string>() { "Assembly.Common.dll", "Assembly.Data.dll" }; var packages = new List<IPackage> { PackageUtility.CreatePackage("Assembly.Common", "1.2", assemblyReferences: fileList, isLatest: true), PackageUtility.CreatePackage("Assembly.Common", "1.1", assemblyReferences: fileList, isLatest: false), PackageUtility.CreatePackage("Assembly.Common", "1.0", assemblyReferences: fileList, isLatest: false), PackageUtility.CreatePackage("Assembly.Data", "1.0", assemblyReferences: new List<string>() { "Assembly.Data.dll" }, isLatest: true) }; var assemblies = new List<string>() { "Assembly.Common.dll", "Assembly.Data.dll" }; var assemblyResolver = new RepositoryAssemblyResolver(assemblies, packages.AsQueryable(), new Mock<MockFileSystem>().Object, new Mock<IConsole>().Object); var resolved = assemblyResolver.ResolveAssemblies(true); Assert.AreEqual(3, resolved["Assembly.Common.dll"].Count); Assert.AreEqual(4, resolved["Assembly.Data.dll"].Count); }
public override void ExecuteCommand() { if (string.IsNullOrEmpty(Arguments[0])) return; var assemblies = new List<string>(); if (!Arguments[0].EndsWith(".dll")) { _fileSystem = CreateFileSystem(Directory.GetCurrentDirectory()); assemblies.AddRange(GetAssemblyListFromDirectory()); } else { assemblies.Add(Arguments[0]); } var sw = new Stopwatch(); sw.Start(); var repository = GetRepository(); var packageSource = GetPackageList(repository); _resolver = new RepositoryAssemblyResolver(assemblies, packageSource, _fileSystem, Console); var assemblyToPackageMapping = _resolver.GetAssemblyToPackageMapping(Exhaustive); Console.WriteLine(); sw.Stop(); if (!OutputPackageConfig) { OutputResultsToConsole(sw, assemblyToPackageMapping.ResolvedMappings); OutputErrors(assemblyToPackageMapping.FailedMappings); } else { assemblyToPackageMapping.OutputPackageConfigFile(); OutputErrors(assemblyToPackageMapping.FailedMappings); } Environment.Exit(0); }
public void WillChoosePackageWithSmallestNumberOfAssembliesFromMultipleMatches() { var packages = new List<IPackage> { PackageUtility.CreatePackage(AssemblyCommon, "1.0", assemblyReferences: new List<string>() { AssemblyCommonDll }), PackageUtility.CreatePackage("Assembly.Other", "1.0", assemblyReferences: new List<string>() { AssemblyCommonDll, "Assembly.Other.dll" }) }; var assemblies = new List<string>() { AssemblyCommonDll }; var filesystem = new MockFileSystem(); var assemblyResolver = new RepositoryAssemblyResolver(assemblies, packages.AsQueryable(), filesystem, new Mock<IConsole>().Object); var resolved = assemblyResolver.GetAssemblyToPackageMapping(false); resolved.OutputPackageConfigFile(); Assert.AreEqual(1, filesystem.Paths.Count); var file = new PackageReferenceFile(filesystem, string.Concat(filesystem.Root, ".\\packages.config")); Assert.AreEqual(1, file.GetPackageReferences().Count()); Assert.AreEqual(true, file.EntryExists(AssemblyCommon,SemanticVersion.Parse("1.0"))); }
public void CanOutputPackageConfigWithSingleEntry() { var fileList = new List<string>() { AssemblyCommonDll }; var packages = new List<IPackage> { PackageUtility.CreatePackage(AssemblyCommon, "1.0", assemblyReferences: fileList) }; var assemblies = new List<string>() { AssemblyCommonDll }; var filesystem = new MockFileSystem(); //filesystem.Root = @"c:\test"; var assemblyResolver = new RepositoryAssemblyResolver(assemblies, packages.AsQueryable(), filesystem, new Mock<IConsole>().Object); var resolved = assemblyResolver.GetAssemblyToPackageMapping(false); resolved.OutputPackageConfigFile(); Assert.AreEqual(1,filesystem.Paths.Count); var file = new PackageReferenceFile(filesystem, string.Concat(filesystem.Root, ".\\packages.config")); Assert.AreEqual(1, file.GetPackageReferences().Count()); }
private IEnumerable<KeyValuePair<string, List<IPackage>>> ResolveReferenceMappings(IEnumerable<IReference> references) { var referenceList = GetReferencedAssemblies(references); if (referenceList.Any()) { _console.WriteLine("Checking feed for {0} references...", referenceList.Count); IQueryable<IPackage> packageSource = _packageRepository.GetPackages(); var assemblyResolver = new RepositoryAssemblyResolver(referenceList, packageSource, _projectFileSystem, _console); var referenceMappings = assemblyResolver.GetAssemblyToPackageMapping(false); referenceMappings.OutputPackageConfigFile(); //next, lets rewrite the project file with the mappings to the new location... //Going to have to use the mapping to assembly name that we get back from the resolve above _console.WriteLine(); _console.WriteLine("Found {0} package to assembly mappings on feed...", referenceMappings.ResolvedMappings.Count()); referenceMappings.FailedMappings.ToList().ForEach(f => _console.WriteLine("Could not match: {0}", f)); return referenceMappings.ResolvedMappings; } _console.WriteLine("No references found to resolve (all GAC?)"); return Enumerable.Empty<KeyValuePair<string, List<IPackage>>>(); }
private Dictionary<string, List<IPackage>> ResolveAssembliesToPackagesConfigFile(FileInfo projectFileInfo, List<string> referenceFiles) { var results = new Dictionary<string, List<IPackage>>(); if (referenceFiles.Any()) { Console.WriteLine("Checking feed for {0} references...", referenceFiles.Count); IQueryable<IPackage> packageSource = GetRepository().GetPackages().OrderBy(p => p.Id); var assemblyResolver = new RepositoryAssemblyResolver(referenceFiles, packageSource, new PhysicalFileSystem(projectFileInfo.Directory.ToString()), Console); results = assemblyResolver.ResolveAssemblies(false); assemblyResolver.OutputPackageConfigFile(); } else { Console.WriteWarning("No references found to resolve (all GAC?)"); } return results; }