Пример #1
0
            private static ImmutableArray <PackageReference> GetPackageReferences(ICollection <MSB.Execution.ProjectItemInstance> items)
            {
                var builder  = ImmutableArray.CreateBuilder <PackageReference>(items.Count);
                var addedSet = new HashSet <PackageReference>();

                foreach (var item in items)
                {
                    var name         = item.EvaluatedInclude;
                    var versionValue = item.GetMetadataValue(MetadataNames.Version);
                    var versionRange = PropertyConverter.ToVersionRange(versionValue);
                    var dependency   = new PackageDependency(name, versionRange);

                    var isImplicitlyDefinedValue = item.GetMetadataValue(MetadataNames.IsImplicitlyDefined);
                    var isImplicitlyDefined      = PropertyConverter.ToBoolean(isImplicitlyDefinedValue, defaultValue: false);

                    var packageReference = new PackageReference(dependency, isImplicitlyDefined);

                    if (addedSet.Add(packageReference))
                    {
                        builder.Add(packageReference);
                    }
                }

                return(builder.ToImmutable());
            }
Пример #2
0
        private static ProjectData CreateProjectData(ProjectInstance projectInstance, ImmutableArray <string> targetFrameworks)
        {
            var guid              = PropertyConverter.ToGuid(projectInstance.GetPropertyValue(PropertyNames.ProjectGuid));
            var name              = projectInstance.GetPropertyValue(PropertyNames.ProjectName);
            var assemblyName      = projectInstance.GetPropertyValue(PropertyNames.AssemblyName);
            var targetPath        = projectInstance.GetPropertyValue(PropertyNames.TargetPath);
            var outputPath        = projectInstance.GetPropertyValue(PropertyNames.OutputPath);
            var projectAssetsFile = projectInstance.GetPropertyValue(PropertyNames.ProjectAssetsFile);

            var targetFramework = new FrameworkName(projectInstance.GetPropertyValue(PropertyNames.TargetFrameworkMoniker));

            var languageVersion           = PropertyConverter.ToLanguageVersion(projectInstance.GetPropertyValue(PropertyNames.LangVersion));
            var allowUnsafeCode           = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.AllowUnsafeBlocks), defaultValue: false);
            var outputKind                = PropertyConverter.ToOutputKind(projectInstance.GetPropertyValue(PropertyNames.OutputType));
            var documentationFile         = projectInstance.GetPropertyValue(PropertyNames.DocumentationFile);
            var preprocessorSymbolNames   = PropertyConverter.ToPreprocessorSymbolNames(projectInstance.GetPropertyValue(PropertyNames.DefineConstants));
            var suppressDiagnosticIds     = PropertyConverter.ToSuppressDiagnosticIds(projectInstance.GetPropertyValue(PropertyNames.NoWarn));
            var signAssembly              = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.SignAssembly), defaultValue: false);
            var assemblyOriginatorKeyFile = projectInstance.GetPropertyValue(PropertyNames.AssemblyOriginatorKeyFile);

            var sourceFiles       = GetFullPaths(projectInstance.GetItems(ItemNames.Compile));
            var projectReferences = GetFullPaths(projectInstance.GetItems(ItemNames.ProjectReference));
            var references        = GetFullPaths(
                projectInstance.GetItems(ItemNames.ReferencePath).Where(ReferenceSourceTargetIsNotProjectReference));
            var packageReferences = GetPackageReferences(projectInstance.GetItems(ItemNames.PackageReference));
            var analyzers         = GetFullPaths(projectInstance.GetItems(ItemNames.Analyzer));

            return(new ProjectData(guid, name,
                                   assemblyName, targetPath, outputPath, projectAssetsFile,
                                   targetFramework, targetFrameworks,
                                   outputKind, languageVersion, allowUnsafeCode, documentationFile, preprocessorSymbolNames, suppressDiagnosticIds,
                                   signAssembly, assemblyOriginatorKeyFile,
                                   sourceFiles, projectReferences, references, packageReferences, analyzers));
        }
            public static ProjectData Create(MSB.Evaluation.Project project)
            {
                var guid              = PropertyConverter.ToGuid(project.GetPropertyValue(PropertyNames.ProjectGuid));
                var name              = project.GetPropertyValue(PropertyNames.ProjectName);
                var assemblyName      = project.GetPropertyValue(PropertyNames.AssemblyName);
                var targetPath        = project.GetPropertyValue(PropertyNames.TargetPath);
                var outputPath        = project.GetPropertyValue(PropertyNames.OutputPath);
                var projectAssetsFile = project.GetPropertyValue(PropertyNames.ProjectAssetsFile);

                var targetFramework = new FrameworkName(project.GetPropertyValue(PropertyNames.TargetFrameworkMoniker));

                var targetFrameworkValue = project.GetPropertyValue(PropertyNames.TargetFramework);
                var targetFrameworks     = PropertyConverter.SplitList(project.GetPropertyValue(PropertyNames.TargetFrameworks), ';');

                if (!string.IsNullOrWhiteSpace(targetFrameworkValue) && targetFrameworks.Length == 0)
                {
                    targetFrameworks = ImmutableArray.Create(targetFrameworkValue);
                }

                var languageVersion           = PropertyConverter.ToLanguageVersion(project.GetPropertyValue(PropertyNames.LangVersion));
                var allowUnsafeCode           = PropertyConverter.ToBoolean(project.GetPropertyValue(PropertyNames.AllowUnsafeBlocks), defaultValue: false);
                var outputKind                = PropertyConverter.ToOutputKind(project.GetPropertyValue(PropertyNames.OutputType));
                var documentationFile         = project.GetPropertyValue(PropertyNames.DocumentationFile);
                var preprocessorSymbolNames   = PropertyConverter.ToPreprocessorSymbolNames(project.GetPropertyValue(PropertyNames.DefineConstants));
                var suppressedDiagnosticIds   = PropertyConverter.ToSuppressedDiagnosticIds(project.GetPropertyValue(PropertyNames.NoWarn));
                var signAssembly              = PropertyConverter.ToBoolean(project.GetPropertyValue(PropertyNames.SignAssembly), defaultValue: false);
                var assemblyOriginatorKeyFile = project.GetPropertyValue(PropertyNames.AssemblyOriginatorKeyFile);

                return(new ProjectData(
                           guid, name, assemblyName, targetPath, outputPath, projectAssetsFile,
                           targetFramework, targetFrameworks, outputKind, languageVersion, allowUnsafeCode,
                           documentationFile, preprocessorSymbolNames, suppressedDiagnosticIds, signAssembly, assemblyOriginatorKeyFile));
            }
Пример #4
0
        private static ProjectInstance LoadProject(
            string filePath, string solutionDirectory, string sdksPath, ILogger logger,
            MSBuildOptions options, ICollection <MSBuildDiagnosticsMessage> diagnostics, out ImmutableArray <string> targetFrameworks)
        {
            options = options ?? new MSBuildOptions();

            var globalProperties = GetGlobalProperties(options, solutionDirectory, sdksPath, logger);

            const string MSBuildSDKsPath  = "MSBuildSDKsPath";
            var          oldSdksPathValue = Environment.GetEnvironmentVariable(MSBuildSDKsPath);

            try
            {
                if (globalProperties.TryGetValue(MSBuildSDKsPath, out var sdksPathValue))
                {
                    Environment.SetEnvironmentVariable(MSBuildSDKsPath, sdksPathValue);
                }

                var collection = new ProjectCollection(globalProperties);

                // Evaluate the MSBuild project
                var project = string.IsNullOrEmpty(options.ToolsVersion)
                    ? collection.LoadProject(filePath)
                    : collection.LoadProject(filePath, options.ToolsVersion);

                var targetFramework = project.GetPropertyValue(PropertyNames.TargetFramework);
                targetFrameworks = PropertyConverter.SplitList(project.GetPropertyValue(PropertyNames.TargetFrameworks), ';');

                // If the project supports multiple target frameworks and specific framework isn't
                // selected, we must pick one before execution. Otherwise, the ResolveReferences
                // target might not be available to us.
                if (string.IsNullOrWhiteSpace(targetFramework) && targetFrameworks.Length > 0)
                {
                    // For now, we'll just pick the first target framework. Eventually, we'll need to
                    // do better and potentially allow OmniSharp hosts to select a target framework.
                    targetFramework = targetFrameworks[0];
                    project.SetProperty(PropertyNames.TargetFramework, targetFramework);
                }
                else if (!string.IsNullOrWhiteSpace(targetFramework) && targetFrameworks.Length == 0)
                {
                    targetFrameworks = ImmutableArray.Create(targetFramework);
                }

                var projectInstance = project.CreateProjectInstance();
                var buildResult     = projectInstance.Build(TargetNames.Compile,
                                                            new[] { new MSBuildLogForwarder(logger, diagnostics) });

                return(buildResult
                    ? projectInstance
                    : null);
            }
            finally
            {
                Environment.SetEnvironmentVariable(MSBuildSDKsPath, oldSdksPathValue);
            }
        }
            public static ProjectData Create(MSB.Evaluation.Project project)
            {
                var guid                   = PropertyConverter.ToGuid(project.GetPropertyValue(PropertyNames.ProjectGuid));
                var name                   = project.GetPropertyValue(PropertyNames.ProjectName);
                var assemblyName           = project.GetPropertyValue(PropertyNames.AssemblyName);
                var targetPath             = project.GetPropertyValue(PropertyNames.TargetPath);
                var outputPath             = project.GetPropertyValue(PropertyNames.OutputPath);
                var intermediateOutputPath = project.GetPropertyValue(PropertyNames.IntermediateOutputPath);
                var projectAssetsFile      = project.GetPropertyValue(PropertyNames.ProjectAssetsFile);
                var configuration          = project.GetPropertyValue(PropertyNames.Configuration);
                var platform               = project.GetPropertyValue(PropertyNames.Platform);
                var platformTarget         = project.GetPropertyValue(PropertyNames.PlatformTarget);
                var defaultNamespace       = project.GetPropertyValue(PropertyNames.RootNamespace);

                var targetFramework = new FrameworkName(project.GetPropertyValue(PropertyNames.TargetFrameworkMoniker));

                var targetFrameworkValue = project.GetPropertyValue(PropertyNames.TargetFramework);
                var targetFrameworks     = PropertyConverter.SplitList(project.GetPropertyValue(PropertyNames.TargetFrameworks), ';');

                if (!string.IsNullOrWhiteSpace(targetFrameworkValue) && targetFrameworks.Length == 0)
                {
                    targetFrameworks = ImmutableArray.Create(targetFrameworkValue);
                }

                var languageVersion           = PropertyConverter.ToLanguageVersion(project.GetPropertyValue(PropertyNames.LangVersion));
                var allowUnsafeCode           = PropertyConverter.ToBoolean(project.GetPropertyValue(PropertyNames.AllowUnsafeBlocks), defaultValue: false);
                var checkForOverflowUnderflow = PropertyConverter.ToBoolean(project.GetPropertyValue(PropertyNames.CheckForOverflowUnderflow), defaultValue: false);
                var outputKind                     = PropertyConverter.ToOutputKind(project.GetPropertyValue(PropertyNames.OutputType));
                var nullableContextOptions         = PropertyConverter.ToNullableContextOptions(project.GetPropertyValue(PropertyNames.Nullable));
                var documentationFile              = project.GetPropertyValue(PropertyNames.DocumentationFile);
                var preprocessorSymbolNames        = PropertyConverter.ToPreprocessorSymbolNames(project.GetPropertyValue(PropertyNames.DefineConstants));
                var suppressedDiagnosticIds        = PropertyConverter.ToSuppressedDiagnosticIds(project.GetPropertyValue(PropertyNames.NoWarn));
                var warningsAsErrors               = PropertyConverter.SplitList(project.GetPropertyValue(PropertyNames.WarningsAsErrors), ',');
                var warningsNotAsErrors            = PropertyConverter.SplitList(project.GetPropertyValue(PropertyNames.WarningsNotAsErrors), ',');
                var signAssembly                   = PropertyConverter.ToBoolean(project.GetPropertyValue(PropertyNames.SignAssembly), defaultValue: false);
                var assemblyOriginatorKeyFile      = project.GetPropertyValue(PropertyNames.AssemblyOriginatorKeyFile);
                var treatWarningsAsErrors          = PropertyConverter.ToBoolean(project.GetPropertyValue(PropertyNames.TreatWarningsAsErrors), defaultValue: false);
                var runAnalyzers                   = PropertyConverter.ToBoolean(project.GetPropertyValue(PropertyNames.RunAnalyzers), defaultValue: true);
                var runAnalyzersDuringLiveAnalysis = PropertyConverter.ToBoolean(project.GetPropertyValue(PropertyNames.RunAnalyzersDuringLiveAnalysis), defaultValue: true);

                return(new ProjectData(
                           guid, name, assemblyName, targetPath, outputPath, intermediateOutputPath, projectAssetsFile,
                           configuration, platform, platformTarget, targetFramework, targetFrameworks, outputKind, languageVersion, nullableContextOptions, allowUnsafeCode, checkForOverflowUnderflow,
                           documentationFile, preprocessorSymbolNames, suppressedDiagnosticIds, warningsAsErrors, warningsNotAsErrors, signAssembly, assemblyOriginatorKeyFile, treatWarningsAsErrors, defaultNamespace, runAnalyzers, runAnalyzersDuringLiveAnalysis, ruleset: null));
            }
Пример #6
0
            public static ProjectData Create(MSB.Execution.ProjectInstance projectInstance)
            {
                var guid                   = PropertyConverter.ToGuid(projectInstance.GetPropertyValue(PropertyNames.ProjectGuid));
                var name                   = projectInstance.GetPropertyValue(PropertyNames.ProjectName);
                var assemblyName           = projectInstance.GetPropertyValue(PropertyNames.AssemblyName);
                var targetPath             = projectInstance.GetPropertyValue(PropertyNames.TargetPath);
                var outputPath             = projectInstance.GetPropertyValue(PropertyNames.OutputPath);
                var intermediateOutputPath = projectInstance.GetPropertyValue(PropertyNames.IntermediateOutputPath);
                var projectAssetsFile      = projectInstance.GetPropertyValue(PropertyNames.ProjectAssetsFile);
                var configuration          = projectInstance.GetPropertyValue(PropertyNames.Configuration);
                var platform               = projectInstance.GetPropertyValue(PropertyNames.Platform);

                var targetFramework = new FrameworkName(projectInstance.GetPropertyValue(PropertyNames.TargetFrameworkMoniker));

                var targetFrameworkValue = projectInstance.GetPropertyValue(PropertyNames.TargetFramework);
                var targetFrameworks     = PropertyConverter.SplitList(projectInstance.GetPropertyValue(PropertyNames.TargetFrameworks), ';');

                if (!string.IsNullOrWhiteSpace(targetFrameworkValue) && targetFrameworks.Length == 0)
                {
                    targetFrameworks = ImmutableArray.Create(targetFrameworkValue);
                }

                var languageVersion           = PropertyConverter.ToLanguageVersion(projectInstance.GetPropertyValue(PropertyNames.LangVersion));
                var allowUnsafeCode           = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.AllowUnsafeBlocks), defaultValue: false);
                var outputKind                = PropertyConverter.ToOutputKind(projectInstance.GetPropertyValue(PropertyNames.OutputType));
                var documentationFile         = projectInstance.GetPropertyValue(PropertyNames.DocumentationFile);
                var preprocessorSymbolNames   = PropertyConverter.ToPreprocessorSymbolNames(projectInstance.GetPropertyValue(PropertyNames.DefineConstants));
                var suppressedDiagnosticIds   = PropertyConverter.ToSuppressedDiagnosticIds(projectInstance.GetPropertyValue(PropertyNames.NoWarn));
                var signAssembly              = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.SignAssembly), defaultValue: false);
                var assemblyOriginatorKeyFile = projectInstance.GetPropertyValue(PropertyNames.AssemblyOriginatorKeyFile);

                var sourceFiles = GetFullPaths(
                    projectInstance.GetItems(ItemNames.Compile), filter: FileNameIsNotGenerated);

                var projectReferences = GetFullPaths(
                    projectInstance.GetItems(ItemNames.ProjectReference), filter: IsCSharpProject);

                var references = ImmutableArray.CreateBuilder <string>();

                foreach (var referencePathItem in projectInstance.GetItems(ItemNames.ReferencePath))
                {
                    var referenceSourceTarget = referencePathItem.GetMetadataValue(MetadataNames.ReferenceSourceTarget);

                    if (StringComparer.OrdinalIgnoreCase.Equals(referenceSourceTarget, ItemNames.ProjectReference))
                    {
                        // If the reference was sourced from a project reference, we have two choices:
                        //
                        //   1. If the reference is a C# project reference, we shouldn't add it because it'll just duplicate
                        //      the project reference.
                        //   2. If the reference is *not* a C# project reference, we should keep this reference because the
                        //      project reference was already removed.

                        var originalItemSpec = referencePathItem.GetMetadataValue(MetadataNames.OriginalItemSpec);
                        if (originalItemSpec.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }
                    }

                    var fullPath = referencePathItem.GetMetadataValue(MetadataNames.FullPath);
                    if (!string.IsNullOrEmpty(fullPath))
                    {
                        references.Add(fullPath);
                    }
                }

                var packageReferences = GetPackageReferences(projectInstance.GetItems(ItemNames.PackageReference));
                var analyzers         = GetFullPaths(projectInstance.GetItems(ItemNames.Analyzer));

                return(new ProjectData(guid, name,
                                       assemblyName, targetPath, outputPath, intermediateOutputPath, projectAssetsFile,
                                       configuration, platform, targetFramework, targetFrameworks,
                                       outputKind, languageVersion, allowUnsafeCode, documentationFile, preprocessorSymbolNames, suppressedDiagnosticIds,
                                       signAssembly, assemblyOriginatorKeyFile,
                                       sourceFiles, projectReferences, references.ToImmutable(), packageReferences, analyzers));
            }
Пример #7
0
            public static ProjectData Create(string projectFilePath, MSB.Execution.ProjectInstance projectInstance, MSB.Evaluation.Project project)
            {
                var projectFolderPath = Path.GetDirectoryName(projectFilePath);

                var guid                   = PropertyConverter.ToGuid(projectInstance.GetPropertyValue(PropertyNames.ProjectGuid));
                var name                   = projectInstance.GetPropertyValue(PropertyNames.ProjectName);
                var assemblyName           = projectInstance.GetPropertyValue(PropertyNames.AssemblyName);
                var targetPath             = projectInstance.GetPropertyValue(PropertyNames.TargetPath);
                var outputPath             = projectInstance.GetPropertyValue(PropertyNames.OutputPath);
                var intermediateOutputPath = projectInstance.GetPropertyValue(PropertyNames.IntermediateOutputPath);
                var projectAssetsFile      = projectInstance.GetPropertyValue(PropertyNames.ProjectAssetsFile);
                var configuration          = projectInstance.GetPropertyValue(PropertyNames.Configuration);
                var platform               = projectInstance.GetPropertyValue(PropertyNames.Platform);
                var defaultNamespace       = projectInstance.GetPropertyValue(PropertyNames.RootNamespace);

                var targetFramework = new FrameworkName(projectInstance.GetPropertyValue(PropertyNames.TargetFrameworkMoniker));

                var targetFrameworkValue = projectInstance.GetPropertyValue(PropertyNames.TargetFramework);
                var targetFrameworks     = PropertyConverter.SplitList(projectInstance.GetPropertyValue(PropertyNames.TargetFrameworks), ';');

                if (!string.IsNullOrWhiteSpace(targetFrameworkValue) && targetFrameworks.Length == 0)
                {
                    targetFrameworks = ImmutableArray.Create(targetFrameworkValue);
                }

                var languageVersion           = PropertyConverter.ToLanguageVersion(projectInstance.GetPropertyValue(PropertyNames.LangVersion));
                var allowUnsafeCode           = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.AllowUnsafeBlocks), defaultValue: false);
                var checkForOverflowUnderflow = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.CheckForOverflowUnderflow), defaultValue: false);
                var outputKind                     = PropertyConverter.ToOutputKind(projectInstance.GetPropertyValue(PropertyNames.OutputType));
                var nullableContextOptions         = PropertyConverter.ToNullableContextOptions(projectInstance.GetPropertyValue(PropertyNames.Nullable));
                var documentationFile              = projectInstance.GetPropertyValue(PropertyNames.DocumentationFile);
                var preprocessorSymbolNames        = PropertyConverter.ToPreprocessorSymbolNames(projectInstance.GetPropertyValue(PropertyNames.DefineConstants));
                var suppressedDiagnosticIds        = PropertyConverter.ToSuppressedDiagnosticIds(projectInstance.GetPropertyValue(PropertyNames.NoWarn));
                var warningsAsErrors               = PropertyConverter.SplitList(projectInstance.GetPropertyValue(PropertyNames.WarningsAsErrors), ',');
                var warningsNotAsErrors            = PropertyConverter.SplitList(projectInstance.GetPropertyValue(PropertyNames.WarningsNotAsErrors), ',');
                var signAssembly                   = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.SignAssembly), defaultValue: false);
                var treatWarningsAsErrors          = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.TreatWarningsAsErrors), defaultValue: false);
                var runAnalyzers                   = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.RunAnalyzers), defaultValue: true);
                var runAnalyzersDuringLiveAnalysis = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.RunAnalyzersDuringLiveAnalysis), defaultValue: true);
                var assemblyOriginatorKeyFile      = projectInstance.GetPropertyValue(PropertyNames.AssemblyOriginatorKeyFile);

                var ruleset = ResolveRulesetIfAny(projectInstance);

                var sourceFiles = GetFullPaths(
                    projectInstance.GetItems(ItemNames.Compile), filter: FileNameIsNotGenerated);

                var projectReferences       = ImmutableArray.CreateBuilder <string>();
                var projectReferenceAliases = ImmutableDictionary.CreateBuilder <string, string>();

                var references       = ImmutableArray.CreateBuilder <string>();
                var referenceAliases = ImmutableDictionary.CreateBuilder <string, string>();

                foreach (var referencePathItem in projectInstance.GetItems(ItemNames.ReferencePath))
                {
                    var referenceSourceTarget = referencePathItem.GetMetadataValue(MetadataNames.ReferenceSourceTarget);
                    var aliases = referencePathItem.GetMetadataValue(MetadataNames.Aliases);

                    // If this reference came from a project reference, count it as such. We never want to directly look
                    // at the ProjectReference items in the project, as those don't always create project references
                    // if things like OutputItemType or ReferenceOutputAssembly are set. It's also possible that other
                    // MSBuild logic is adding or removing properties too.
                    if (StringComparer.OrdinalIgnoreCase.Equals(referenceSourceTarget, ItemNames.ProjectReference))
                    {
                        var projectReferenceOriginalItemSpec = referencePathItem.GetMetadataValue(MetadataNames.ProjectReferenceOriginalItemSpec);
                        if (projectReferenceOriginalItemSpec.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase))
                        {
                            var projectReferenceFilePath = Path.GetFullPath(Path.Combine(projectFolderPath, projectReferenceOriginalItemSpec));

                            projectReferences.Add(projectReferenceFilePath);

                            if (!string.IsNullOrEmpty(aliases))
                            {
                                projectReferenceAliases[projectReferenceFilePath] = aliases;
                            }

                            continue;
                        }
                    }

                    var fullPath = referencePathItem.GetMetadataValue(MetadataNames.FullPath);
                    if (!string.IsNullOrEmpty(fullPath))
                    {
                        references.Add(fullPath);

                        if (!string.IsNullOrEmpty(aliases))
                        {
                            referenceAliases[fullPath] = aliases;
                        }
                    }
                }

                var packageReferences = GetPackageReferences(projectInstance.GetItems(ItemNames.PackageReference));
                var analyzers         = GetFullPaths(projectInstance.GetItems(ItemNames.Analyzer));
                var additionalFiles   = GetFullPaths(projectInstance.GetItems(ItemNames.AdditionalFiles));
                var editorConfigFiles = GetFullPaths(projectInstance.GetItems(ItemNames.EditorConfigFiles));
                var includeGlobs      = project.GetAllGlobs().Select(x => x.MsBuildGlob).ToImmutableArray();

                return(new ProjectData(
                           guid,
                           name,
                           assemblyName,
                           targetPath,
                           outputPath,
                           intermediateOutputPath,
                           projectAssetsFile,
                           configuration,
                           platform,
                           targetFramework,
                           targetFrameworks,
                           outputKind,
                           languageVersion,
                           nullableContextOptions,
                           allowUnsafeCode,
                           checkForOverflowUnderflow,
                           documentationFile,
                           preprocessorSymbolNames,
                           suppressedDiagnosticIds,
                           warningsAsErrors,
                           warningsNotAsErrors,
                           signAssembly,
                           assemblyOriginatorKeyFile,
                           sourceFiles,
                           projectReferences.ToImmutable(),
                           references.ToImmutable(),
                           packageReferences,
                           analyzers,
                           additionalFiles,
                           editorConfigFiles,
                           treatWarningsAsErrors,
                           defaultNamespace,
                           runAnalyzers,
                           runAnalyzersDuringLiveAnalysis,
                           ruleset,
                           referenceAliases.ToImmutableDictionary(),
                           projectReferenceAliases.ToImmutable(),
                           includeGlobs));
            }
            public static ProjectData Create(MSB.Execution.ProjectInstance projectInstance, MSB.Evaluation.Project project)
            {
                var guid                   = PropertyConverter.ToGuid(projectInstance.GetPropertyValue(PropertyNames.ProjectGuid));
                var name                   = projectInstance.GetPropertyValue(PropertyNames.ProjectName);
                var assemblyName           = projectInstance.GetPropertyValue(PropertyNames.AssemblyName);
                var targetPath             = projectInstance.GetPropertyValue(PropertyNames.TargetPath);
                var outputPath             = projectInstance.GetPropertyValue(PropertyNames.OutputPath);
                var intermediateOutputPath = projectInstance.GetPropertyValue(PropertyNames.IntermediateOutputPath);
                var projectAssetsFile      = projectInstance.GetPropertyValue(PropertyNames.ProjectAssetsFile);
                var configuration          = projectInstance.GetPropertyValue(PropertyNames.Configuration);
                var platform               = projectInstance.GetPropertyValue(PropertyNames.Platform);
                var defaultNamespace       = projectInstance.GetPropertyValue(PropertyNames.RootNamespace);

                var targetFramework = new FrameworkName(projectInstance.GetPropertyValue(PropertyNames.TargetFrameworkMoniker));

                var targetFrameworkValue = projectInstance.GetPropertyValue(PropertyNames.TargetFramework);
                var targetFrameworks     = PropertyConverter.SplitList(projectInstance.GetPropertyValue(PropertyNames.TargetFrameworks), ';');

                if (!string.IsNullOrWhiteSpace(targetFrameworkValue) && targetFrameworks.Length == 0)
                {
                    targetFrameworks = ImmutableArray.Create(targetFrameworkValue);
                }

                var languageVersion           = PropertyConverter.ToLanguageVersion(projectInstance.GetPropertyValue(PropertyNames.LangVersion));
                var allowUnsafeCode           = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.AllowUnsafeBlocks), defaultValue: false);
                var checkForOverflowUnderflow = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.CheckForOverflowUnderflow), defaultValue: false);
                var outputKind                     = PropertyConverter.ToOutputKind(projectInstance.GetPropertyValue(PropertyNames.OutputType));
                var nullableContextOptions         = PropertyConverter.ToNullableContextOptions(projectInstance.GetPropertyValue(PropertyNames.Nullable));
                var documentationFile              = projectInstance.GetPropertyValue(PropertyNames.DocumentationFile);
                var preprocessorSymbolNames        = PropertyConverter.ToPreprocessorSymbolNames(projectInstance.GetPropertyValue(PropertyNames.DefineConstants));
                var suppressedDiagnosticIds        = PropertyConverter.ToSuppressedDiagnosticIds(projectInstance.GetPropertyValue(PropertyNames.NoWarn));
                var warningsAsErrors               = PropertyConverter.SplitList(projectInstance.GetPropertyValue(PropertyNames.WarningsAsErrors), ',');
                var warningsNotAsErrors            = PropertyConverter.SplitList(projectInstance.GetPropertyValue(PropertyNames.WarningsNotAsErrors), ',');
                var signAssembly                   = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.SignAssembly), defaultValue: false);
                var treatWarningsAsErrors          = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.TreatWarningsAsErrors), defaultValue: false);
                var runAnalyzers                   = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.RunAnalyzers), defaultValue: true);
                var runAnalyzersDuringLiveAnalysis = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.RunAnalyzersDuringLiveAnalysis), defaultValue: true);
                var assemblyOriginatorKeyFile      = projectInstance.GetPropertyValue(PropertyNames.AssemblyOriginatorKeyFile);

                var ruleset = ResolveRulesetIfAny(projectInstance);

                var sourceFiles = GetFullPaths(
                    projectInstance.GetItems(ItemNames.Compile), filter: FileNameIsNotGenerated);

                var projectReferences       = ImmutableArray.CreateBuilder <string>();
                var projectReferenceAliases = ImmutableDictionary.CreateBuilder <string, string>();
                var projectReferencesAdded  = new HashSet <string>();

                foreach (var projectReferenceItem in projectInstance.GetItems(ItemNames.ProjectReference))
                {
                    var fullPath = projectReferenceItem.GetMetadataValue(MetadataNames.FullPath);

                    if (IsCSharpProject(fullPath) && projectReferencesAdded.Add(fullPath))
                    {
                        projectReferences.Add(fullPath);

                        var aliases = projectReferenceItem.GetMetadataValue(MetadataNames.Aliases);
                        if (!string.IsNullOrEmpty(aliases))
                        {
                            projectReferenceAliases[fullPath] = aliases;
                        }
                    }
                }

                var references       = ImmutableArray.CreateBuilder <string>();
                var referenceAliases = ImmutableDictionary.CreateBuilder <string, string>();

                foreach (var referencePathItem in projectInstance.GetItems(ItemNames.ReferencePath))
                {
                    var referenceSourceTarget = referencePathItem.GetMetadataValue(MetadataNames.ReferenceSourceTarget);

                    if (StringComparer.OrdinalIgnoreCase.Equals(referenceSourceTarget, ItemNames.ProjectReference))
                    {
                        // If the reference was sourced from a project reference, we have two choices:
                        //
                        //   1. If the reference is a C# project reference, we shouldn't add it because it'll just duplicate
                        //      the project reference.
                        //   2. If the reference is *not* a C# project reference, we should keep this reference because the
                        //      project reference was already removed.

                        var originalItemSpec = referencePathItem.GetMetadataValue(MetadataNames.OriginalItemSpec);
                        if (originalItemSpec.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }
                    }

                    var fullPath = referencePathItem.GetMetadataValue(MetadataNames.FullPath);
                    if (!string.IsNullOrEmpty(fullPath))
                    {
                        references.Add(fullPath);

                        var aliases = referencePathItem.GetMetadataValue(MetadataNames.Aliases);
                        if (!string.IsNullOrEmpty(aliases))
                        {
                            referenceAliases[fullPath] = aliases;
                        }
                    }
                }

                var packageReferences = GetPackageReferences(projectInstance.GetItems(ItemNames.PackageReference));
                var analyzers         = GetFullPaths(projectInstance.GetItems(ItemNames.Analyzer));
                var additionalFiles   = GetFullPaths(projectInstance.GetItems(ItemNames.AdditionalFiles));
                var editorConfigFiles = GetFullPaths(projectInstance.GetItems(ItemNames.EditorConfigFiles));
                var includeGlobs      = project.GetAllGlobs().Select(x => x.MsBuildGlob).ToImmutableArray();

                return(new ProjectData(
                           guid,
                           name,
                           assemblyName,
                           targetPath,
                           outputPath,
                           intermediateOutputPath,
                           projectAssetsFile,
                           configuration,
                           platform,
                           targetFramework,
                           targetFrameworks,
                           outputKind,
                           languageVersion,
                           nullableContextOptions,
                           allowUnsafeCode,
                           checkForOverflowUnderflow,
                           documentationFile,
                           preprocessorSymbolNames,
                           suppressedDiagnosticIds,
                           warningsAsErrors,
                           warningsNotAsErrors,
                           signAssembly,
                           assemblyOriginatorKeyFile,
                           sourceFiles,
                           projectReferences.ToImmutable(),
                           references.ToImmutable(),
                           packageReferences,
                           analyzers,
                           additionalFiles,
                           editorConfigFiles,
                           treatWarningsAsErrors,
                           defaultNamespace,
                           runAnalyzers,
                           runAnalyzersDuringLiveAnalysis,
                           ruleset,
                           referenceAliases.ToImmutableDictionary(),
                           projectReferenceAliases.ToImmutable(),
                           includeGlobs));
            }