コード例 #1
0
        private static IEnumerable <string> GetPackageContents(string vsixName)
        {
            var rootPath = RepoUtil.FindRepoRootPath();

#if DEBUG
            var config = "Debug";
#elif RELEASE
            var config = "Release";
#else
#error Unexpected configuration
#endif

            // D:\repos\project-system\artifacts\Debug\VSSetup\ProjectSystem.vsix

            var vsixPath = Path.Combine(
                rootPath,
                "artifacts",
                config,
                "VSSetup",
                "Insertion",
                vsixName);

            using var archive = ZipFile.OpenRead(vsixPath);

            return(archive.Entries.Select(entry => entry.FullName).OrderBy(fn => fn));
        }
コード例 #2
0
        public void ResourceCodeGenHasCorrectBaseName(string sourcePath, string baseName)
        {
            // Resx code generation does not respect <LogicalName> metadata on <EmbeddedResource />.
            // This can result in an incorrect base name being used in generated code.
            //
            // https://github.com/dotnet/project-system/issues/1058
            //
            // To prevent this from happening unwittingly (eg. https://github.com/dotnet/project-system/issues/6180)
            // this test ensures the expected name is used. This will catch cases when code gen
            // produces invalid code before merging/insertion.

            string pattern = sourcePath.Substring(sourcePath.Length - 2, 2) switch
            {
                "cs" => $"global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager(\"{baseName}\"",
                "vb" => $"Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager(\"{baseName}\"",
                string format => throw new Exception("Unexpected source file format: " + format)
            };

            string path = Path.Combine(RepoUtil.FindRepoRootPath(), sourcePath);

            foreach (string line in File.ReadLines(path))
            {
                if (line.Contains(pattern))
                {
                    return;
                }
            }

            throw new XunitException($"Expected base name \"{baseName}\" not found in generated file: {sourcePath}");
        }
    }
コード例 #3
0
        protected static IEnumerable <string> GetRules(string suffix, bool recursive = false)
        {
            // Not all rules are embedded as manifests so we have to read the xaml files from the file system.
            string rulesPath = Path.Combine(RepoUtil.FindRepoRootPath(), "src", "Microsoft.VisualStudio.ProjectSystem.Managed", "ProjectSystem", "Rules");

            if (!string.IsNullOrEmpty(suffix))
            {
                rulesPath = Path.Combine(rulesPath, suffix);
            }

            Assert.True(Directory.Exists(rulesPath), "Couldn't find XAML rules folder: " + rulesPath);

            var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;

            foreach (var filePath in Directory.EnumerateFiles(rulesPath, "*.xaml", searchOption))
            {
                XElement rule = LoadXamlRule(filePath);

                // Ignore XAML documents for non-Rule types (such as ProjectSchemaDefinitions)
                if (rule.Name.LocalName != "Rule")
                {
                    continue;
                }

                yield return(filePath);
            }
        }
コード例 #4
0
        public static IEnumerable <object[]> GetRules(string suffix, bool file, bool browseObject)
        {
            // Not all rules are embedded as manifests so we have to read the xaml files from the file system.
            string rulesPath = Path.Combine(RepoUtil.FindRepoRootPath(), "src", "Microsoft.VisualStudio.ProjectSystem.Managed", "ProjectSystem", "Rules");

            Assert.True(Directory.Exists(rulesPath), "Couldn't find XAML rules folder: " + rulesPath);

            if (!string.IsNullOrEmpty(suffix))
            {
                rulesPath = Path.Combine(rulesPath, suffix);
            }
            foreach (var fileName in Directory.EnumerateFiles(rulesPath, "*.xaml"))
            {
                if (fileName.EndsWith(".BrowseObject.xaml", StringComparisons.Paths) && !browseObject)
                {
                    continue;
                }
                // Special case for Folder because it is File and BrowseObject context (for now) but naming convention is like File
                if ((!fileName.EndsWith(".BrowseObject.xaml", StringComparisons.Paths) && !file) ||
                    (fileName.EndsWith("Folder.xaml", StringComparisons.Paths) && browseObject))
                {
                    continue;
                }

                // we return the rule name separately mainly to get a readable display in Test Explorer so failures can be diagnosed more easily
                yield return(new object[] { Path.GetFileNameWithoutExtension(fileName), fileName });
            }
        }