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);
        }
        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);
        }
        public CommandSpec CreateCommandSpecFromLibrary(
            LockFileTargetLibrary toolLibrary,
            string commandName,
            IEnumerable<string> commandArguments,
            IEnumerable<string> allowedExtensions,
            string nugetPackagesRoot,
            CommandResolutionStrategy commandResolutionStrategy,
            string depsFilePath)
        {

            var toolAssembly = toolLibrary?.RuntimeAssemblies
                    .FirstOrDefault(r => Path.GetFileNameWithoutExtension(r.Path) == commandName);

            if (toolAssembly == null)
            {
                return null;
            }
            
            var commandPath = GetCommandFilePath(nugetPackagesRoot, toolLibrary, toolAssembly);

            if (!File.Exists(commandPath))
            {
                return null;
            }

            var isPortable = IsPortableApp(commandPath);

            return CreateCommandSpecWrappingWithCorehostIfDll(
                commandPath, 
                commandArguments, 
                depsFilePath, 
                commandResolutionStrategy,
                nugetPackagesRoot,
                isPortable);
        }
示例#4
0
        private void PopulateDependencies(
            List<LibraryRange> dependencies,
            LockFileTargetLibrary targetLibrary,
            NuGetFramework targetFramework)
        {
            foreach (var dependency in targetLibrary.Dependencies)
            {
                dependencies.Add(new LibraryRange(
                    dependency.Id,
                    dependency.VersionRange,
                    LibraryType.Unspecified,
                    LibraryDependencyType.Default));
            }

            if (!targetFramework.IsPackageBased)
            {
                // Only add framework assemblies for non-package based frameworks.
                foreach (var frameworkAssembly in targetLibrary.FrameworkAssemblies)
                {
                    dependencies.Add(new LibraryRange(
                        frameworkAssembly,
                        LibraryType.ReferenceAssembly,
                        LibraryDependencyType.Default));
                }
            }
        }
示例#5
0
        public MSBuildProjectDescription GetDescription(NuGetFramework targetFramework, LockFileProjectLibrary projectLibrary, LockFileTargetLibrary targetLibrary)
        {
            var compatible = targetLibrary.FrameworkAssemblies.Any() ||
                             targetLibrary.CompileTimeAssemblies.Any() ||
                             targetLibrary.RuntimeAssemblies.Any();

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

            var msbuildProjectFilePath = GetMSBuildProjectFilePath(projectLibrary);
            var msbuildProjectDirectoryPath = Path.GetDirectoryName(msbuildProjectFilePath);

            var exists = Directory.Exists(msbuildProjectDirectoryPath);

            var projectFile = projectLibrary.Path == null ? null : _projectResolver(projectLibrary.Path);

            var msbuildPackageDescription = new MSBuildProjectDescription(
                msbuildProjectDirectoryPath,
                msbuildProjectFilePath,
                projectLibrary,
                targetLibrary,
                projectFile,
                dependencies,
                compatible,
                resolved: compatible && exists);

            return msbuildPackageDescription;
        }
示例#6
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;
        }
示例#7
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;
        }
 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);
 }
示例#9
0
 private static void Patch(LockFileTargetLibrary libraryToPatch, LockFileTargetLibrary export)
 {
     libraryToPatch.CompileTimeAssemblies = export.CompileTimeAssemblies;
     libraryToPatch.ContentFiles = export.ContentFiles;
     libraryToPatch.FrameworkAssemblies = export.FrameworkAssemblies;
     libraryToPatch.NativeLibraries = export.NativeLibraries;
     libraryToPatch.ResourceAssemblies = export.ResourceAssemblies;
     libraryToPatch.RuntimeAssemblies = export.RuntimeAssemblies;
 }
        private string GetCommandFilePath(string nugetPackagesRoot, LockFileTargetLibrary toolLibrary, LockFileItem runtimeAssembly)
        {
            var packageDirectory = new VersionFolderPathResolver(nugetPackagesRoot)
                .GetInstallPath(toolLibrary.Name, toolLibrary.Version);

            var filePath = Path.Combine(packageDirectory, runtimeAssembly.Path);

            return filePath;
        }
        public ProjectDescription GetDescription(string name, string path, LockFileTargetLibrary targetLibrary)
        {
            Project project;

            // Can't find a project file with the name so bail
            if (!ProjectReader.TryGetProject(path, out project))
            {
                return new ProjectDescription(name, path);
            }

            return GetDescription(targetLibrary.TargetFramework, project);
        }
示例#12
0
        public ProjectDescription GetDescription(NuGetFramework targetFramework, Project project, LockFileTargetLibrary targetLibrary)
        {
            // This never returns null
            var targetFrameworkInfo = project.GetTargetFramework(targetFramework);
            var dependencies = new List<LibraryRange>(targetFrameworkInfo.Dependencies);            

            // Add all of the project's dependencies
            dependencies.AddRange(project.Dependencies);

            if (targetFramework != null && targetFramework.IsDesktop())
            {
                dependencies.Add(new LibraryRange("mscorlib", LibraryType.ReferenceAssembly, LibraryDependencyType.Build));

                dependencies.Add(new LibraryRange("System", LibraryType.ReferenceAssembly, LibraryDependencyType.Build));

                if (targetFramework.Version >= new Version(3, 5))
                {
                    dependencies.Add(new LibraryRange("System.Core", LibraryType.ReferenceAssembly, LibraryDependencyType.Build));

                    if (targetFramework.Version >= new Version(4, 0))
                    {
                        if (!dependencies.Any(dep => string.Equals(dep.Name, "Microsoft.CSharp", StringComparison.OrdinalIgnoreCase)))
                        {
                            dependencies.Add(new LibraryRange("Microsoft.CSharp", LibraryType.ReferenceAssembly, LibraryDependencyType.Build));
                        }
                    }
                }
            }
            
            if (targetLibrary != null)
            {
                // The lock file entry might have a filtered set of dependencies
                var lockFileDependencies = targetLibrary.Dependencies.ToDictionary(d => d.Id);

                // Remove all non-framework dependencies that don't appear in the lock file entry
                dependencies.RemoveAll(m => !lockFileDependencies.ContainsKey(m.Name) && m.Target != LibraryType.ReferenceAssembly);
            }

            // Mark the library as unresolved if there were specified frameworks
            // and none of them resolved
            bool unresolved = targetFrameworkInfo.FrameworkName == null;

            return new ProjectDescription(
                new LibraryRange(project.Name, LibraryType.Unspecified),
                project,
                dependencies,
                targetFrameworkInfo,
                !unresolved);
        }
 public ProjectDescription GetDescription(string name,
                                          string path,
                                          LockFileTargetLibrary targetLibrary,
                                          Func<string, Project> projectCacheResolver)
 {
     var project = _resolveProject(Path.GetDirectoryName(path));
     if (project != null)
     {
         return GetDescription(targetLibrary.TargetFramework, project);
     }
     else
     {
         return new ProjectDescription(name, path);
     }
 }
示例#14
0
        private void PopulateLegacyPortableDependencies(NuGetFramework targetFramework, List<LibraryRange> dependencies, string packagePath, LockFileTargetLibrary targetLibrary)
        {
            var seen = new HashSet<string>();

            foreach (var assembly in targetLibrary.CompileTimeAssemblies)
            {
                if (IsPlaceholderFile(assembly))
                {
                    continue;
                }

                // (ref/lib)/{tfm}/{assembly}
                var pathParts = assembly.Path.Split(Path.DirectorySeparatorChar);

                if (pathParts.Length != 3)
                {
                    continue;
                }

                var assemblyTargetFramework = NuGetFramework.Parse(pathParts[1]);

                if (!assemblyTargetFramework.IsPCL)
                {
                    continue;
                }

                var assemblyPath = Path.Combine(packagePath, assembly.Path);

                foreach (var dependency in GetDependencies(assemblyPath))
                {
                    if (seen.Add(dependency))
                    {
                        string path;
                        Version version;

                        // If there exists a reference assembly on the requested framework with the same name then turn this into a
                        // framework assembly dependency
                        if (_frameworkReferenceResolver.TryGetAssembly(dependency, targetFramework, out path, out version))
                        {
                            dependencies.Add(new LibraryRange(dependency,
                                LibraryType.ReferenceAssembly,
                                LibraryDependencyType.Build));
                        }
                    }
                }
            }
        }
        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());
        }
示例#16
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;
 }
示例#17
0
        private void PopulateDependencies(List<LibraryRange> dependencies, LockFileTargetLibrary targetLibrary)
        {
            foreach (var dependency in targetLibrary.Dependencies)
            {
                dependencies.Add(new LibraryRange(
                    dependency.Id,
                    dependency.VersionRange,
                    LibraryType.Unspecified,
                    LibraryDependencyType.Default));
            }

            foreach (var frameworkAssembly in targetLibrary.FrameworkAssemblies)
            {
                dependencies.Add(new LibraryRange(
                    frameworkAssembly, 
                    LibraryType.ReferenceAssembly, 
                    LibraryDependencyType.Default));
            }
        }
示例#18
0
        private static void AssertTargetLibrary(Microsoft.DotNet.ProjectModel.Graph.LockFileTargetLibrary library)
        {
            var libraryNumber = LibraryNumberFromName(library);

            library.Type.Should().Be("project");

            library.Name.Should().Be("ClassLibrary" + libraryNumber);
            library.Version.ToNormalizedString().Should().Be("1.0.0");

            var dll = $"bin/Debug/ClassLibrary{libraryNumber}.dll";

            dll = dll.Replace('/', Path.DirectorySeparatorChar);

            library.CompileTimeAssemblies.Count.Should().Be(1);
            library.CompileTimeAssemblies.ElementAt(0).Path.Should().Be(dll);

            library.RuntimeAssemblies.Count.Should().Be(1);
            library.RuntimeAssemblies.ElementAt(0).Path.Should().Be(dll);
        }
示例#19
0
 public TargetLibraryWithAssets(
     LibraryIdentity libraryIdentity,
     string sha512,
     string path,
     LockFileTargetLibrary lockFileLibrary,
     IEnumerable<LibraryRange> dependencies,
     bool compatible,
     bool resolved,
     NuGetFramework framework = null)
     : base(
           libraryIdentity,
           sha512,
           path,
           dependencies: dependencies,
           framework: null,
           resolved: resolved,
           compatible: compatible)
 {
     TargetLibrary = lockFileLibrary;
 }
示例#20
0
        private LockFileTargetLibrary ReadTargetLibrary(string property, JToken json)
        {
            var jobject = json as JObject;

            if (jobject == null)
            {
                throw FileFormatException.Create("The value type is not an object.", json);
            }

            var library = new LockFileTargetLibrary();

            var parts = property.Split(new[] { '/' }, 2);

            library.Name = _symbols.GetString(parts[0]);
            if (parts.Length == 2)
            {
                library.Version = _symbols.GetVersion(parts[1]);
            }

            library.Type = _symbols.GetString(jobject.Value <string>("type"));
            var framework = jobject.Value <string>("framework");

            if (framework != null)
            {
                library.TargetFramework = _symbols.GetFramework(framework);
            }

            library.Dependencies          = ReadObject(jobject.Value <JObject>("dependencies"), ReadPackageDependency);
            library.FrameworkAssemblies   = new HashSet <string>(ReadArray(jobject["frameworkAssemblies"], ReadFrameworkAssemblyReference), StringComparer.OrdinalIgnoreCase);
            library.RuntimeAssemblies     = ReadObject(jobject.Value <JObject>("runtime"), ReadFileItem);
            library.CompileTimeAssemblies = ReadObject(jobject.Value <JObject>("compile"), ReadFileItem);
            library.ResourceAssemblies    = ReadObject(jobject.Value <JObject>("resource"), ReadFileItem);
            library.NativeLibraries       = ReadObject(jobject.Value <JObject>("native"), ReadFileItem);
            library.ContentFiles          = ReadObject(jobject.Value <JObject>("contentFiles"), ReadContentFile);
            library.RuntimeTargets        = ReadObject(jobject.Value <JObject>("runtimeTargets"), ReadRuntimeTarget);

            return(library);
        }
 public MSBuildProjectDescription(
     string path,
     string msbuildProjectPath,
     LockFileProjectLibrary projectLibrary,
     LockFileTargetLibrary lockFileLibrary,
     Project projectFile,
     IEnumerable<LibraryRange> dependencies,
     bool compatible,
     bool resolved)
     : base(
           new LibraryIdentity(projectLibrary.Name, projectLibrary.Version, LibraryType.MSBuildProject),
           string.Empty, //msbuild projects don't have hashes
           path,
           lockFileLibrary,
           dependencies,
           resolved: resolved,
           compatible: compatible,
           framework: null)
 {
     MSBuildProjectPath = msbuildProjectPath;
     ProjectFile = projectFile;
     ProjectLibrary = projectLibrary;
 }
示例#22
0
        private static int LibraryNumberFromName(Microsoft.DotNet.ProjectModel.Graph.LockFileTargetLibrary library)
        {
            var libraryName = library.Name;

            return((int)char.GetNumericValue(libraryName[libraryName.Length - 1]));
        }
 private CommandSpec ResolveFromDependencyLibrary(
     LockFileTargetLibrary toolLibrary,
     string depsFilePath,
     string commandName,
     IEnumerable<string> allowedExtensions,
     IEnumerable<string> commandArguments,
     ProjectContext projectContext)
 {
     return _packagedCommandSpecFactory.CreateCommandSpecFromLibrary(
                 toolLibrary,
                 commandName,
                 commandArguments,
                 allowedExtensions,
                 projectContext.PackagesDirectory,
                 s_commandResolutionStrategy,
                 depsFilePath);
 }
 public ProjectDescription GetDescription(string name, string path, LockFileTargetLibrary targetLibrary)
 {
     return GetDescription(name, path, targetLibrary, projectCacheResolver: null);
 }
示例#25
0
 private static string GetTargetLibraryKey(LockFileTargetLibrary library)
 {
     return library.Name + "/" + library.Version;
 }
示例#26
0
 private static object TypeName(LockFileTargetLibrary library)
 {
     return(library.Name + "/" + library.Version + "/" + library.Type);
 }
示例#27
0
 private static string GetTargetLibraryKey(LockFileTargetLibrary library)
 {
     return(library.Name + "/" + library.Version);
 }
示例#28
0
 private static object TypeName(LockFileTargetLibrary library)
 {
     return library.Name + "/" + library.Version + "/" + library.Type;
 }