CreateWorkspace() private static method

private static CreateWorkspace ( string>.ImmutableDictionary propertiesOpt = null ) : MSBuildWorkspace
propertiesOpt string>.ImmutableDictionary
return MSBuildWorkspace
Exemplo n.º 1
0
        private IEnumerable <Tuple <string, string, string> > GetTypeForwardsImpl(string path, IReadOnlyDictionary <string, string> properties)
        {
            var      workspace = SolutionGenerator.CreateWorkspace(properties.ToImmutableDictionary());
            Solution solution;

            if (path.EndsWith(".sln"))
            {
                solution = workspace.OpenSolutionAsync(path).GetAwaiter().GetResult();
            }
            else
            {
                solution = workspace.OpenProjectAsync(path).GetAwaiter().GetResult().Solution;
            }

            var assemblies = solution.Projects.Select(p => p.OutputFilePath).ToList();

            foreach (var assemblyFile in assemblies)
            {
                if (File.Exists(assemblyFile))
                {
                    Log.Write("File exists: " + assemblyFile);
                }
                else
                {
                    Log.Write("File doesn't exist: " + assemblyFile);
                    continue;
                }

                foreach (Tuple <string, string, string> tuple in ReadTypeForwardsFromAssembly(assemblyFile))
                {
                    yield return(tuple);
                }
            }
        }
Exemplo n.º 2
0
        private IEnumerable <Tuple <string, string, string> > GetTypeForwardsImpl(string path, IReadOnlyDictionary <string, string> properties)
        {
            var      workspace = SolutionGenerator.CreateWorkspace(properties.ToImmutableDictionary());
            Solution solution;

            if (path.EndsWith(".sln"))
            {
                solution = workspace.OpenSolutionAsync(path).GetAwaiter().GetResult();
            }
            else
            {
                solution = workspace.OpenProjectAsync(path).GetAwaiter().GetResult().Solution;
            }

            var assemblies = solution.Projects.Select(p => p.OutputFilePath).ToList();

            foreach (var assemblyFile in assemblies)
            {
                if (File.Exists(assemblyFile))
                {
                    Log.Write("File exists: " + assemblyFile);
                }
                else
                {
                    Log.Write("File doesn't exist: " + assemblyFile);
                    continue;
                }

                var thisAssemblyName = Path.GetFileNameWithoutExtension(assemblyFile);
                using (var peReader = new PEReader(File.ReadAllBytes(assemblyFile).ToImmutableArray()))
                {
                    var reader = peReader.GetMetadataReader();
                    foreach (var exportedTypeHandle in reader.ExportedTypes)
                    {
                        var exportedType = reader.GetExportedType(exportedTypeHandle);
                        var result       = ProcessExportedType(exportedType, reader, thisAssemblyName);
                        if (result != null)
                        {
                            Log.Write(result.ToString());
                            yield return(result);
                        }
                    }
                }
            }
        }