Exemple #1
0
        private void SetTypeAndVersion(string targetValue)
        {
            if (targetValue.StartsWith(TargetValuePrefix.Core, true, CultureInfo.InvariantCulture))
            {
                Type    = TargetType.Core;
                Version = targetValue.Substring(TargetValuePrefix.Core.Length);
                return;
            }

            if (targetValue.StartsWith(TargetValuePrefix.Standard, true, CultureInfo.InvariantCulture))
            {
                Type    = TargetType.Standard;
                Version = targetValue.Substring(TargetValuePrefix.Standard.Length);
                return;
            }

            if (targetValue.StartsWith(TargetValuePrefix.FrameworkNew, true, CultureInfo.InvariantCulture))
            {
                Type    = TargetType.Framework;
                Version = VersionNumberFormatter.Format(TargetValue.Substring(TargetValuePrefix.FrameworkNew.Length));
                return;
            }

            if (targetValue.StartsWith(TargetValuePrefix.FrameworkOld, true, CultureInfo.InvariantCulture))
            {
                Type    = TargetType.Framework;
                Version = targetValue.Substring(TargetValuePrefix.FrameworkOld.Length);
                return;
            }

            throw new InvalidDotNetProjectException($"Could not determine {nameof(Type)} from '{targetValue}'.");
        }
Exemple #2
0
        private void SetVersionWindowsPhone()
        {
            if (Moniker.StartsWith("wpa", true, CultureInfo.InvariantCulture))
            {
                // wpa81
                Version = VersionNumberFormatter.Format(Moniker.Substring(3));
            }
            else if (Moniker.StartsWith("wp [", true, CultureInfo.InvariantCulture))
            {
                // wp [wp71]
                var startIndex = Moniker.IndexOf("[wp", StringComparison.Ordinal);
                var endIndex   = Moniker.IndexOf("]", StringComparison.Ordinal);

                if (endIndex < 1)
                {
                    Version = string.Empty;
                }
                else
                {
                    var ver = Moniker.Substring(startIndex + 3, endIndex - startIndex - 3);
                    Version = VersionNumberFormatter.Format(ver);
                }
            }
            else
            {
                Version = VersionNumberFormatter.Format(Moniker.Substring(2));
            }
        }
Exemple #3
0
        private void SetVersionUniversalWindowsPlatform()
        {
            if (Moniker.StartsWith("uap [", true, CultureInfo.InvariantCulture))
            {
                // uap [uap10.0]
                var startIndex = Moniker.IndexOf("[uap", StringComparison.Ordinal);
                var endIndex   = Moniker.IndexOf("]", StringComparison.Ordinal);

                if (endIndex > 0)
                {
                    var ver = Moniker.Substring(startIndex + 4, endIndex - startIndex - 4);
                    Version = VersionNumberFormatter.Format(ver);
                }
            }
            else
            {
                // uap10.0 [win10] [netcore50]
                var startIndex = Moniker.IndexOf("[", StringComparison.Ordinal);

                if (startIndex < 1)
                {
                    Version = VersionNumberFormatter.Format(Moniker.Substring(3));
                }
                else
                {
                    Version = VersionNumberFormatter.Format(Moniker.Substring(3, startIndex - 3));
                }
            }
        }
Exemple #4
0
        private void SetVersionWindowsStore()
        {
            if (Moniker.StartsWith("netcore [", true, CultureInfo.InvariantCulture))
            {
                // netcore [netcore45]
                var startIndex = Moniker.IndexOf("[netcore", StringComparison.Ordinal);
                var endIndex   = Moniker.IndexOf("]", StringComparison.Ordinal);

                if (endIndex > 0)
                {
                    var ver = Moniker.Substring(startIndex + 8, endIndex - startIndex - 8);
                    Version = VersionNumberFormatter.Format(ver);
                }
            }
            else
            {
                // netcore451 [win81]
                // netcore451
                var startIndex = Moniker.IndexOf("[", StringComparison.Ordinal);

                if (startIndex < 1)
                {
                    Version = VersionNumberFormatter.Format(Moniker.Substring(7));
                }
                else
                {
                    Version = VersionNumberFormatter.Format(Moniker.Substring(7, startIndex - 7));
                }
            }
        }
Exemple #5
0
        private void SetTypeAndVersion()
        {
            FrameworkType = TargetFrameworkType.Unknown;
            Version       = string.Empty;

            if (Moniker.StartsWith("net6", true, CultureInfo.InvariantCulture) ||
                Moniker.StartsWith("net5", true, CultureInfo.InvariantCulture))
            {
                FrameworkType = TargetFrameworkType.Core;
                SetVersionDotNet5Plus();
            }
            else if (Moniker.StartsWith("netcoreapp", true, CultureInfo.InvariantCulture))
            {
                FrameworkType = TargetFrameworkType.Core;
                Version       = Moniker.Substring(10);
            }
            else if (Moniker.StartsWith("netstandard", true, CultureInfo.InvariantCulture))
            {
                FrameworkType = TargetFrameworkType.Standard;
                Version       = Moniker.Substring(11);
            }
            else if (Moniker.StartsWith("netmf", true, CultureInfo.InvariantCulture))
            {
                FrameworkType = TargetFrameworkType.MicroFramework;
            }
            else if (Moniker.StartsWith("v", true, CultureInfo.InvariantCulture))
            {
                FrameworkType = TargetFrameworkType.Framework;
                Version       = Moniker.Substring(1);
            }
            else if (Moniker.StartsWith("sl", true, CultureInfo.InvariantCulture))
            {
                FrameworkType = TargetFrameworkType.Silverlight;
                Version       = Moniker.Substring(2);
            }
            else if (Moniker.StartsWith("wp", true, CultureInfo.InvariantCulture))
            {
                FrameworkType = TargetFrameworkType.WindowsPhone;
                SetVersionWindowsPhone();
            }
            else if (Moniker.StartsWith("uap", true, CultureInfo.InvariantCulture))
            {
                FrameworkType = TargetFrameworkType.UniversalWindowsPlatform;
                SetVersionUniversalWindowsPlatform();
            }
            else if (Moniker.StartsWith("netcore", true, CultureInfo.InvariantCulture))
            {
                FrameworkType = TargetFrameworkType.WindowsStore;
                SetVersionWindowsStore();
            }
            else if (Moniker.StartsWith("net", true, CultureInfo.InvariantCulture))
            {
                FrameworkType = TargetFrameworkType.Framework;
                Version       = VersionNumberFormatter.Format(Moniker.Substring(3));
            }
        }
        private void SetDescription()
        {
            switch (Type)
            {
            case TargetType.Framework:
                Description = _isOldStyleFormat ?
                              $".NET Framework {TargetValue.Substring(TargetValuePrefix.FrameworkOld.Length)}" :
                              $".NET Framework {VersionNumberFormatter.Format(TargetValue.Substring(TargetValuePrefix.FrameworkNew.Length))}";
                break;

            case TargetType.Core:
                Description = $".NET Core {TargetValue.Substring(TargetValuePrefix.Core.Length)}";
                break;

            case TargetType.Standard:
                Description = $".NET Standard {TargetValue.Substring(TargetValuePrefix.Standard.Length)}";
                break;

            default:
                throw new InvalidOperationException($"Unhandled {nameof(TargetType)}: {Type}.");
            }
        }