Exemplo n.º 1
0
        /// <summary>
        /// Creates a NuGetFramework from a folder name using the given mappings.
        /// </summary>
        public static NuGetFramework Parse(string folderName, IFrameworkNameProvider mappings)
        {
            if (folderName == null)
            {
                throw new ArgumentNullException(nameof(folderName));
            }

            if (mappings == null)
            {
                throw new ArgumentNullException(nameof(mappings));
            }

            var framework = UnsupportedFramework;

            if (folderName.IndexOf(',') > -1)
            {
                framework = ParseFrameworkName(folderName, mappings);
            }
            else
            {
                framework = ParseFolder(folderName, mappings);
            }

            return framework;
        }
Exemplo n.º 2
0
 public CompatibilityTable(IEnumerable<NuGetFramework> frameworks, IFrameworkNameProvider mappings, IFrameworkCompatibilityProvider compat)
 {
     _compat = compat;
     _mappings = mappings;
     _table = GetTable(frameworks, _mappings, _compat);
     _reducer = new FrameworkReducer(_mappings, _compat);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Creates a FrameworkReducer using custom framework mappings.
 /// </summary>
 public FrameworkReducer(IFrameworkNameProvider mappings, IFrameworkCompatibilityProvider compat)
 {
     _mappings = mappings;
     _compat = compat;
     _fullComparer = new NuGetFrameworkFullComparer();
     _fwNameComparer = new NuGetFrameworkNameComparer();
 }
Exemplo n.º 4
0
 public PackagesConfigWriter(IFrameworkNameProvider frameworkMappings, Stream stream)
 {
     _stream            = stream;
     _closed            = false;
     _entries           = new List <PackageReference>();
     _frameworkMappings = frameworkMappings;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a NuGetFramework from a folder name using the given mappings.
        /// </summary>
        public static NuGetFramework Parse(string folderName, IFrameworkNameProvider mappings)
        {
            if (folderName == null)
            {
                throw new ArgumentNullException(nameof(folderName));
            }

            if (mappings == null)
            {
                throw new ArgumentNullException(nameof(mappings));
            }

            var framework = UnsupportedFramework;

            if (folderName.IndexOf(',') > -1)
            {
                framework = ParseFrameworkName(folderName, mappings);
            }
            else
            {
                framework = ParseFolder(folderName, mappings);
            }

            return(framework);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Create a packages.config writer using file path
        /// </summary>
        /// <param name="fullPath">The full path to write the XML packages.config file into, or load existing packages.config from</param>
        /// <param name="createNew">Whether to create a new packages.config file, or load an existing one</param>
        /// <param name="frameworkMappings">Framework mappings</param>
        public PackagesConfigWriter(string fullPath, bool createNew, IFrameworkNameProvider frameworkMappings)
        {
            if (fullPath == null)
            {
                throw new ArgumentNullException(nameof(fullPath));
            }

            _frameworkMappings = frameworkMappings;
            _filePath          = fullPath;

            if (createNew)
            {
                CreateDefaultXDocument();
            }
            // Load the existing packages.config file.
            else
            {
                try
                {
                    using (var stream = new FileStream(fullPath, FileMode.Open, FileAccess.Read))
                    {
                        _xDocument = XDocument.Load(stream);
                    }
                }
                catch (Exception ex)
                {
                    throw new PackagesConfigWriterException(string.Format(CultureInfo.CurrentCulture,
                                                                          Strings.FailToLoadPackagesConfig), ex);
                }
            }
        }
        /// <summary>
        /// Find the most compatible group based on target framework
        /// </summary>
        /// <param name="items">framework specific groups or items</param>
        /// <param name="framework">project target framework</param>
        public static T GetNearest <T>(IEnumerable <T> items,
                                       NuGetFramework framework,
                                       IFrameworkNameProvider frameworkMappings,
                                       IFrameworkCompatibilityProvider compatibilityProvider) where T : IFrameworkSpecific
        {
            if (framework == null)
            {
                throw new ArgumentNullException("framework");
            }

            if (frameworkMappings == null)
            {
                throw new ArgumentNullException("frameworkMappings");
            }

            if (compatibilityProvider == null)
            {
                throw new ArgumentNullException("compatibilityProvider");
            }

            if (items != null)
            {
                var reducer = new FrameworkReducer(frameworkMappings, compatibilityProvider);

                var mostCompatibleFramework = reducer.GetNearest(framework, items.Select(item => item.TargetFramework));
                if (mostCompatibleFramework != null)
                {
                    return(items.FirstOrDefault(item => NuGetFramework.Comparer.Equals(item.TargetFramework, mostCompatibleFramework)));
                }
            }

            return(default(T));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Find the most compatible group based on target framework
        /// </summary>
        /// <param name="items">framework specific groups or items</param>
        /// <param name="framework">project target framework</param>
        /// <param name="selector">retrieves the framework from the group</param>
        /// <param name="frameworkMappings">framework mappings</param>
        public static T GetNearest <T>(IEnumerable <T> items,
                                       NuGetFramework framework,
                                       IFrameworkNameProvider frameworkMappings,
                                       IFrameworkCompatibilityProvider compatibilityProvider,
                                       Func <T, NuGetFramework> selector) where T : class
        {
            if (framework == null)
            {
                throw new ArgumentNullException(nameof(framework));
            }

            if (frameworkMappings == null)
            {
                throw new ArgumentNullException(nameof(frameworkMappings));
            }

            if (compatibilityProvider == null)
            {
                throw new ArgumentNullException(nameof(compatibilityProvider));
            }

            if (items != null)
            {
                var reducer = new FrameworkReducer(frameworkMappings, compatibilityProvider);

                var mostCompatibleFramework = reducer.GetNearest(framework, items.Select(selector));
                if (mostCompatibleFramework != null)
                {
                    return(items.FirstOrDefault(item => NuGetFramework.Comparer.Equals(selector(item), mostCompatibleFramework)));
                }
            }

            return(null);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates a NuGetFramework from a folder name using the given mappings.
        /// </summary>
        public static NuGetFramework Parse(string folderName, IFrameworkNameProvider mappings)
        {
            if (folderName == null)
            {
                throw new ArgumentNullException("folderName");
            }

            if (mappings == null)
            {
                throw new ArgumentNullException("mappings");
            }

            Debug.Assert(folderName.IndexOf(";") < 0, "invalid folder name, this appears to contain multiple frameworks");

            var framework = UnsupportedFramework;

            if (folderName.IndexOf(',') > -1)
            {
                framework = ParseFrameworkName(folderName, mappings);
            }
            else
            {
                framework = ParseFolder(folderName, mappings);
            }

            return(framework);
        }
Exemplo n.º 10
0
        /// <summary>The TargetFrameworkMoniker identifier of the current NuGetFrameowrk.</summary>
        /// <remarks>Formatted to a System.Versioning.FrameworkName</remarks>
        public string GetDotNetFrameworkName(IFrameworkNameProvider mappings)
        {
            if (mappings == null)
            {
                throw new ArgumentNullException(nameof(mappings));
            }

            // Check for rewrites
            var framework = mappings.GetFullNameReplacement(this);

            if (framework.IsSpecificFramework)
            {
                var parts = new List <string>(3)
                {
                    Framework
                };

                parts.Add(string.Format(CultureInfo.InvariantCulture, "Version=v{0}", GetDisplayVersion(framework.Version)));

                if (!string.IsNullOrEmpty(framework.Profile))
                {
                    parts.Add(string.Format(CultureInfo.InvariantCulture, "Profile={0}", framework.Profile));
                }

                return(string.Join(",", parts));
            }
            else
            {
                return(string.Format(CultureInfo.InvariantCulture, "{0},Version=v0.0", framework.Framework));
            }
        }
 /// <summary>
 /// Creates a FrameworkReducer using custom framework mappings.
 /// </summary>
 public FrameworkReducer(IFrameworkNameProvider mappings, IFrameworkCompatibilityProvider compat)
 {
     _mappings       = mappings;
     _compat         = compat;
     _fullComparer   = new NuGetFrameworkFullComparer();
     _fwNameComparer = new NuGetFrameworkNameComparer();
 }
Exemplo n.º 12
0
        public PackageArchiveReader(string filePath, IFrameworkNameProvider frameworkProvider = null, IFrameworkCompatibilityProvider compatibilityProvider = null)
            : base(frameworkProvider ?? DefaultFrameworkNameProvider.Instance, compatibilityProvider ?? DefaultCompatibilityProvider.Instance)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException(nameof(filePath));
            }

            // Since this constructor owns the stream, the responsibility falls here to dispose the stream of an
            // invalid .zip archive. If this constructor succeeds, the disposal of the stream is handled by the
            // disposal of this instance.
            Stream stream = null;

            try
            {
                stream        = File.OpenRead(filePath);
                ZipReadStream = stream;
                _zipArchive   = new ZipArchive(stream, ZipArchiveMode.Read);
            }
            catch
            {
                stream?.Dispose();
                throw;
            }
        }
Exemplo n.º 13
0
 public PackagesConfigWriter(IFrameworkNameProvider frameworkMappings, Stream stream)
 {
     _stream = stream;
     _closed = false;
     _entries = new List<PackageReference>();
     _frameworkMappings = frameworkMappings;
 }
Exemplo n.º 14
0
        /// <summary>
        /// Formatted to a System.Versioning.FrameworkName
        /// </summary>
        public string GetDotNetFrameworkName(IFrameworkNameProvider mappings)
        {
            // Check for rewrites
            var framework = mappings.GetFullNameReplacement(this);

            var result = string.Empty;

            if (framework.IsSpecificFramework)
            {
                var parts = new List <string>(3)
                {
                    framework.Framework
                };

                parts.Add(String.Format(CultureInfo.InvariantCulture, "Version=v{0}", GetDisplayVersion(framework.Version)));

                if (!String.IsNullOrEmpty(framework.Profile))
                {
                    parts.Add(String.Format(CultureInfo.InvariantCulture, "Profile={0}", framework.Profile));
                }

                result = String.Join(",", parts);
            }
            else
            {
                result = String.Format(CultureInfo.InvariantCulture, "{0},Version=v0.0", framework.Framework);
            }

            return(result);
        }
 public CompatibilityTable(IEnumerable <NuGetFramework> frameworks, IFrameworkNameProvider mappings, IFrameworkCompatibilityProvider compat)
 {
     _compat   = compat;
     _mappings = mappings;
     _table    = GetTable(frameworks, _compat);
     _reducer  = new FrameworkReducer(_mappings, _compat);
 }
        public DefaultNuGetFramework(IFrameworkNameProvider frameworkNameProvider)
        {
            Argument.IsNotNull(() => frameworkNameProvider);

            _frameworkNameProvider = frameworkNameProvider;

            LoadAvailableFrameworks();
        }
Exemplo n.º 17
0
        public PackageDependencyResolverService(IFrameworkNameProvider frameworkNameProvider, ISourceRepositoryProvider sourceRepositoryProvider)
        {
            Argument.IsNotNull(() => frameworkNameProvider);
            Argument.IsNotNull(() => sourceRepositoryProvider);

            _frameworkNameProvider = frameworkNameProvider;
            repositories           = sourceRepositoryProvider.GetRepositories();
        }
Exemplo n.º 18
0
        public ExampleProject(IFrameworkNameProvider frameworkNameProvider)
        {
            _pathResolver = TypeFactory.Default.CreateInstanceWithParametersAndAutoCompletion <ExamplePackagePathResolver>();

            var targetFramework = FrameworkParser.TryParseFrameworkName(Framework, frameworkNameProvider);

            SupportedPlatforms = ImmutableList.Create(FrameworkParser.ToSpecificPlatform(targetFramework));
        }
Exemplo n.º 19
0
        /// <summary>
        /// Nupkg package reader
        /// </summary>
        /// <param name="zipArchive">ZipArchive containing the nupkg data.</param>
        /// <param name="frameworkProvider">Framework mapping provider for NuGetFramework parsing.</param>
        /// <param name="compatibilityProvider">Framework compatibility provider.</param>
        public PackageReader(ZipArchive zipArchive, IFrameworkNameProvider frameworkProvider, IFrameworkCompatibilityProvider compatibilityProvider)
            : base(frameworkProvider, compatibilityProvider)
        {
            if (zipArchive == null)
            {
                throw new ArgumentNullException(nameof(zipArchive));
            }

            _zip = zipArchive;
        }
Exemplo n.º 20
0
        public PackageArchiveReader(string filePath, IFrameworkNameProvider frameworkProvider = null, IFrameworkCompatibilityProvider compatibilityProvider = null)
            : base(frameworkProvider ?? DefaultFrameworkNameProvider.Instance, compatibilityProvider ?? DefaultCompatibilityProvider.Instance)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException(nameof(filePath));
            }

            _zipArchive = new ZipArchive(File.OpenRead(filePath), ZipArchiveMode.Read);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Nupkg package reader
        /// </summary>
        /// <param name="zipArchive">ZipArchive containing the nupkg data.</param>
        /// <param name="frameworkProvider">Framework mapping provider for NuGetFramework parsing.</param>
        /// <param name="compatibilityProvider">Framework compatibility provider.</param>
        public PackageArchiveReader(ZipArchive zipArchive, IFrameworkNameProvider frameworkProvider, IFrameworkCompatibilityProvider compatibilityProvider)
            : base(frameworkProvider, compatibilityProvider)
        {
            if (zipArchive == null)
            {
                throw new ArgumentNullException(nameof(zipArchive));
            }

            _zipArchive = zipArchive;
        }
Exemplo n.º 22
0
 public static NuGetFramework TryParseFrameworkName(string frameworkString, IFrameworkNameProvider frameworkNameProvider)
 {
     try
     {
         return(NuGetFramework.ParseFrameworkName(frameworkString, frameworkNameProvider));
     }
     catch (ArgumentException)
     {
         return(NuGetFramework.UnsupportedFramework);
     }
 }
        internal static NuGetFramework GetNuGetFramework(
            NetPortableProfileTable table,
            IFrameworkNameProvider provider,
            FrameworkName framework)
        {
            // Use the short folder name as the common format between FrameworkName and
            // NuGetFramework. With portable frameworks, there are differences in
            // FrameworkName and NuGetFramework.DotNetFrameworkName.
            var folderName = GetShortFrameworkName(table, framework);

            return(NuGetFramework.ParseFolder(folderName, provider));
        }
Exemplo n.º 24
0
        /// <summary>
        /// Packages.config reader
        /// </summary>
        /// <param name="frameworkMappings">Additional target framework mappings for parsing target frameworks</param>
        /// <param name="xml">Packages.config XML</param>
        public PackagesConfigReader(IFrameworkNameProvider frameworkMappings, XDocument xml)
        {
            if (xml == null)
            {
                throw new ArgumentNullException(nameof(xml));
            }

            if (frameworkMappings == null)
            {
                throw new ArgumentNullException(nameof(frameworkMappings));
            }

            _doc = xml;
            _frameworkMappings = frameworkMappings;
        }
Exemplo n.º 25
0
        /// <summary>
        /// Packages.config reader
        /// </summary>
        /// <param name="frameworkMappings">Additional target framework mappings for parsing target frameworks</param>
        /// <param name="xml">Packages.config XML</param>
        public PackagesConfigReader(IFrameworkNameProvider frameworkMappings, XDocument xml)
        {
            if (xml == null)
            {
                throw new ArgumentNullException(nameof(xml));
            }

            if (frameworkMappings == null)
            {
                throw new ArgumentNullException(nameof(frameworkMappings));
            }

            _doc = xml;
            _frameworkMappings = frameworkMappings;
        }
Exemplo n.º 26
0
        /// <summary>
        /// Instantiates a new <see cref="PackageReaderBase" /> class.
        /// </summary>
        /// <param name="frameworkProvider">A framework mapping provider.</param>
        /// <param name="compatibilityProvider">A framework compatibility provider.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="frameworkProvider" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="compatibilityProvider" /> is <c>null</c>.</exception>
        public PackageReaderBase(IFrameworkNameProvider frameworkProvider, IFrameworkCompatibilityProvider compatibilityProvider)
        {
            if (frameworkProvider == null)
            {
                throw new ArgumentNullException(nameof(frameworkProvider));
            }

            if (compatibilityProvider == null)
            {
                throw new ArgumentNullException(nameof(compatibilityProvider));
            }

            FrameworkProvider     = frameworkProvider;
            CompatibilityProvider = compatibilityProvider;
        }
Exemplo n.º 27
0
        /// <summary>
        /// Packages.config reader
        /// </summary>
        /// <param name="stream">Stream containing packages.config</param>
        /// <param name="leaveStreamOpen">True will leave the stream open</param>
        /// <param name="frameworkMappings">Additional target framework mappings for parsing target frameworks</param>
        public PackagesConfigReader(IFrameworkNameProvider frameworkMappings, Stream stream, bool leaveStreamOpen)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            _frameworkMappings = frameworkMappings;
            _doc = XDocument.Load(stream);

            if (!leaveStreamOpen)
            {
                stream.Dispose();
            }
        }
        private static void ParseFrameworkNameParts(IFrameworkNameProvider mappings, string[] parts, out string framework, out Version version, out string profile)
        {
            framework = null;
            if (!mappings.TryGetIdentifier(parts[0], out framework))
            {
                framework = parts[0];
            }

            version = new Version(0, 0);
            profile = null;
            var versionPart = SingleOrDefaultSafe(parts.Where(s => s.IndexOf("Version=", StringComparison.OrdinalIgnoreCase) == 0));
            var profilePart = SingleOrDefaultSafe(parts.Where(s => s.IndexOf("Profile=", StringComparison.OrdinalIgnoreCase) == 0));

            if (!string.IsNullOrEmpty(versionPart))
            {
                var versionString = versionPart.Split('=')[1].TrimStart('v');

                if (versionString.IndexOf('.') < 0)
                {
                    versionString += ".0";
                }

                if (!Version.TryParse(versionString, out version))
                {
                    throw new ArgumentException(string.Format(
                                                    CultureInfo.CurrentCulture,
                                                    Strings.InvalidFrameworkVersion,
                                                    versionString));
                }
            }

            if (!string.IsNullOrEmpty(profilePart))
            {
                profile = profilePart.Split('=')[1];
            }

            if (StringComparer.OrdinalIgnoreCase.Equals(FrameworkConstants.FrameworkIdentifiers.Portable, framework) &&
                !string.IsNullOrEmpty(profile) &&
                profile.Contains("-"))
            {
                // Frameworks within the portable profile are not allowed
                // to have profiles themselves #1869
                throw new ArgumentException(string.Format(
                                                CultureInfo.CurrentCulture,
                                                Strings.InvalidPortableFrameworksDueToHyphen,
                                                profile));
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Core package reader
        /// </summary>
        /// <param name="frameworkProvider">framework mapping provider</param>
        /// <param name="compatibilityProvider">framework compatibility provider</param>
        public PackageReaderBase(IFrameworkNameProvider frameworkProvider, IFrameworkCompatibilityProvider compatibilityProvider)
            : base()
        {
            if (frameworkProvider == null)
            {
                throw new ArgumentNullException(nameof(frameworkProvider));
            }

            if (compatibilityProvider == null)
            {
                throw new ArgumentNullException(nameof(compatibilityProvider));
            }

            _frameworkProvider = frameworkProvider;
            _compatibilityProvider = compatibilityProvider;
        }
Exemplo n.º 30
0
        /// <summary>
        /// Creates a NuGetFramework from a .NET FrameworkName
        /// </summary>
        public static NuGetFramework ParseFrameworkName(string frameworkName, IFrameworkNameProvider mappings)
        {
            if (frameworkName == null)
            {
                throw new ArgumentNullException(nameof(frameworkName));
            }

            if (mappings == null)
            {
                throw new ArgumentNullException(nameof(mappings));
            }

            var parts = frameworkName.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray();

            NuGetFramework result = null;

            // if the first part is a special framework, ignore the rest
            if (!TryParseSpecialFramework(parts[0], out result))
            {
                string platform = null;
                if (!mappings.TryGetIdentifier(parts[0], out platform))
                {
                    platform = parts[0];
                }

                var version = new Version(0, 0);
                string profile = null;

                var versionPart = SingleOrDefaultSafe(parts.Where(s => s.IndexOf("Version=", StringComparison.OrdinalIgnoreCase) == 0));
                var profilePart = SingleOrDefaultSafe(parts.Where(s => s.IndexOf("Profile=", StringComparison.OrdinalIgnoreCase) == 0));

                if (!String.IsNullOrEmpty(versionPart))
                {
                    Version.TryParse(versionPart.Split('=')[1].TrimStart('v'), out version);
                }

                if (!String.IsNullOrEmpty(profilePart))
                {
                    profile = profilePart.Split('=')[1];
                }

                result = new NuGetFramework(platform, version, profile);
            }

            return result;
        }
Exemplo n.º 31
0
        /// <summary>
        /// Creates a NuGetFramework from a .NET FrameworkName
        /// </summary>
        public static NuGetFramework ParseFrameworkName(string frameworkName, IFrameworkNameProvider mappings)
        {
            if (frameworkName == null)
            {
                throw new ArgumentNullException(nameof(frameworkName));
            }

            if (mappings == null)
            {
                throw new ArgumentNullException(nameof(mappings));
            }

            var parts = frameworkName.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray();

            NuGetFramework result = null;

            // if the first part is a special framework, ignore the rest
            if (!TryParseSpecialFramework(parts[0], out result))
            {
                string platform = null;
                if (!mappings.TryGetIdentifier(parts[0], out platform))
                {
                    platform = parts[0];
                }

                var    version = new Version(0, 0);
                string profile = null;

                var versionPart = SingleOrDefaultSafe(parts.Where(s => s.IndexOf("Version=", StringComparison.OrdinalIgnoreCase) == 0));
                var profilePart = SingleOrDefaultSafe(parts.Where(s => s.IndexOf("Profile=", StringComparison.OrdinalIgnoreCase) == 0));

                if (!String.IsNullOrEmpty(versionPart))
                {
                    Version.TryParse(versionPart.Split('=')[1].TrimStart('v'), out version);
                }

                if (!String.IsNullOrEmpty(profilePart))
                {
                    profile = profilePart.Split('=')[1];
                }

                result = new NuGetFramework(platform, version, profile);
            }

            return(result);
        }
Exemplo n.º 32
0
        /// <summary>
        /// Packages.config reader
        /// </summary>
        /// <param name="stream">Stream containing packages.config</param>
        /// <param name="leaveStreamOpen">True will leave the stream open</param>
        /// <param name="frameworkMappings">Additional target framework mappings for parsing target frameworks</param>
        public PackagesConfigReader(IFrameworkNameProvider frameworkMappings, Stream stream, bool leaveStreamOpen)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            if (frameworkMappings == null)
            {
                throw new ArgumentNullException(nameof(frameworkMappings));
            }

            _frameworkMappings = frameworkMappings;
            _doc = XDocument.Load(stream);

            if (!leaveStreamOpen)
            {
                stream.Dispose();
            }
        }
Exemplo n.º 33
0
        /// <summary>
        /// Create a packages.config writer using stream
        /// </summary>
        /// <param name="stream">Stream to write the XML packages.config file into, or load existing packages.config from</param>
        /// <param name="createNew">Whether to create a new packages.config file, or load an existing one</param>
        /// <param name="frameworkMappings">Framework mappings</param>
        public PackagesConfigWriter(Stream stream, bool createNew, IFrameworkNameProvider frameworkMappings)
        {
            if (stream == null)
            {
                throw new ArgumentException(nameof(stream));
            }

            _stream            = stream;
            _frameworkMappings = frameworkMappings;

            if (createNew)
            {
                CreateDefaultXDocument();
            }
            // Load the existing packages.config file.
            else
            {
                _xDocument = XDocument.Load(stream);
            }
        }
Exemplo n.º 34
0
        private static Dictionary<NuGetFramework, HashSet<NuGetFramework>> GetTable(IEnumerable<NuGetFramework> frameworks, IFrameworkNameProvider mappings, IFrameworkCompatibilityProvider compat)
        {
            // get the distinct set of frameworks, ignoring all special frameworks like Any, and Unsupported
            var input = new HashSet<NuGetFramework>(frameworks.Where(f => f.IsSpecificFramework), NuGetFramework.Comparer);
            var table = new Dictionary<NuGetFramework, HashSet<NuGetFramework>>(NuGetFramework.Comparer);

            foreach (var framework in input)
            {
                var compatFrameworks = new HashSet<NuGetFramework>(NuGetFramework.Comparer);
                table.Add(framework, compatFrameworks);

                foreach (var testFramework in input)
                {
                    if (compat.IsCompatible(framework, testFramework))
                    {
                        compatFrameworks.Add(testFramework);
                    }
                }
            }

            return table;
        }
        internal static bool IsCompatible(
            NetPortableProfileTable table,
            IFrameworkCompatibilityProvider compatibilityProvider,
            IFrameworkNameProvider nameProvider,
            FrameworkName projectFrameworkName,
            FrameworkName packageTargetFrameworkName)
        {
            if (projectFrameworkName == null)
            {
                return(true);
            }

            var projectNuGetFramework = GetNuGetFramework(
                table,
                nameProvider,
                projectFrameworkName);

            var packageTargetNuGetFramework = GetNuGetFramework(
                table,
                nameProvider,
                packageTargetFrameworkName);

            var isCompatible = compatibilityProvider.IsCompatible(
                projectNuGetFramework,
                packageTargetNuGetFramework);

            // Fallback to legacy portable compatibility logic if both:
            //   a) the modern compatibility code returns false
            //   b) the package framework is portable
            if (!isCompatible && packageTargetFrameworkName.IsPortableFramework())
            {
                return(IsPortableLibraryCompatible(table, projectFrameworkName, packageTargetFrameworkName));
            }

            return(isCompatible);
        }
        /// <summary>
        /// Creates a NuGetFramework from a .NET FrameworkName
        /// </summary>
        public static NuGetFramework ParseFrameworkName(string frameworkName, IFrameworkNameProvider mappings)
        {
            if (frameworkName == null)
            {
                throw new ArgumentNullException(nameof(frameworkName));
            }

            if (mappings == null)
            {
                throw new ArgumentNullException(nameof(mappings));
            }

            var parts = frameworkName.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray();

            NuGetFramework result = null;

            // if the first part is a special framework, ignore the rest
            if (!TryParseSpecialFramework(parts[0], out result))
            {
                string  framework, profile;
                Version version;
                ParseFrameworkNameParts(mappings, parts, out framework, out version, out profile);

                if (version.Major >= 5 &&
                    StringComparer.OrdinalIgnoreCase.Equals(FrameworkConstants.FrameworkIdentifiers.NetCoreApp, framework))
                {
                    result = new NuGetFramework(framework, version, string.Empty, FrameworkConstants.EmptyVersion);
                }
                else
                {
                    result = new NuGetFramework(framework, version, profile);
                }
            }

            return(result);
        }
Exemplo n.º 37
0
 /// <summary>
 /// Nuspec file reader
 /// </summary>
 /// <param name="stream">Nuspec file stream.</param>
 /// <param name="frameworkProvider">Framework mapping provider for NuGetFramework parsing.</param>
 public NuspecReader(Stream stream, IFrameworkNameProvider frameworkProvider, bool leaveStreamOpen)
     : base(stream, leaveStreamOpen)
 {
     _frameworkProvider = frameworkProvider;
 }
Exemplo n.º 38
0
 /// <summary>
 /// Nuspec file reader.
 /// </summary>
 public NuspecReader(string path, IFrameworkNameProvider frameworkProvider)
     : base(path)
 {
     _frameworkProvider = frameworkProvider;
 }
Exemplo n.º 39
0
 /// <summary>
 /// Nupkg package reader
 /// </summary>
 /// <param name="stream">Nupkg data stream.</param>
 /// <param name="frameworkProvider">Framework mapping provider for NuGetFramework parsing.</param>
 /// <param name="compatibilityProvider">Framework compatibility provider.</param>
 public PackageArchiveReader(Stream stream, IFrameworkNameProvider frameworkProvider, IFrameworkCompatibilityProvider compatibilityProvider)
     : this(stream, false)
 {
 }
Exemplo n.º 40
0
 /// <summary>
 /// Core package reader
 /// </summary>
 /// <param name="frameworkProvider">framework mapping provider</param>
 public PackageReaderBase(IFrameworkNameProvider frameworkProvider)
     : this(frameworkProvider, new CompatibilityProvider(frameworkProvider))
 {
 }
Exemplo n.º 41
0
 /// <summary>
 /// Nupkg package reader
 /// </summary>
 /// <param name="stream">Nupkg data stream.</param>
 /// <param name="frameworkProvider">Framework mapping provider for NuGetFramework parsing.</param>
 /// <param name="compatibilityProvider">Framework compatibility provider.</param>
 public PackageReader(Stream stream, IFrameworkNameProvider frameworkProvider, IFrameworkCompatibilityProvider compatibilityProvider)
     : this(stream, false)
 {
 }
Exemplo n.º 42
0
 /// <summary>
 /// Nupkg package reader
 /// </summary>
 /// <param name="stream">Nupkg data stream.</param>
 /// <param name="leaveStreamOpen">leave nupkg stream open</param>
 /// <param name="frameworkProvider">Framework mapping provider for NuGetFramework parsing.</param>
 /// <param name="compatibilityProvider">Framework compatibility provider.</param>
 public PackageReader(Stream stream, bool leaveStreamOpen, IFrameworkNameProvider frameworkProvider, IFrameworkCompatibilityProvider compatibilityProvider)
     : this(new ZipArchive(stream, ZipArchiveMode.Read, leaveStreamOpen), frameworkProvider, compatibilityProvider)
 {
 }
Exemplo n.º 43
0
 public FrameworkExpander(IFrameworkNameProvider mappings)
 {
     _mappings = mappings;
 }
Exemplo n.º 44
0
        /// <summary>
        /// Creates a NuGetFramework from a folder name using the given mappings.
        /// </summary>
        public static NuGetFramework ParseFolder(string folderName, IFrameworkNameProvider mappings)
        {
            if (folderName == null)
            {
                throw new ArgumentNullException(nameof(folderName));
            }

            if (mappings == null)
            {
                throw new ArgumentNullException(nameof(mappings));
            }

            if (folderName.IndexOf('%') > -1)
            {
                folderName = Uri.UnescapeDataString(folderName);
            }

            NuGetFramework result = null;

            // first check if we have a special or common framework
            if (!TryParseSpecialFramework(folderName, out result)
                && !TryParseCommonFramework(folderName, out result))
            {
                // assume this is unsupported unless we find a match
                result = UnsupportedFramework;

                var parts = RawParse(folderName);

                if (parts != null)
                {
                    string framework = null;

                    if (mappings.TryGetIdentifier(parts.Item1, out framework))
                    {
                        var version = FrameworkConstants.EmptyVersion;

                        if (parts.Item2 == null
                            || mappings.TryGetVersion(parts.Item2, out version))
                        {
                            var profileShort = parts.Item3;
                            string profile = null;
                            if (!mappings.TryGetProfile(framework, profileShort, out profile))
                            {
                                profile = profileShort ?? string.Empty;
                            }

                            if (StringComparer.OrdinalIgnoreCase.Equals(FrameworkConstants.FrameworkIdentifiers.Portable, framework))
                            {
                                IEnumerable<NuGetFramework> clientFrameworks = null;
                                mappings.TryGetPortableFrameworks(profileShort, out clientFrameworks);

                                var profileNumber = -1;
                                if (mappings.TryGetPortableProfile(clientFrameworks, out profileNumber))
                                {
                                    var portableProfileNumber = FrameworkNameHelpers.GetPortableProfileNumberString(profileNumber);
                                    result = new NuGetFramework(framework, version, portableProfileNumber);
                                }
                                else
                                {
                                    // TODO: should this be unsupported?
                                    result = new NuGetFramework(framework, version, profileShort);
                                }
                            }
                            else
                            {
                                result = new NuGetFramework(framework, version, profile);
                            }
                        }
                    }
                }
                else
                {
                    // If the framework was not recognized check if it is a deprecated framework
                    NuGetFramework deprecated = null;

                    if (TryParseDeprecatedFramework(folderName, out deprecated))
                    {
                        result = deprecated;
                    }
                }
            }

            return result;
        }
Exemplo n.º 45
0
 public CompatibilityProvider(IFrameworkNameProvider mappings)
 {
     _mappings = mappings;
     _expander = new FrameworkExpander(mappings);
     _cache = new ConcurrentDictionary<int, bool>();
 }
Exemplo n.º 46
0
 /// <summary>
 /// Nuspec file reader
 /// </summary>
 /// <param name="xml">Nuspec file xml data.</param>
 /// <param name="frameworkProvider">Framework mapping provider for NuGetFramework parsing.</param>
 public NuspecReader(XDocument xml, IFrameworkNameProvider frameworkProvider)
     : base(xml)
 {
     _frameworkProvider = frameworkProvider;
 }
Exemplo n.º 47
0
 /// <summary>
 /// Package folder reader
 /// </summary>
 /// <param name="folderPath">root directory of an extracted nupkg</param>
 /// <param name="frameworkProvider">framework mappings</param>
 /// <param name="compatibilityProvider">framework compatibility provider</param>
 public PackageFolderReader(string folderPath, IFrameworkNameProvider frameworkProvider, IFrameworkCompatibilityProvider compatibilityProvider)
     : this(new DirectoryInfo(folderPath), frameworkProvider, compatibilityProvider)
 {
 }
Exemplo n.º 48
0
 /// <summary>
 /// Package folder reader
 /// </summary>
 /// <param name="folder">root directory of an extracted nupkg</param>
 /// <param name="frameworkProvider">framework mappings</param>
 /// <param name="compatibilityProvider">framework compatibility provider</param>
 public PackageFolderReader(DirectoryInfo folder, IFrameworkNameProvider frameworkProvider, IFrameworkCompatibilityProvider compatibilityProvider)
     : base(frameworkProvider, compatibilityProvider)
 {
     _root = folder;
 }
Exemplo n.º 49
0
 /// <summary>
 /// Nuspec file reader
 /// </summary>
 /// <param name="stream">Nuspec file stream.</param>
 /// <param name="frameworkProvider">Framework mapping provider for NuGetFramework parsing.</param>
 public NuspecReader(Stream stream, IFrameworkNameProvider frameworkProvider)
     : base(stream)
 {
     _frameworkProvider = frameworkProvider;
 }
Exemplo n.º 50
0
 /// <summary>
 /// Nuspec file reader
 /// </summary>
 /// <param name="xml">Nuspec file xml data.</param>
 /// <param name="frameworkProvider">Framework mapping provider for NuGetFramework parsing.</param>
 public NuspecReader(XDocument xml, IFrameworkNameProvider frameworkProvider)
     : base(xml)
 {
     _frameworkProvider = frameworkProvider;
 }