/// <summary>
 /// Gets the package sources of the specified project.
 /// </summary>
 /// <param name="project">An <see cref="IMSBuildItem" /> representing the project..</param>
 /// <param name="innerNodes">An <see cref="IReadOnlyCollection{IMSBuildItem}" /> containing the inner nodes of the project if its targets multiple frameworks.</param>
 /// <param name="settings">The <see cref="ISettings" /> of the specified project.</param>
 /// <returns>A <see cref="List{PackageSource}" /> object containing the packages sources for the specified project.</returns>
 internal static List <PackageSource> GetSources(IMSBuildProject project, IReadOnlyCollection <IMSBuildProject> innerNodes, ISettings settings)
 {
     return(BuildTasksUtility.GetSources(
                project.Directory,
                project.SplitPropertyValueOrNull("RestoreSources"),
                project.SplitPropertyValueOrNull("RestoreSourcesOverride"),
                innerNodes.SelectMany(i => MSBuildStringUtility.Split(i.GetProperty("RestoreAdditionalProjectSources"))),
                settings)
            .Select(i => new PackageSource(i))
            .ToList());
 }
        /// <summary>
        /// Gets the original target frameworks for the specified project.
        /// </summary>
        /// <param name="project">An <see cref="IMSBuildItem" /> representing the project.</param>
        /// <param name="frameworks">An <see cref="IReadOnlyCollection{NuGetFrameowrk}" /> object containing the frameworks that were parsed from the outer project.</param>
        /// <returns>A <see cref="List{String}" /> containing the original target frameworks of the project.</returns>
        internal static List <string> GetOriginalTargetFrameworks(IMSBuildProject project, IReadOnlyCollection <NuGetFramework> frameworks)
        {
            // If the project specified the TargetFrameworks property, just return that list
            var projectTargetFrameworks = project.SplitPropertyValueOrNull("TargetFrameworks");

            if (projectTargetFrameworks != null)
            {
                return(projectTargetFrameworks.ToList());
            }

            // If the project did not specify a value for TargetFrameworks, return the short folder name of the frameworks which where parsed via other properties
            var targetFrameworks = new List <string>(frameworks.Count);

            foreach (var framework in frameworks)
            {
                targetFrameworks.Add(framework.GetShortFolderName());
            }

            return(targetFrameworks);
        }
        /// <summary>
        /// Gets the restore metadata and target framework information for the specified project.
        /// </summary>
        /// <param name="project">An <see cref="IMSBuildProject" /> representing the project.</param>
        /// <param name="projectsByTargetFramework">A <see cref="IReadOnlyDictionary{NuGetFramework,IMSBuildProject}" /> containing the inner nodes by target framework.</param>
        /// <param name="settings">The <see cref="ISettings" /> of the specified project.</param>
        /// <returns>A <see cref="Tuple" /> containing the <see cref="ProjectRestoreMetadata" /> and <see cref="List{TargetFrameworkInformation}" /> for the specified project.</returns>
        private (ProjectRestoreMetadata RestoreMetadata, List <TargetFrameworkInformation> TargetFrameworkInfos) GetProjectRestoreMetadataAndTargetFrameworkInformation(IMSBuildProject project, IReadOnlyDictionary <NuGetFramework, IMSBuildProject> projectsByTargetFramework, ISettings settings)
        {
            var projectName = GetProjectName(project);

            var outputPath = GetRestoreOutputPath(project);

            var targetFrameworkInfos = GetTargetFrameworkInfos(projectsByTargetFramework);

            var projectStyleResult = BuildTasksUtility.GetProjectRestoreStyle(
                restoreProjectStyle: project.GetProperty("RestoreProjectStyle"),
                hasPackageReferenceItems: targetFrameworkInfos.Any(i => i.Dependencies.Any()),
                projectJsonPath: project.GetProperty("_CurrentProjectJsonPath"),
                projectDirectory: project.Directory,
                projectName: project.GetProperty("MSBuildProjectName"),
                log: MSBuildLogger);

            var projectStyle = projectStyleResult.ProjectStyle;

            var innerNodes = projectsByTargetFramework.Values.ToList();

            ProjectRestoreMetadata restoreMetadata;

            if (projectStyle == ProjectStyle.PackagesConfig)
            {
                restoreMetadata = new PackagesConfigProjectRestoreMetadata
                {
                    PackagesConfigPath = projectStyleResult.PackagesConfigFilePath,
                    RepositoryPath     = GetRepositoryPath(project, settings)
                };
            }
            else
            {
                restoreMetadata = new ProjectRestoreMetadata
                {
                    CrossTargeting  = (projectStyle == ProjectStyle.PackageReference || projectStyle == ProjectStyle.DotnetToolReference) && projectsByTargetFramework.Count > 1,
                    FallbackFolders = BuildTasksUtility.GetFallbackFolders(
                        project.Directory,
                        project.SplitPropertyValueOrNull("RestoreFallbackFolders"),
                        project.SplitPropertyValueOrNull("RestoreFallbackFoldersOverride"),
                        innerNodes.SelectMany(i => MSBuildStringUtility.Split(i.GetProperty("RestoreAdditionalProjectFallbackFolders"))),
                        innerNodes.SelectMany(i => MSBuildStringUtility.Split(i.GetProperty("RestoreAdditionalProjectFallbackFoldersExcludes"))),
                        settings),
                    SkipContentFileWrite  = IsLegacyProject(project),
                    ValidateRuntimeAssets = project.IsPropertyTrue("ValidateRuntimeIdentifierCompatibility")
                };
            }

            restoreMetadata.CacheFilePath                = NoOpRestoreUtilities.GetProjectCacheFilePath(outputPath, project.FullPath);
            restoreMetadata.ConfigFilePaths              = settings.GetConfigFilePaths();
            restoreMetadata.OutputPath                   = outputPath;
            restoreMetadata.OriginalTargetFrameworks     = GetOriginalTargetFrameworks(project, projectsByTargetFramework.Keys.ToList());
            restoreMetadata.PackagesPath                 = GetPackagesPath(project, settings);
            restoreMetadata.ProjectName                  = projectName;
            restoreMetadata.ProjectPath                  = project.FullPath;
            restoreMetadata.ProjectStyle                 = projectStyle;
            restoreMetadata.ProjectUniqueName            = project.FullPath;
            restoreMetadata.ProjectWideWarningProperties = WarningProperties.GetWarningProperties(project.GetProperty("TreatWarningsAsErrors"), project.GetProperty("WarningsAsErrors"), project.GetProperty("NoWarn"));
            restoreMetadata.RestoreLockProperties        = new RestoreLockProperties(project.GetProperty("RestorePackagesWithLockFile"), project.GetProperty("NuGetLockFilePath"), project.IsPropertyTrue("RestoreLockedMode"));
            restoreMetadata.Sources          = GetSources(project, innerNodes, settings);
            restoreMetadata.TargetFrameworks = GetProjectRestoreMetadataFrameworkInfos(projectsByTargetFramework);

            return(restoreMetadata, targetFrameworkInfos);
        }