Example #1
0
        /// <summary>
        /// Skips all packages declared in specified <paramref name="packagesConfig"/>.
        /// </summary>
        /// <param name="skipPackages">The instance</param>
        /// <param name="packagesConfig">The document</param>
        public static void SkipPackages(this ISkipPackages skipPackages, XDocument packagesConfig)
        {
            var xPackages = packagesConfig.Element("packages")?.Elements("package").ToList();
            var packages  =
                xPackages?.Select(
                    p => new PackageName(p.Attribute("id").Value, SemanticVersion.Parse(p.Attribute("version").Value)));

            skipPackages.SkipPackages(packages);
        }
Example #2
0
        /// <summary>
        /// Skips all packages specified in an embedded resource <paramref name="resourceName"/> of the specified <paramref name="assembly"/>.
        /// This tries finding and reading embedded resource as an <see cref="XDocument"/> with the existing packages to skip installing.
        /// </summary>
        /// <param name="skipPackages">The instance</param>
        /// <param name="assembly">The assembly</param>
        /// <param name="resourceName">The resource name</param>
        public static void SkipPackages(this ISkipPackages skipPackages, Assembly assembly = null, string resourceName = "packages.config")
        {
            var safeAssembly = assembly ?? Assembly.GetCallingAssembly();

            using (var stream = GetResourceStream(safeAssembly, resourceName))
            {
                if (stream == null)
                {
                    return;
                }
                try
                {
                    var xDoc = XDocument.Load(stream);
                    SkipPackages(skipPackages, xDoc);
                }
                catch (Exception ex)
                {
                    Trace.TraceWarning($"Could not read embedded resource 'packages.config': {ex}");
                }
            }
        }