Example #1
0
        public void TryParse_VersionIsEmptyString()
        {
            DotNetCoreVersion version = null;
            bool result = DotNetCoreVersion.TryParse(string.Empty, out version);

            Assert.IsFalse(result);
        }
Example #2
0
        public void TryParse_NullVersion()
        {
            DotNetCoreVersion version = null;
            bool result = DotNetCoreVersion.TryParse(null, out version);

            Assert.IsFalse(result);
        }
Example #3
0
        public void TryParse_InvalidVersion()
        {
            DotNetCoreVersion version = null;
            bool result = DotNetCoreVersion.TryParse("INVALID", out version);

            Assert.IsFalse(result);
        }
Example #4
0
        public void CheckSupportedSdkVersion(string version, bool isSupported)
        {
            if (!DotNetCoreVersion.TryParse(version, out var dotnetCoreVersion))
            {
                Assert.Inconclusive("Unable to parse {0}", version);
            }

            var result = DotNetCoreVersion.IsSdkSupported(dotnetCoreVersion);

            Assert.True(result == isSupported);
        }
Example #5
0
        /// <summary>
        /// Only .NET Core SDKs 2.1/2.2/3.0 are supported.
        /// </summary>
        string GetDotNetCoreSdkTemplatesDirectory(string tag)
        {
            DotNetCoreVersion dotNetCoreSdk = null;

            foreach (var sdk in SupportedSDK)
            {
                if (tag.StartsWith($"DotNetCoreSdk.{sdk}", StringComparison.OrdinalIgnoreCase))
                {
                    dotNetCoreSdk = GetDotNetCoreSdkVersion(DotNetCoreVersion.Parse(sdk));
                    break;
                }
            }

            if (dotNetCoreSdk == null)
            {
                return(null);
            }

            string templatesDirectory = Path.Combine(
                DotNetCoreSdk.SdkRootPath,
                dotNetCoreSdk.OriginalString,
                "Templates"
                );

            if (!DirectoryExists(templatesDirectory))
            {
                // .NET Core 3.0 Preview 8 and higher place templates in the root dir
                // and versioned by runtime, not SDK
                var baseTemplatesDir = Path.Combine(Directory.GetParent(DotNetCoreSdk.SdkRootPath).FullName, "templates");
                if (DirectoryExists(baseTemplatesDir))
                {
                    var availableTemplates = new Dictionary <DotNetCoreVersion, string> ();
                    foreach (var dir in EnumerateDirectories(baseTemplatesDir))
                    {
                        if (DotNetCoreVersion.TryParse(Path.GetFileName(dir), out var version))
                        {
                            availableTemplates [version] = dir;
                        }
                    }

                    templatesDirectory = availableTemplates.Keys
                                         .Where(v => v.Major < dotNetCoreSdk.Major || (v.Major == dotNetCoreSdk.Major && v.Minor <= dotNetCoreSdk.Minor))
                                         .OrderByDescending(v => v)
                                         .Select(v => availableTemplates [v])
                                         .FirstOrDefault();
                }
            }

            return(DirectoryExists(templatesDirectory) ? templatesDirectory : string.Empty);
        }