示例#1
0
        public PackageDescription GetDescription(LockFilePackageLibrary package, LockFileTargetLibrary targetLibrary)
        {
            // If a NuGet dependency is supposed to provide assemblies but there is no assembly compatible with
            // current target framework, we should mark this dependency as unresolved
            var containsAssembly = package.Files
                .Any(x => x.StartsWith($"ref{Path.DirectorySeparatorChar}") ||
                    x.StartsWith($"lib{Path.DirectorySeparatorChar}"));

            var compatible = targetLibrary.FrameworkAssemblies.Any() ||
                targetLibrary.CompileTimeAssemblies.Any() ||
                targetLibrary.RuntimeAssemblies.Any() ||
                !containsAssembly;

            var dependencies = new List<LibraryRange>(targetLibrary.Dependencies.Count + targetLibrary.FrameworkAssemblies.Count);
            PopulateDependencies(dependencies, targetLibrary);

            var path = _packagePathResolver.GetInstallPath(package.Name, package.Version);

            var packageDescription = new PackageDescription(
                path,
                package,
                targetLibrary,
                dependencies,
                compatible);

            return packageDescription;
        }
 private PackageDescription CreateDescription(LockFileTargetLibrary target = null, LockFilePackageLibrary package = null)
 {
     return new PackageDescription(PackagePath,
         package ?? new LockFilePackageLibrary(),
         target ?? new LockFileTargetLibrary(),
         new List<LibraryRange>(), compatible: true, resolved: true);
 }
        public void GetDescriptionShouldNotModifyTarget()
        {
            var provider = new PackageDependencyProvider("/foo/packages", new FrameworkReferenceResolver("/foo/references"));
            var package = new LockFilePackageLibrary();
            package.Name = "Something";
            package.Version = NuGetVersion.Parse("1.0.0");
            package.Files.Add("lib/dotnet/_._");
            package.Files.Add("runtimes/any/native/Microsoft.CSharp.CurrentVersion.targets");

            var target = new LockFileTargetLibrary();
            target.Name = "Something";
            target.Version = package.Version;

            target.RuntimeAssemblies.Add("lib/dotnet/_._");
            target.CompileTimeAssemblies.Add("lib/dotnet/_._");
            target.NativeLibraries.Add("runtimes/any/native/Microsoft.CSharp.CurrentVersion.targets");

            var p1 = provider.GetDescription(NuGetFramework.Parse("netstandardapp1.5"), package, target);
            var p2 = provider.GetDescription(NuGetFramework.Parse("netstandardapp1.5"), package, target);

            Assert.True(p1.Compatible);
            Assert.True(p2.Compatible);

            Assert.Empty(p1.CompileTimeAssemblies);
            Assert.Empty(p1.RuntimeAssemblies);

            Assert.Empty(p2.CompileTimeAssemblies);
            Assert.Empty(p2.RuntimeAssemblies);
        }
示例#4
0
        public PackageDescription GetDescription(NuGetFramework targetFramework, LockFilePackageLibrary package, LockFileTargetLibrary targetLibrary)
        {
            // If a NuGet dependency is supposed to provide assemblies but there is no assembly compatible with
            // current target framework, we should mark this dependency as unresolved
            var containsAssembly = package.Files
                .Any(x => x.StartsWith($"ref{Path.DirectorySeparatorChar}") ||
                    x.StartsWith($"lib{Path.DirectorySeparatorChar}"));

            var compatible = targetLibrary.FrameworkAssemblies.Any() ||
                targetLibrary.CompileTimeAssemblies.Any() ||
                targetLibrary.RuntimeAssemblies.Any() ||
                !containsAssembly;

            var dependencies = new List<LibraryRange>(targetLibrary.Dependencies.Count + targetLibrary.FrameworkAssemblies.Count);
            PopulateDependencies(dependencies, targetLibrary, targetFramework);

            var path = _packagePathResolver.GetInstallPath(package.Name, package.Version);

            // Remove place holders
            targetLibrary.CompileTimeAssemblies = targetLibrary.CompileTimeAssemblies.Where(item => !IsPlaceholderFile(item.Path)).ToList();
            targetLibrary.RuntimeAssemblies = targetLibrary.RuntimeAssemblies.Where(item => !IsPlaceholderFile(item.Path)).ToList();

            // If the package's compile time assemblies is for a portable profile then, read the assembly metadata
            // and turn System.* references into reference assembly dependencies
            PopulateLegacyPortableDependencies(targetFramework, dependencies, path, targetLibrary);

            var packageDescription = new PackageDescription(
                path,
                package,
                targetLibrary,
                dependencies,
                compatible);

            return packageDescription;
        }
示例#5
0
        private string GetPackageDirectoryFullPath(LockFilePackageLibrary library, string nugetPackagesRoot)
        {
            var packageDirectory = new VersionFolderPathResolver(nugetPackagesRoot)
                .GetInstallPath(library.Name, library.Version);

            return packageDirectory;
        }
示例#6
0
        public CommandSpec CreateCommandSpecFromLibrary(
            LockFilePackageLibrary library,
            string commandName,
            IEnumerable<string> commandArguments,
            IEnumerable<string> allowedExtensions,
            string nugetPackagesRoot,
            CommandResolutionStrategy commandResolutionStrategy,
            string depsFilePath)
        {
            var packageDirectory = GetPackageDirectoryFullPath(library, nugetPackagesRoot);

            if (!Directory.Exists(packageDirectory))
            {
                return null;
            }

            var commandFile = GetCommandFileRelativePath(library, commandName, allowedExtensions);

            if (commandFile == null)
            {
                return null;
            }

            var commandPath = Path.Combine(packageDirectory, commandFile);

            return CreateCommandSpecWrappingWithCorehostfDll(
                commandPath, 
                commandArguments, 
                depsFilePath, 
                commandResolutionStrategy);
        }
        public void HasCompileTimePlaceholderChecksAllCompileTimeAssets()
        {
            var provider = new PackageDependencyProvider("/foo/packages", new FrameworkReferenceResolver("/foo/references"));
            var package = new LockFilePackageLibrary();
            package.Name = "Something";
            package.Version = NuGetVersion.Parse("1.0.0");
            package.Files.Add("lib/net46/_._");
            package.Files.Add("lib/net46/Something.dll");

            var target = new LockFileTargetLibrary();
            target.Name = "Something";
            target.Version = package.Version;

            target.RuntimeAssemblies.Add("lib/net46/_._");
            target.RuntimeAssemblies.Add("lib/net46/Something.dll");
            target.CompileTimeAssemblies.Add("lib/net46/_._");
            target.CompileTimeAssemblies.Add("lib/net46/Something.dll");

            var p1 = provider.GetDescription(NuGetFramework.Parse("net46"), package, target);
            
            Assert.False(p1.HasCompileTimePlaceholder);
            Assert.Equal(1, p1.CompileTimeAssemblies.Count());
            Assert.Equal(1, p1.RuntimeAssemblies.Count());
            Assert.Equal("lib/net46/Something.dll", p1.CompileTimeAssemblies.First().Path);
            Assert.Equal("lib/net46/Something.dll", p1.RuntimeAssemblies.First().Path);
        }
示例#8
0
 private string GetCommandFileRelativePath(
     LockFilePackageLibrary library, 
     string commandName, 
     IEnumerable<string> allowedExtensions)
 {
     // TODO: Should command names be case sensitive?
     return library.Files
             .Where(f => Path.GetFileNameWithoutExtension(f) == commandName)
             .Where(e => allowedExtensions.Contains(Path.GetExtension(e)))
             .FirstOrDefault();
 }
示例#9
0
 public PackageDescription(
     string path,
     LockFilePackageLibrary package,
     LockFileTargetLibrary lockFileLibrary,
     IEnumerable<LibraryRange> dependencies,
     bool compatible)
     : base(new LibraryIdentity(package.Name, package.Version, LibraryType.Package),
           "sha512-" + package.Sha512,
           path,
           dependencies: dependencies,
           framework: null,
           resolved: compatible,
           compatible: compatible)
 {
     Library = package;
     Target = lockFileLibrary;
 }
        public void HasCompileTimePlaceholderReturnsFalseIfEmpty()
        {
            var provider = new PackageDependencyProvider("/foo/packages", new FrameworkReferenceResolver("/foo/references"));
            var package = new LockFilePackageLibrary();
            package.Name = "Something";
            package.Version = NuGetVersion.Parse("1.0.0");

            var target = new LockFileTargetLibrary();
            target.Name = "Something";
            target.Version = package.Version;

            var p1 = provider.GetDescription(NuGetFramework.Parse("net46"), package, target);
            
            Assert.False(p1.HasCompileTimePlaceholder);
            Assert.Equal(0, p1.CompileTimeAssemblies.Count());
            Assert.Equal(0, p1.RuntimeAssemblies.Count());
        }
 private CommandSpec ResolveFromDependencyLibrary(
     LockFilePackageLibrary dependencyLibrary,
     string depsFilePath,
     string commandName,
     IEnumerable<string> allowedExtensions,
     IEnumerable<string> commandArguments,
     ProjectContext projectContext)
 {
     return _packagedCommandSpecFactory.CreateCommandSpecFromLibrary(
                 dependencyLibrary,
                 commandName,
                 commandArguments,
                 allowedExtensions,
                 projectContext.PackagesDirectory,
                 s_commandResolutionStrategy,
                 depsFilePath);
 }