Beispiel #1
0
        private static string ResolveTargetPath(IProjectSystem projectSystem,
                                                IDictionary <string, IPackageFileTransformer> fileTransformers,
                                                string effectivePath,
                                                out IPackageFileTransformer transformer)
        {
            // Try to get the package file modifier for the extension
            string extension = Path.GetExtension(effectivePath);

            if (fileTransformers.TryGetValue(extension, out transformer))
            {
                // Remove the transformer extension (e.g. .pp, .transform)
                string truncatedPath = RemoveExtension(effectivePath);

                // Bug 1686: Don't allow transforming packages.config.transform,
                // but we still want to copy packages.config.transform as-is into the project.
                string fileName = Path.GetFileName(truncatedPath);
                if (Constants.PackageReferenceFile.Equals(fileName, StringComparison.OrdinalIgnoreCase))
                {
                    // setting to null means no pre-processing of this file
                    transformer = null;
                }
                else
                {
                    effectivePath = truncatedPath;
                }
            }

            return(projectSystem.ResolvePath(effectivePath));
        }
        private static string ResolveTargetPath(IProjectSystem projectSystem,
                                                IDictionary <FileTransformExtensions, IPackageFileTransformer> fileTransformers,
                                                Func <FileTransformExtensions, string> extensionSelector,
                                                string effectivePath,
                                                out IPackageFileTransformer transformer)
        {
            string truncatedPath;

            // Remove the transformer extension (e.g. .pp, .transform)
            transformer = FindFileTransformer(fileTransformers, extensionSelector, effectivePath, out truncatedPath);
            if (transformer != null)
            {
                effectivePath = truncatedPath;
            }

            return(projectSystem.ResolvePath(effectivePath));
        }
        public static void AddFiles(this IProjectSystem project,
                                    IEnumerable <IPackageFile> files,
                                    IDictionary <FileTransformExtensions, IPackageFileTransformer> fileTransformers)
        {
            // Convert files to a list
            List <IPackageFile> fileList = files.ToList();

            // See if the project system knows how to sort the files
            var fileComparer = project as IComparer <IPackageFile>;

            if (fileComparer != null)
            {
                fileList.Sort(fileComparer);
            }

            var batchProcessor = project as IBatchProcessor <string>;

            try
            {
                if (batchProcessor != null)
                {
                    var paths = fileList.Select(file => ResolvePath(fileTransformers, fte => fte.InstallExtension, file.EffectivePath));
                    batchProcessor.BeginProcessing(paths, PackageAction.Install);
                }

                foreach (IPackageFile file in fileList)
                {
                    if (file.IsEmptyFolder())
                    {
                        continue;
                    }

                    // Resolve the target path
                    IPackageFileTransformer installTransformer;
                    string path = ResolveTargetPath(project, fileTransformers, fte => fte.InstallExtension, file.EffectivePath, out installTransformer);

                    if (project.IsSupportedFile(path))
                    {
                        if (installTransformer != null)
                        {
                            installTransformer.TransformFile(file, path, project);
                        }
                        else
                        {
                            // Ignore uninstall transform file during installation
                            string truncatedPath;
                            IPackageFileTransformer uninstallTransformer =
                                FindFileTransformer(fileTransformers, fte => fte.UninstallExtension, file.EffectivePath, out truncatedPath);
                            if (uninstallTransformer != null)
                            {
                                continue;
                            }
                            TryAddFile(project, path, file.GetStream);
                        }
                    }
                }
            }
            finally
            {
                if (batchProcessor != null)
                {
                    batchProcessor.EndProcessing();
                }
            }
        }
        private static string ResolveTargetPath(IMSBuildNuGetProjectSystem msBuildNuGetProjectSystem,
                                                IDictionary<FileTransformExtensions, IPackageFileTransformer> fileTransformers,
                                                Func<FileTransformExtensions, string> extensionSelector,
                                                string effectivePath,
                                                out IPackageFileTransformer transformer)
        {
            string truncatedPath;

            // Remove the transformer extension (e.g. .pp, .transform)
            transformer = FindFileTransformer(fileTransformers, extensionSelector, effectivePath, out truncatedPath);
            if (transformer != null)
            {
                effectivePath = truncatedPath;
            }

            return msBuildNuGetProjectSystem.ResolvePath(effectivePath);
        }
Beispiel #5
0
        private static string ResolveTargetPath(IProjectSystem projectSystem, IDictionary <FileTransformExtensions, IPackageFileTransformer> fileTransformers, Func <FileTransformExtensions, string> extensionSelector, string effectivePath, out IPackageFileTransformer transformer)
        {
            string str;

            transformer = FindFileTransformer(fileTransformers, extensionSelector, effectivePath, out str);
            if (transformer != null)
            {
                effectivePath = str;
            }
            return(projectSystem.ResolvePath(effectivePath));
        }
Beispiel #6
0
        internal static void AddFiles(IMSBuildNuGetProjectSystem msBuildNuGetProjectSystem,
                                      ZipArchive zipArchive,
                                      FrameworkSpecificGroup frameworkSpecificGroup,
                                      IDictionary <FileTransformExtensions, IPackageFileTransformer> fileTransformers)
        {
            var packageTargetFramework = frameworkSpecificGroup.TargetFramework;

            // Content files are maintained with AltDirectorySeparatorChar
            List <string> packageItemListAsArchiveEntryNames = frameworkSpecificGroup.Items.Select(i => PathUtility.ReplaceDirSeparatorWithAltDirSeparator(i)).ToList();

            packageItemListAsArchiveEntryNames.Sort(new PackageItemComparer());
            try
            {
                var zipArchiveEntryList = packageItemListAsArchiveEntryNames.Select(i => zipArchive.GetEntry(i)).Where(i => i != null).ToList();
                try
                {
                    var paths = zipArchiveEntryList.Select(file => ResolvePath(fileTransformers, fte => fte.InstallExtension,
                                                                               GetEffectivePathForContentFile(packageTargetFramework, file.FullName)));
                    paths = paths.Where(p => !String.IsNullOrEmpty(p));
                    msBuildNuGetProjectSystem.BeginProcessing(paths);
                }
                catch (Exception)
                {
                    // Ignore all exceptions for now
                }

                foreach (ZipArchiveEntry zipArchiveEntry in zipArchiveEntryList)
                {
                    if (zipArchiveEntry == null)
                    {
                        throw new ArgumentNullException("zipArchiveEntry");
                    }

                    if (IsEmptyFolder(zipArchiveEntry.FullName))
                    {
                        continue;
                    }

                    var effectivePathForContentFile = GetEffectivePathForContentFile(packageTargetFramework, zipArchiveEntry.FullName);

                    // Resolve the target path
                    IPackageFileTransformer installTransformer;
                    string path = ResolveTargetPath(msBuildNuGetProjectSystem,
                                                    fileTransformers,
                                                    fte => fte.InstallExtension, effectivePathForContentFile, out installTransformer);

                    if (msBuildNuGetProjectSystem.IsSupportedFile(path))
                    {
                        if (installTransformer != null)
                        {
                            installTransformer.TransformFile(zipArchiveEntry, path, msBuildNuGetProjectSystem);
                        }
                        else
                        {
                            // Ignore uninstall transform file during installation
                            string truncatedPath;
                            IPackageFileTransformer uninstallTransformer =
                                FindFileTransformer(fileTransformers, fte => fte.UninstallExtension, effectivePathForContentFile, out truncatedPath);
                            if (uninstallTransformer != null)
                            {
                                continue;
                            }
                            TryAddFile(msBuildNuGetProjectSystem, path, zipArchiveEntry.Open);
                        }
                    }
                }
            }
            finally
            {
                msBuildNuGetProjectSystem.EndProcessing();
            }
        }