コード例 #1
0
        private Dictionary <string, string> CreateFileMapping(NuGet.IPackage package)
        {
            Dictionary <string, string> fileMapping = new Dictionary <string, string>();

            bool isDualityPackage =
                package.Tags != null &&
                package.Tags.Contains("Duality");
            bool isPluginPackage =
                isDualityPackage &&
                package.Tags.Contains("Plugin");
            string binaryBaseDir  = this.pluginTargetDir;
            string contentBaseDir = this.dataTargetDir;

            if (!isPluginPackage || !isDualityPackage)
            {
                binaryBaseDir = "";
            }

            foreach (var f in package.GetFiles()
                     .Where(f => f.TargetFramework == null || f.TargetFramework.Version < Environment.Version)
                     .OrderByDescending(f => f.TargetFramework == null ? new Version() : f.TargetFramework.Version)
                     .OrderByDescending(f => f.TargetFramework == null))
            {
                // Determine where the file needs to go
                string targetPath = f.EffectivePath;
                string baseDir    = f.Path;
                while (baseDir.Contains(Path.DirectorySeparatorChar) || baseDir.Contains(Path.AltDirectorySeparatorChar))
                {
                    baseDir = Path.GetDirectoryName(baseDir);
                }
                if (string.Equals(baseDir, "lib", StringComparison.InvariantCultureIgnoreCase))
                {
                    targetPath = Path.Combine(binaryBaseDir, targetPath);
                }
                else if (string.Equals(baseDir, "content", StringComparison.InvariantCultureIgnoreCase))
                {
                    targetPath = Path.Combine(contentBaseDir, targetPath);
                }
                else
                {
                    continue;
                }

                // Add a file mapping entry linking target path to package path
                if (fileMapping.ContainsKey(targetPath))
                {
                    continue;
                }
                fileMapping[targetPath] = f.Path;
            }

            return(fileMapping);
        }
コード例 #2
0
        private Dictionary <string, string> CreateFileMapping(NuGet.IPackage package)
        {
            Dictionary <string, string> fileMapping = new Dictionary <string, string>();

            bool isDualityPackage = IsDualityPackage(package);
            bool isPluginPackage  = isDualityPackage && package.Tags.Contains(PluginTag);

            string folderFriendlyPackageName = package.Id;
            string binaryBaseDir             = this.env.TargetPluginPath;
            string contentBaseDir            = this.env.TargetDataPath;
            string sourceBaseDir             = Path.Combine(this.env.TargetSourcePath, folderFriendlyPackageName);

            if (!isPluginPackage || !isDualityPackage)
            {
                binaryBaseDir  = this.env.RootPath;
                contentBaseDir = this.env.RootPath;
            }

            IPackageFile[] packageFiles;
            try
            {
                packageFiles = package.GetFiles()
                               .Where(f => f.TargetFramework == null || f.TargetFramework.Version < Environment.Version)
                               .OrderByDescending(f => f.TargetFramework == null ? new Version() : f.TargetFramework.Version)
                               .OrderByDescending(f => f.TargetFramework == null)
                               .ToArray();
            }
            catch (DirectoryNotFoundException)
            {
                // We'll run into this exception when uninstalling a package without any files.
                return(fileMapping);
            }

            foreach (IPackageFile f in packageFiles)
            {
                // Determine where the file needs to go
                string targetPath = f.EffectivePath;
                string baseDir    = f.Path;
                while (baseDir.Contains(Path.DirectorySeparatorChar) || baseDir.Contains(Path.AltDirectorySeparatorChar))
                {
                    baseDir = Path.GetDirectoryName(baseDir);
                }
                if (string.Equals(baseDir, "lib", StringComparison.InvariantCultureIgnoreCase))
                {
                    targetPath = Path.Combine(binaryBaseDir, targetPath);
                }
                else if (string.Equals(baseDir, "content", StringComparison.InvariantCultureIgnoreCase))
                {
                    targetPath = Path.Combine(contentBaseDir, targetPath);
                }
                else if (string.Equals(baseDir, "source", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (targetPath.StartsWith("source") && targetPath.Length > "source".Length)
                    {
                        targetPath = targetPath.Remove(0, "source".Length + 1);
                    }
                    targetPath = Path.Combine(sourceBaseDir, targetPath);
                }
                else
                {
                    continue;
                }

                // Add a file mapping entry linking target path to package path
                if (fileMapping.ContainsKey(targetPath))
                {
                    continue;
                }
                fileMapping[targetPath] = f.Path;
            }

            return(fileMapping);
        }