Esempio n. 1
0
File: NuGet.cs Progetto: vigoo/bari
        /// <summary>
        /// Installs a package and returns the path to the DLLs to be linked
        /// </summary>
        /// <param name="name">Package name</param>
        /// <param name="version">Package version, if null or empty then the latest one will be used</param>
        /// <param name="root">Root directory for storing the downloaded packages</param>
        /// <param name="relativeTargetDirectory">Path relative to <c>root</c> where the downloaded package should be placed</param>
        /// <param name="dllsOnly">If <c>true</c>, only the DLLs will be returned, otherwise all the files in the package</param>
        /// <param name="maxProfile">Maximum allowed profile</param>
        /// <returns>Returns the <c>root</c> relative paths of the DLL files to be used</returns>
        public Tuple<string, IEnumerable<string>> InstallPackage(string name, string version, IFileSystemDirectory root, string relativeTargetDirectory, bool dllsOnly, NugetLibraryProfile maxProfile)
        {
            if (String.IsNullOrWhiteSpace(version))
                Run(root, "install", name, "-o", "\""+relativeTargetDirectory+"\"", "-Verbosity", Verbosity);
            else
                Run(root, "install", name, "-Version", version, "-o", "\"" + relativeTargetDirectory + "\"", "-Verbosity", Verbosity);

            var result = new List<string>(); // root relative paths
            string commonRoot = String.Empty; // root relative path

            var localRoot = root as LocalFileSystemDirectory;
            if (localRoot != null)
            {
                var pkgRoot = new DirectoryInfo(Path.Combine(localRoot.AbsolutePath, relativeTargetDirectory));

                var modRoot = FindDirectory(pkgRoot, name);

                if (modRoot != null)
                {
                    var libRoot = modRoot.GetDirectories("lib", SearchOption.TopDirectoryOnly).FirstOrDefault();
                    var contentRoot = modRoot.GetDirectories("content", SearchOption.TopDirectoryOnly).FirstOrDefault();
                    commonRoot = GetRelativePath(modRoot.FullName, localRoot);

                    if (libRoot != null)
                    {
                        AddDlls(libRoot, result, localRoot, maxProfile);
                        commonRoot = GetRelativePath(libRoot.FullName, localRoot);
                    }
                    if (contentRoot != null && !dllsOnly)
                    {
                        AddContents(contentRoot, result, localRoot);

                        if (libRoot == null)
                            commonRoot = GetRelativePath(contentRoot.FullName, localRoot);
                    }
                }
            }

            log.DebugFormat("Returning common root {0}", commonRoot);
            return Tuple.Create(commonRoot, result.AsEnumerable());
        }
Esempio n. 2
0
File: NuGet.cs Progetto: vigoo/bari
        private void AddDlls(DirectoryInfo libRoot, List<string> result, LocalFileSystemDirectory localRoot, NugetLibraryProfile maxProfile)
        {
            var lib45 = GetChild(libRoot, "net45-full") ??
                        GetChild(libRoot, "net45");
            var lib40 = GetChild(libRoot, "net40-full") ??
                        GetChild(libRoot, "net40") ??
                        GetChild(libRoot, "net4");
            var lib40client = GetChild(libRoot, "net40-client");
            var lib35 = GetChild(libRoot, "net35");
            var lib35client = GetChild(libRoot, "net35-client");
            var lib20 = GetChild(libRoot, "net20") ??
                        GetChild(libRoot, "20");

            if (lib45 != null && maxProfile == NugetLibraryProfile.Net45)
                result.AddRange(GetDllsIn(localRoot, lib45));
            else if (lib40 != null && maxProfile >= NugetLibraryProfile.Net4)
                result.AddRange(GetDllsIn(localRoot, lib40));
            else if (lib40client != null && maxProfile >= NugetLibraryProfile.Net4Client)
                result.AddRange(GetDllsIn(localRoot, lib40client));
            else if (lib35 != null && maxProfile != NugetLibraryProfile.Net35)
                result.AddRange(GetDllsIn(localRoot, lib35));
            else if (lib35client != null && maxProfile != NugetLibraryProfile.Net35Client)
                result.AddRange(GetDllsIn(localRoot, lib35client));
            else if (lib20 != null && maxProfile != NugetLibraryProfile.Net2)
                result.AddRange(GetDllsIn(localRoot, lib20));
            else
                result.AddRange(GetDllsIn(localRoot, libRoot));
        }