Пример #1
0
        private void ValidatePackagesConfigLockFiles(IEnumerable <NuGetProject> allProjects, CancellationToken token)
        {
            var pcProjects = allProjects.Where(p => p.ProjectStyle == ProjectModel.ProjectStyle.PackagesConfig);

            foreach (MSBuildNuGetProject project in pcProjects)
            {
                string projectFile  = project.MSBuildProjectPath;
                string pcFile       = project.PackagesConfigNuGetProject.FullPath;
                var    projectName  = (string)project.GetMetadataOrNull("Name");
                var    lockFileName = (string)project.GetMetadataOrNull("NuGetLockFilePath");
                var    restorePackagesWithLockFile = (string)project.GetMetadataOrNull("RestorePackagesWithLockFile");
                var    projectTfm        = (NuGetFramework)project.GetMetadataOrNull("TargetFramework");
                bool   restoreLockedMode = MSBuildStringUtility.GetBooleanOrNull((string)project.GetMetadataOrNull("LockedMode")) ?? false;

                IReadOnlyList <IRestoreLogMessage> validationLogs = PackagesConfigLockFileUtility.ValidatePackagesConfigLockFiles(
                    projectFile,
                    pcFile,
                    projectName,
                    lockFileName,
                    restorePackagesWithLockFile,
                    projectTfm,
                    project.FolderNuGetProject.Root,
                    restoreLockedMode,
                    token);

                if (validationLogs != null)
                {
                    foreach (var logItem in validationLogs)
                    {
                        _logger.Log(logItem);
                    }
                }
            }
        }
Пример #2
0
        private void ValidatePackagesConfigLockFiles(IReadOnlyList <string> packagesConfigFiles, IReadOnlyList <PackageSpec> projects, string packagesFolderPath, List <RestoreSummary> restoreSummaries)
        {
            foreach (var pcFile in packagesConfigFiles)
            {
                var dgSpec = projects?.FirstOrDefault(p =>
                {
                    if (p.RestoreMetadata is PackagesConfigProjectRestoreMetadata pcRestoreMetadata)
                    {
                        return(StringComparer.OrdinalIgnoreCase.Equals(pcRestoreMetadata.PackagesConfigPath, pcFile));
                    }
                    return(false);
                });

                var projectFile       = dgSpec?.FilePath ?? pcFile;
                var projectTfm        = dgSpec?.TargetFrameworks.SingleOrDefault()?.FrameworkName ?? NuGetFramework.AnyFramework;
                var restoreLockedMode = LockedMode || (dgSpec?.RestoreMetadata?.RestoreLockProperties?.RestoreLockedMode ?? false);
                var lockFilePath      = LockFilePath ?? dgSpec?.RestoreMetadata?.RestoreLockProperties?.NuGetLockFilePath;
                var useLockFile       = UseLockFile ? bool.TrueString : dgSpec?.RestoreMetadata?.RestoreLockProperties?.RestorePackagesWithLockFile;

                IReadOnlyList <IRestoreLogMessage> result = PackagesConfigLockFileUtility.ValidatePackagesConfigLockFiles(
                    projectFile,
                    pcFile,
                    dgSpec?.Name,
                    lockFilePath,
                    useLockFile,
                    projectTfm,
                    packagesFolderPath,
                    restoreLockedMode,
                    CancellationToken.None);

                if (result != null)
                {
                    restoreSummaries.Add(new RestoreSummary(
                                             success: false,
                                             inputPath: projectFile,
                                             configFiles: Array.Empty <string>(),
                                             feedsUsed: Array.Empty <string>(),
                                             installCount: 0,
                                             errors: result));
                }
            }
        }