Beispiel #1
0
        private bool CheckTargetFrameworks(TextWriter textWriter, RoslynProjectData data)
        {
            if (!data.IsAnyUnitTest)
            {
                return(true);
            }

            var allGood = true;

            foreach (var targetFramework in _projectUtil.GetAllTargetFrameworks())
            {
                switch (targetFramework)
                {
                case "net20":
                case "net46":
                case "net461":
                case "net462":
                case "netstandard1.3":
                case "netcoreapp1.1":
                case "netcoreapp2.0":
                case "$(RoslynPortableTargetFrameworks)":
                    break;

                default:
                    textWriter.WriteLine($"TargetFramework {targetFramework} is not supported in this build");
                    allGood = false;
                    break;
                }
            }

            return(allGood);
        }
Beispiel #2
0
        private bool IsVsixCorrectlySpecified(TextWriter textWriter, RoslynProjectData data)
        {
            var element = _projectUtil.FindSingleProperty("ProjectTypeGuids");

            if (element == null)
            {
                return(true);
            }

            foreach (var rawValue in element.Value.Split(';'))
            {
                var value = rawValue.Trim();
                if (string.IsNullOrEmpty(value))
                {
                    continue;
                }

                var guid = Guid.Parse(value);
                if (guid == ProjectEntryUtil.VsixProjectType && data.EffectiveKind != RoslynProjectKind.Vsix)
                {
                    textWriter.WriteLine("Vsix projects must specify <RoslynProjectType>Vsix</RoslynProjectType>");
                    return(false);
                }
            }

            return(true);
        }
Beispiel #3
0
 private bool ParseRoslynProjectData(TextWriter textWriter, out RoslynProjectData data)
 {
     try
     {
         data = _projectUtil.GetRoslynProjectData();
         return(true);
     }
     catch (Exception ex)
     {
         data = default(RoslynProjectData);
         textWriter.WriteLine(ex.Message);
         return(false);
     }
 }
Beispiel #4
0
 private bool ParseRoslynProjectData(TextWriter textWriter, out RoslynProjectData data)
 {
     try
     {
         data = _projectUtil.GetRoslynProjectData();
         return true;
     }
     catch (Exception ex)
     {
         data = default(RoslynProjectData);
         textWriter.WriteLine(ex.Message);
         return false;
     }
 }
Beispiel #5
0
        private bool IsUnitTestPortableCorrectlySpecified(TextWriter textWriter, RoslynProjectData data)
        {
            if (!data.IsAnyUnitTest)
            {
                return(true);
            }

            if (data.EffectiveKind == RoslynProjectKind.UnitTest && _projectUtil.GetTargetFrameworks() != null)
            {
                textWriter.WriteLine($"UnitTestPortable needs to be specified when using TargetFrameworks on a unit test project");
                return(false);
            }

            return(true);
        }
Beispiel #6
0
        /// <summary>
        /// Our infrastructure depends on test assembly names having a very specific set of
        /// suffixes: UnitTest and IntegrationTests. This check will verify that both test assemblies
        /// are properly named and non-test assemblies are not incorrectly named.
        /// </summary>
        private bool IsUnitTestNameCorrectlySpecified(TextWriter textWriter, RoslynProjectData data)
        {
            if (ProjectType != ProjectFileType.CSharp && ProjectType != ProjectFileType.Basic)
            {
                return(true);
            }

            if (data.EffectiveKind == RoslynProjectKind.Depedency)
            {
                return(true);
            }

            string name    = null;
            var    element = _projectUtil.FindSingleProperty("AssemblyName");

            if (element != null)
            {
                name = element.Value.Trim();
            }
            else if (_projectUtil.IsNewSdk)
            {
                name = Path.GetFileNameWithoutExtension(_data.FileName);
            }
            else
            {
                textWriter.WriteLine($"Need to specify AssemblyName");
                return(false);
            }

            if (Regex.IsMatch(name, @"(UnitTests|IntegrationTests)$", RegexOptions.IgnoreCase) && !data.IsAnyUnitTest)
            {
                textWriter.WriteLine($"Assembly named {name} is not marked as a unit test");
                return(false);
            }

            if (data.IsAnyUnitTest && !Regex.IsMatch(name, @".*(UnitTests|IntegrationTests)$", RegexOptions.IgnoreCase))
            {
                textWriter.WriteLine($"Assembly {name} is a unit test that doesn't end with UnitTests.dll");
                return(false);
            }

            return(true);
        }
Beispiel #7
0
        private bool CheckTargetFrameworks(TextWriter textWriter, RoslynProjectData data)
        {
            if (!data.IsAnyUnitTest)
            {
                return(true);
            }

            var allGood = true;

            foreach (var targetFramework in _projectUtil.GetAllTargetFrameworks())
            {
                // TODO: Code Style projects need to be moved over to 4.7.2 and netstandard2.0
                // https://devdiv.visualstudio.com/DevDiv/_workitems/edit/712825
                if (ProjectFilePath.Contains("CodeStyle"))
                {
                    switch (targetFramework)
                    {
                    case "net46":
                    case "netstandard1.3":
                        continue;
                    }
                }
                else
                {
                    switch (targetFramework)
                    {
                    case "net20":
                    case "net472":
                    case "netcoreapp1.1":
                    case "netcoreapp2.1":
                    case "netcoreapp3.0":
                    case "$(RoslynPortableTargetFrameworks)":
                        continue;
                    }
                }

                textWriter.WriteLine($"TargetFramework {targetFramework} is not supported in this build");
                allGood = false;
            }

            return(allGood);
        }
Beispiel #8
0
        internal bool TryGetRoslynProjectData(out RoslynProjectData data, out string error)
        {
            data  = default(RoslynProjectData);
            error = null;

            var typeElement = FindSingleProperty("RoslynProjectType");

            if (typeElement != null)
            {
                var value = typeElement.Value.Trim();
                var kind  = RoslynProjectKindUtil.GetRoslynProjectKind(value);
                if (kind == null)
                {
                    error = $"The value {value} is illegal for element <RoslynProjectType>";
                    return(false);
                }

                data = new RoslynProjectData(kind.Value, kind.Value, value);
                return(true);
            }
            else
            {
                var outputType = FindSingleProperty("OutputType");
                switch (outputType?.Value.Trim())
                {
                case "Exe":
                case "WinExe":
                    data = new RoslynProjectData(RoslynProjectKind.Exe);
                    return(true);

                case "Library":
                    data = new RoslynProjectData(RoslynProjectKind.Dll);
                    return(true);

                default:
                    error = $"The value {outputType?.Value.Trim()} is not a recognized value of OutputType";
                    return(false);
                }
            }
        }
Beispiel #9
0
        private bool IsUnitTestCorrectlySpecified(TextWriter textWriter, RoslynProjectData data)
        {
            if (ProjectType != ProjectFileType.CSharp && ProjectType != ProjectFileType.Basic)
            {
                return(true);
            }

            if (data.EffectiveKind == RoslynProjectKind.Depedency)
            {
                return(true);
            }

            var element = _projectUtil.FindSingleProperty("AssemblyName");

            if (element == null)
            {
                textWriter.WriteLine($"Need to specify AssemblyName");
                return(false);
            }

            var name = element.Value.Trim();

            if (Regex.IsMatch(name, @"UnitTest(s?)\.dll", RegexOptions.IgnoreCase))
            {
                switch (data.EffectiveKind)
                {
                case RoslynProjectKind.UnitTest:
                case RoslynProjectKind.UnitTestNext:
                    // This is correct
                    break;

                default:
                    textWriter.WriteLine($"Assembly named {name} is not marked as a unit test");
                    return(false);
                }
            }

            return(true);
        }
Beispiel #10
0
        private bool ParseRoslynProjectData(TextWriter textWriter, out RoslynProjectData data)
        {
            data = default(RoslynProjectData);

            var typeElement = FindSingleProperty("RoslynProjectType");

            if (typeElement != null)
            {
                var value = typeElement.Value.Trim();
                var kind  = RoslynProjectData.GetRoslynProjectKind(value);
                if (kind == null)
                {
                    textWriter.WriteLine($"Unrecognized RoslynProjectKnid value {value}");
                    return(false);
                }

                data = new RoslynProjectData(kind.Value, kind.Value, value);
                return(true);
            }
            else
            {
                var outputType = FindSingleProperty("OutputType");
                switch (outputType?.Value.Trim())
                {
                case "Exe":
                case "WinExe":
                    data = new RoslynProjectData(RoslynProjectKind.Exe);
                    return(true);

                case "Library":
                    data = new RoslynProjectData(RoslynProjectKind.Dll);
                    return(true);

                default:
                    textWriter.WriteLine($"Unrecognized OutputType value {outputType?.Value.Trim()}");
                    return(false);
                }
            }
        }
Beispiel #11
0
        internal bool TryGetRoslynProjectData(out RoslynProjectData data, out string error)
        {
            data = default(RoslynProjectData);
            error = null;

            var typeElement = FindSingleProperty("RoslynProjectType");
            if (typeElement != null)
            {
                var value = typeElement.Value.Trim();
                var kind = RoslynProjectKindUtil.GetRoslynProjectKind(value);
                if (kind == null)
                {
                    error = $"The value {value} is illegal for element <RoslynProjectType>";
                    return false;
                }

                data = new RoslynProjectData(kind.Value, kind.Value, value);
                return true;
            }
            else
            { 
                var outputType = FindSingleProperty("OutputType");
                switch (outputType?.Value.Trim())
                {
                    case "Exe":
                    case "WinExe":
                        data = new RoslynProjectData(RoslynProjectKind.Exe);
                        return true;
                    case "Library":
                        data = new RoslynProjectData(RoslynProjectKind.Dll);
                        return true;
                    default:
                        error = $"The value {outputType?.Value.Trim()} is not a recognized value of OutputType";
                        return false;
                }
            }
        }
Beispiel #12
0
        private bool IsUnitTestCorrectlySpecified(TextWriter textWriter, RoslynProjectData data)
        {
            if (ProjectType != ProjectFileType.CSharp && ProjectType != ProjectFileType.Basic)
            {
                return true;
            }

            if (data.EffectiveKind == RoslynProjectKind.Depedency)
            {
                return true;
            }

            var element = _projectUtil.FindSingleProperty("AssemblyName");
            if (element == null)
            {
                textWriter.WriteLine($"Need to specify AssemblyName");
                return false;
            }

            var name = element.Value.Trim();
            if (Regex.IsMatch(name, @"(UnitTests|IntegrationTests)$", RegexOptions.IgnoreCase) && !data.IsAnyUnitTest)
            {
                textWriter.WriteLine($"Assembly named {name} is not marked as a unit test");
                return false;
            }

            if (data.IsAnyUnitTest && !Regex.IsMatch(name, @".*(UnitTests|IntegrationTests)$", RegexOptions.IgnoreCase))
            {
                textWriter.WriteLine($"Assembly {name} is a unit test that doesn't end with UnitTests.dll");
                return false;
            }

            return true;
        }
Beispiel #13
0
        private bool IsVsixCorrectlySpecified(TextWriter textWriter, RoslynProjectData data)
        {
            var element = _projectUtil.FindSingleProperty("ProjectTypeGuids");
            if (element == null)
            {
                return true;
            }

            foreach (var rawValue in element.Value.Split(';'))
            {
                var value = rawValue.Trim();
                if (string.IsNullOrEmpty(value))
                {
                    continue;
                }

                var guid = Guid.Parse(value);
                if (guid == ProjectEntryUtil.VsixProjectType && data.EffectiveKind != RoslynProjectKind.Vsix)
                {
                    textWriter.WriteLine("Vsix projects must specify <RoslynProjectType>Vsix</RoslynProjectType>");
                    return false;
                }
            }

            return true;
        }
Beispiel #14
0
        private bool IsUnitTestCorrectlySpecified(TextWriter textWriter, RoslynProjectData data)
        {
            if (ProjectType != ProjectFileType.CSharp && ProjectType != ProjectFileType.Basic)
            {
                return true;
            }

            if (data.EffectiveKind == RoslynProjectKind.Depedency)
            {
                return true;
            }

            var element = _projectUtil.FindSingleProperty("AssemblyName");
            if (element == null)
            {
                textWriter.WriteLine($"Need to specify AssemblyName");
                return false;
            }

            var name = element.Value.Trim();
            if (Regex.IsMatch(name, @"UnitTest(s?)\.dll", RegexOptions.IgnoreCase))
            {
                switch (data.EffectiveKind)
                {
                    case RoslynProjectKind.UnitTest:
                    case RoslynProjectKind.UnitTestNext:
                        // This is correct
                        break;
                    default:
                        textWriter.WriteLine($"Assembly named {name} is not marked as a unit test");
                        return false;
                }
            }

            return true;
        }