diff --git a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/RunWorkerTests.cs b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/RunWorkerTests.cs index fe6a1f851e..e75803f3cc 100644 --- a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/RunWorkerTests.cs +++ b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/RunWorkerTests.cs @@ -142,7 +142,7 @@ await RunAsync( new DependencyFile() { Name = "project.csproj", - Directory = "some-dir", + Directory = "/some-dir", Content = """ @@ -250,14 +250,648 @@ await RunAsync( ); } - private static async Task RunAsync(Job job, TestFile[] files, RunResult expectedResult, object[] expectedApiMessages, MockNuGetPackage[]? packages = null) + [Fact] + public async Task UpdateHandlesPackagesConfigFiles() + { + var repoMetadata = XElement.Parse(""""""); + var repoMetadata2 = XElement.Parse(""""""); + await RunAsync( + packages: + [ + MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.0", "net8.0", additionalMetadata: [repoMetadata]), + MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.1", "net8.0", additionalMetadata: [repoMetadata]), + MockNuGetPackage.CreateSimplePackage("Some.Package2", "2.0.0", "net8.0", additionalMetadata: [repoMetadata2]), + MockNuGetPackage.CreateSimplePackage("Some.Package2", "2.0.1", "net8.0", additionalMetadata: [repoMetadata2]), + ], + job: new Job() + { + PackageManager = "nuget", + Source = new() + { + Provider = "github", + Repo = "test/repo", + Directory = "some-dir", + }, + AllowedUpdates = + [ + new() { UpdateType = "all" } + ] + }, + files: + [ + ("some-dir/project.csproj", """ + + + net8.0 + + + + + + """), + ("some-dir/packages.config", """ + + + + + """), + ], + expectedResult: new RunResult() + { + Base64DependencyFiles = + [ + new DependencyFile() + { + Directory = "/some-dir", + Name = "project.csproj", + Content = Convert.ToBase64String(Encoding.UTF8.GetBytes(""" + + + net8.0 + + + + + + """)) + }, + new DependencyFile() + { + Directory = "/some-dir", + Name = "packages.config", + Content = Convert.ToBase64String(Encoding.UTF8.GetBytes(""" + + + + + """)) + } + ], + BaseCommitSha = "TEST-COMMIT-SHA", + }, + expectedApiMessages: + [ + new UpdatedDependencyList() + { + Dependencies = + [ + new ReportedDependency() + { + Name = "Some.Package", + Version = "1.0.0", + Requirements = + [ + new ReportedRequirement() + { + Requirement = "1.0.0", + File = "/some-dir/project.csproj", + Groups = ["dependencies"], + } + ] + }, + new ReportedDependency() + { + Name = "Some.Package2", + Version = "2.0.0", + Requirements = + [ + new ReportedRequirement() + { + Requirement = "2.0.0", + File = "/some-dir/packages.config", + Groups = ["dependencies"], + } + ] + } + ], + DependencyFiles = ["/some-dir/project.csproj", "/some-dir/packages.config"], + }, + new IncrementMetric() + { + Metric = "updater.started", + Tags = new() + { + ["operation"] = "group_update_all_versions" + } + }, + new CreatePullRequest() + { + Dependencies = + [ + new ReportedDependency() + { + Name = "Some.Package", + Version = "1.0.1", + Requirements = + [ + new ReportedRequirement() + { + Requirement = "1.0.1", + File = "/some-dir/project.csproj", + Groups = ["dependencies"], + Source = new() + { + SourceUrl = "https://nuget.example.com/some-package", + Type = "nuget_repo", + } + } + ], + PreviousVersion = "1.0.0", + PreviousRequirements = + [ + new ReportedRequirement() + { + Requirement = "1.0.0", + File = "/some-dir/project.csproj", + Groups = ["dependencies"], + } + ], + }, + new ReportedDependency() + { + Name = "Some.Package2", + Version = "2.0.1", + Requirements = + [ + new ReportedRequirement() + { + Requirement = "2.0.1", + File = "/some-dir/packages.config", + Groups = ["dependencies"], + Source = new() + { + SourceUrl = "https://nuget.example.com/some-package2", + Type = "nuget_repo", + } + } + ], + PreviousVersion = "2.0.0", + PreviousRequirements = + [ + new ReportedRequirement() + { + Requirement = "2.0.0", + File = "/some-dir/packages.config", + Groups = ["dependencies"], + } + ], + }, + ], + UpdatedDependencyFiles = + [ + new DependencyFile() + { + Name = "project.csproj", + Directory = "/some-dir", + Content = """ + + + net8.0 + + + + + + + ..\packages\Some.Package2.2.0.1\lib\net8.0\Some.Package2.dll + True + + + + """, + }, + new DependencyFile() + { + Name = "packages.config", + Directory = "/some-dir", + Content = """ + + + + + """, + }, + ], + BaseCommitSha = "TEST-COMMIT-SHA", + CommitMessage = "TODO: message", + PrTitle = "TODO: title", + PrBody = "TODO: body", + }, + new MarkAsProcessed("TEST-COMMIT-SHA") + ] + ); + } + + [Fact] + public async Task UpdateHandlesPackagesConfigFromReferencedCsprojFiles() + { + var repoMetadata = XElement.Parse(""""""); + var repoMetadata2 = XElement.Parse(""""""); + await RunAsync( + packages: + [ + MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.0", "net8.0", additionalMetadata: [repoMetadata]), + MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.1", "net8.0", additionalMetadata: [repoMetadata]), + MockNuGetPackage.CreateSimplePackage("Some.Package2", "2.0.0", "net8.0", additionalMetadata: [repoMetadata2]), + MockNuGetPackage.CreateSimplePackage("Some.Package2", "2.0.1", "net8.0", additionalMetadata: [repoMetadata2]), + ], + job: new Job() + { + PackageManager = "nuget", + Source = new() + { + Provider = "github", + Repo = "test/repo", + Directory = "some-dir/ProjectA", + }, + AllowedUpdates = + [ + new() { UpdateType = "all" } + ] + }, + files: + [ + ("some-dir/ProjectA/ProjectA.csproj", """ + + + net8.0 + + + + + + + + + """), + ("some-dir/ProjectA/packages.config", """ + + + + + """), + ("some-dir/ProjectB/ProjectB.csproj", """ + + + net8.0 + + + + + + """), + ("some-dir/ProjectB/packages.config", """ + + + + + """), + ], + expectedResult: new RunResult() + { + Base64DependencyFiles = + [ + new DependencyFile() + { + Directory = "/some-dir/ProjectB", + Name = "ProjectB.csproj", + Content = Convert.ToBase64String(Encoding.UTF8.GetBytes(""" + + + net8.0 + + + + + + """)) + }, + new DependencyFile() + { + Directory = "/some-dir/ProjectB", + Name = "packages.config", + Content = Convert.ToBase64String(Encoding.UTF8.GetBytes(""" + + + + + """)) + }, + new DependencyFile() + { + Directory = "/some-dir/ProjectA", + Name = "ProjectA.csproj", + Content = Convert.ToBase64String(Encoding.UTF8.GetBytes(""" + + + net8.0 + + + + + + + + + """)) + }, + new DependencyFile() + { + Directory = "/some-dir/ProjectA", + Name = "packages.config", + Content = Convert.ToBase64String(Encoding.UTF8.GetBytes(""" + + + + + """)) + }, + ], + BaseCommitSha = "TEST-COMMIT-SHA", + }, + expectedApiMessages: + [ + new UpdatedDependencyList() + { + Dependencies = + [ + new ReportedDependency() + { + Name = "Some.Package", + Version = "1.0.0", + Requirements = + [ + new ReportedRequirement() + { + Requirement = "1.0.0", + File = "/some-dir/ProjectB/ProjectB.csproj", + Groups = ["dependencies"], + } + ] + }, + new ReportedDependency() + { + Name = "Some.Package2", + Version = "2.0.0", + Requirements = + [ + new ReportedRequirement() + { + Requirement = "2.0.0", + File = "/some-dir/ProjectB/packages.config", + Groups = ["dependencies"], + } + ] + }, + new ReportedDependency() + { + Name = "Some.Package", + Version = "1.0.0", + Requirements = + [ + new ReportedRequirement() + { + Requirement = "1.0.0", + File = "/some-dir/ProjectA/ProjectA.csproj", + Groups = ["dependencies"], + } + ] + }, + new ReportedDependency() + { + Name = "Some.Package2", + Version = "2.0.0", + Requirements = + [ + new ReportedRequirement() + { + Requirement = "2.0.0", + File = "/some-dir/ProjectA/packages.config", + Groups = ["dependencies"], + } + ] + }, + ], + DependencyFiles = ["/some-dir/ProjectB/ProjectB.csproj", "/some-dir/ProjectA/ProjectA.csproj", "/some-dir/ProjectB/packages.config", "/some-dir/ProjectA/packages.config"], + }, + new IncrementMetric() + { + Metric = "updater.started", + Tags = new() + { + ["operation"] = "group_update_all_versions" + } + }, + new CreatePullRequest() + { + Dependencies = + [ + new ReportedDependency() + { + Name = "Some.Package", + Version = "1.0.1", + Requirements = + [ + new ReportedRequirement() + { + Requirement = "1.0.1", + File = "/some-dir/ProjectB/ProjectB.csproj", + Groups = ["dependencies"], + Source = new() + { + SourceUrl = "https://nuget.example.com/some-package", + Type = "nuget_repo", + } + } + ], + PreviousVersion = "1.0.0", + PreviousRequirements = + [ + new ReportedRequirement() + { + Requirement = "1.0.0", + File = "/some-dir/ProjectB/ProjectB.csproj", + Groups = ["dependencies"], + } + ], + }, + new ReportedDependency() + { + Name = "Some.Package2", + Version = "2.0.1", + Requirements = + [ + new ReportedRequirement() + { + Requirement = "2.0.1", + File = "/some-dir/ProjectB/packages.config", + Groups = ["dependencies"], + Source = new() + { + SourceUrl = "https://nuget.example.com/some-package2", + Type = "nuget_repo", + } + } + ], + PreviousVersion = "2.0.0", + PreviousRequirements = + [ + new ReportedRequirement() + { + Requirement = "2.0.0", + File = "/some-dir/ProjectB/packages.config", + Groups = ["dependencies"], + } + ], + }, + new ReportedDependency() + { + Name = "Some.Package", + Version = "1.0.1", + Requirements = + [ + new ReportedRequirement() + { + Requirement = "1.0.1", + File = "/some-dir/ProjectA/ProjectA.csproj", + Groups = ["dependencies"], + Source = new() + { + SourceUrl = "https://nuget.example.com/some-package", + Type = "nuget_repo", + } + } + ], + PreviousVersion = "1.0.0", + PreviousRequirements = + [ + new ReportedRequirement() + { + Requirement = "1.0.0", + File = "/some-dir/ProjectA/ProjectA.csproj", + Groups = ["dependencies"], + } + ], + }, + new ReportedDependency() + { + Name = "Some.Package2", + Version = "2.0.1", + Requirements = + [ + new ReportedRequirement() + { + Requirement = "2.0.1", + File = "/some-dir/ProjectA/packages.config", + Groups = ["dependencies"], + Source = new() + { + SourceUrl = "https://nuget.example.com/some-package2", + Type = "nuget_repo", + } + } + ], + PreviousVersion = "2.0.0", + PreviousRequirements = + [ + new ReportedRequirement() + { + Requirement = "2.0.0", + File = "/some-dir/ProjectA/packages.config", + Groups = ["dependencies"], + } + ], + }, + ], + UpdatedDependencyFiles = + [ + new DependencyFile() + { + Name = "../ProjectB/ProjectB.csproj", + Directory = "/some-dir/ProjectB", + Content = """ + + + net8.0 + + + + + + + ..\packages\Some.Package2.2.0.1\lib\net8.0\Some.Package2.dll + True + + + + """, + }, + new DependencyFile() + { + Name = "../ProjectB/packages.config", + Directory = "/some-dir/ProjectB", + Content = """ + + + + + """, + }, + new DependencyFile() + { + Name = "ProjectA.csproj", + Directory = "/some-dir/ProjectA", + Content = """ + + + net8.0 + + + + + + + + + + ..\packages\Some.Package2.2.0.1\lib\net8.0\Some.Package2.dll + True + + + + """, + }, + new DependencyFile() + { + Name = "packages.config", + Directory = "/some-dir/ProjectA", + Content = """ + + + + + """, + }, + ], + BaseCommitSha = "TEST-COMMIT-SHA", + CommitMessage = "TODO: message", + PrTitle = "TODO: title", + PrBody = "TODO: body", + }, + new MarkAsProcessed("TEST-COMMIT-SHA") + ] + ); + } + + private static async Task RunAsync(Job job, TestFile[] files, RunResult? expectedResult, object[] expectedApiMessages, MockNuGetPackage[]? packages = null, string? repoContentsPath = null) { // arrange using var tempDirectory = new TemporaryDirectory(); - await UpdateWorkerTestBase.MockNuGetPackagesInDirectory(packages, tempDirectory.DirectoryPath); + repoContentsPath ??= tempDirectory.DirectoryPath; + await UpdateWorkerTestBase.MockNuGetPackagesInDirectory(packages, repoContentsPath); foreach (var (path, content) in files) { - var fullPath = Path.Combine(tempDirectory.DirectoryPath, path); + var fullPath = Path.Combine(repoContentsPath, path); var directory = Path.GetDirectoryName(fullPath)!; Directory.CreateDirectory(directory); await File.WriteAllTextAsync(fullPath, content); @@ -266,8 +900,8 @@ private static async Task RunAsync(Job job, TestFile[] files, RunResult expected // act var testApiHandler = new TestApiHandler(); var worker = new RunWorker(testApiHandler, new TestLogger()); - var repoContentsPath = new DirectoryInfo(tempDirectory.DirectoryPath); - var actualResult = await worker.RunAsync(job, repoContentsPath, "TEST-COMMIT-SHA"); + var repoContentsPathDirectoryInfo = new DirectoryInfo(repoContentsPath); + var actualResult = await worker.RunAsync(job, repoContentsPathDirectoryInfo, "TEST-COMMIT-SHA"); var actualApiMessages = testApiHandler.ReceivedMessages.ToArray(); // assert diff --git a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdatedDependencyListTests.cs b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdatedDependencyListTests.cs index dd27443ac8..1cfdda08aa 100644 --- a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdatedDependencyListTests.cs +++ b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdatedDependencyListTests.cs @@ -13,6 +13,18 @@ public class UpdatedDependencyListTests [Fact] public void GetUpdatedDependencyListFromDiscovery() { + using var temp = new TemporaryDirectory(); + Directory.CreateDirectory(Path.Combine(temp.DirectoryPath, "src", "a")); + Directory.CreateDirectory(Path.Combine(temp.DirectoryPath, "src", "b")); + Directory.CreateDirectory(Path.Combine(temp.DirectoryPath, "src", "c")); + + File.WriteAllText(Path.Combine(temp.DirectoryPath, "src", "a", "packages.config"), ""); + File.WriteAllText(Path.Combine(temp.DirectoryPath, "src", "b", "packages.config"), ""); + File.WriteAllText(Path.Combine(temp.DirectoryPath, "src", "c", "packages.config"), ""); + File.WriteAllText(Path.Combine(temp.DirectoryPath, "src", "a", "project.csproj"), ""); + File.WriteAllText(Path.Combine(temp.DirectoryPath, "src", "b", "project.csproj"), ""); + File.WriteAllText(Path.Combine(temp.DirectoryPath, "src", "c", "project.csproj"), ""); + var discovery = new WorkspaceDiscoveryResult() { Path = "src", @@ -20,10 +32,31 @@ public void GetUpdatedDependencyListFromDiscovery() Projects = [ new() { - FilePath = "project.csproj", + FilePath = "a/project.csproj", Dependencies = [ new("Microsoft.Extensions.DependencyModel", "6.0.0", DependencyType.PackageReference, TargetFrameworks: ["net6.0"]), + ], + IsSuccess = true, + Properties = [], + TargetFrameworks = ["net8.0"], + ReferencedProjectPaths = [], + }, + new() + { + FilePath = "b/project.csproj", + Dependencies = [ + ], + IsSuccess = true, + Properties = [], + TargetFrameworks = ["net8.0"], + ReferencedProjectPaths = [], + }, + new() + { + FilePath = "c/project.csproj", + Dependencies = [ new("System.Text.Json", "6.0.0", DependencyType.Unknown, TargetFrameworks: ["net6.0"], IsTransitive: true), + new("Newtonsoft.Json", "13.0.1", DependencyType.PackagesConfig, TargetFrameworks: ["net6.0"]), ], IsSuccess = true, Properties = [], @@ -32,7 +65,7 @@ public void GetUpdatedDependencyListFromDiscovery() } ] }; - var updatedDependencyList = RunWorker.GetUpdatedDependencyListFromDiscovery(discovery); + var updatedDependencyList = RunWorker.GetUpdatedDependencyListFromDiscovery(discovery, pathToContents: temp.DirectoryPath); var expectedDependencyList = new UpdatedDependencyList() { Dependencies = @@ -46,9 +79,9 @@ public void GetUpdatedDependencyListFromDiscovery() new ReportedRequirement() { Requirement = "6.0.0", - File = "/src/project.csproj", + File = "/src/a/project.csproj", Groups = ["dependencies"], - } + }, ] }, new ReportedDependency() @@ -56,9 +89,23 @@ public void GetUpdatedDependencyListFromDiscovery() Name = "System.Text.Json", Version = "6.0.0", Requirements = [], - } + }, + new ReportedDependency() + { + Name = "Newtonsoft.Json", + Version = "13.0.1", + Requirements = + [ + new ReportedRequirement() + { + Requirement = "13.0.1", + File = "/src/c/packages.config", + Groups = ["dependencies"], + }, + ] + }, ], - DependencyFiles = ["/src/project.csproj"], + DependencyFiles = ["/src/a/project.csproj", "/src/b/project.csproj", "/src/c/project.csproj", "/src/a/packages.config", "/src/b/packages.config", "/src/c/packages.config"], }; // doing JSON comparison makes this easier; we don't have to define custom record equality and we get an easy diff diff --git a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunWorker.cs b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunWorker.cs index 1089101e80..2f8dcf2fb5 100644 --- a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunWorker.cs +++ b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunWorker.cs @@ -63,7 +63,8 @@ private async Task RunWithErrorHandlingAsync(Job job, DirectoryInfo r var result = await RunForDirectory(job, repoContentsPath, directory, baseCommitSha); foreach (var dependencyFile in result.Base64DependencyFiles) { - allDependencyFiles[dependencyFile.Name] = dependencyFile; + var uniqueKey = Path.GetFullPath(Path.Join(dependencyFile.Directory, dependencyFile.Name)).NormalizePathToUnix().EnsurePrefix("/"); + allDependencyFiles[uniqueKey] = dependencyFile; } } @@ -110,7 +111,7 @@ private async Task RunForDirectory(Job job, DirectoryInfo repoContent _logger.Log(JsonSerializer.Serialize(discoveryResult, DiscoveryWorker.SerializerOptions)); // report dependencies - var discoveredUpdatedDependencies = GetUpdatedDependencyListFromDiscovery(discoveryResult); + var discoveredUpdatedDependencies = GetUpdatedDependencyListFromDiscovery(discoveryResult, repoContentsPath.FullName); await _apiHandler.UpdateDependencyList(discoveredUpdatedDependencies); // TODO: pull out relevant dependencies, then check each for updates and track the changes @@ -134,6 +135,16 @@ await _apiHandler.IncrementMetric(new() var localPath = Path.Join(repoContentsPath.FullName, discoveryResult.Path, project.FilePath); var content = await File.ReadAllTextAsync(localPath); originalDependencyFileContents[path] = content; + + // track packages.config if it exists + var projectDirectory = Path.GetDirectoryName(project.FilePath); + var packagesConfigPath = Path.Join(repoContentsPath.FullName, discoveryResult.Path, projectDirectory, "packages.config"); + var normalizedPackagesConfigPath = Path.Join(discoveryResult.Path, projectDirectory, "packages.config").NormalizePathToUnix().EnsurePrefix("/"); + if (File.Exists(packagesConfigPath)) + { + var packagesConfigContent = await File.ReadAllTextAsync(packagesConfigPath); + originalDependencyFileContents[normalizedPackagesConfigPath] = packagesConfigContent; + } } // do update @@ -168,9 +179,15 @@ await _apiHandler.IncrementMetric(new() // TODO: log analysisResult if (analysisResult.CanUpdate) { + var dependencyLocation = Path.GetFullPath(Path.Join(discoveryResult.Path, project.FilePath).NormalizePathToUnix().EnsurePrefix("/")); + if (dependency.Type == DependencyType.PackagesConfig) + { + dependencyLocation = Path.Combine(Path.GetDirectoryName(dependencyLocation)!, "packages.config"); + } + // TODO: this is inefficient, but not likely causing a bottleneck var previousDependency = discoveredUpdatedDependencies.Dependencies - .Single(d => d.Name == dependency.Name && d.Requirements.Single().File == Path.Join(discoveryResult.Path, project.FilePath).NormalizePathToUnix().EnsurePrefix("/")); + .Single(d => d.Name == dependency.Name && d.Requirements.Single().File == dependencyLocation); var updatedDependency = new ReportedDependency() { Name = dependency.Name, @@ -179,7 +196,7 @@ await _apiHandler.IncrementMetric(new() [ new ReportedRequirement() { - File = Path.Join(discoveryResult.Path, project.FilePath).NormalizePathToUnix().EnsurePrefix("/"), + File = dependencyLocation, Requirement = analysisResult.UpdatedVersion, Groups = previousDependency.Requirements.Single().Groups, Source = new RequirementSource() @@ -198,6 +215,11 @@ await _apiHandler.IncrementMetric(new() // TODO: need to report if anything was actually updated if (updateResult.ErrorType is null || updateResult.ErrorType == ErrorType.None) { + if (dependencyLocation != dependencyFilePath) + { + updatedDependency.Requirements.All(r => r.File == dependencyFilePath); + } + actualUpdatedDependencies.Add(updatedDependency); } } @@ -208,19 +230,40 @@ await _apiHandler.IncrementMetric(new() var updatedDependencyFiles = new List(); foreach (var project in discoveryResult.Projects) { - var path = Path.Join(discoveryResult.Path, project.FilePath).NormalizePathToUnix().EnsurePrefix("/"); - var localPath = Path.Join(repoContentsPath.FullName, discoveryResult.Path, project.FilePath); - var updatedContent = await File.ReadAllTextAsync(localPath); - var originalContent = originalDependencyFileContents[path]; - if (updatedContent != originalContent) + var projectPath = Path.Join(discoveryResult.Path, project.FilePath).NormalizePathToUnix().EnsurePrefix("/"); + var localProjectPath = Path.Join(repoContentsPath.FullName, discoveryResult.Path, project.FilePath); + var updatedProjectContent = await File.ReadAllTextAsync(localProjectPath); + var originalProjectContent = originalDependencyFileContents[projectPath]; + + if (updatedProjectContent != originalProjectContent) { updatedDependencyFiles.Add(new DependencyFile() { Name = project.FilePath, - Content = updatedContent, - Directory = discoveryResult.Path, + Content = updatedProjectContent, + Directory = Path.GetDirectoryName(projectPath)!.NormalizeUnixPathParts(), }); } + + var projectDirectory = Path.GetDirectoryName(project.FilePath); + var packagesConfigPath = Path.Join(repoContentsPath.FullName, discoveryResult.Path, projectDirectory, "packages.config"); + var normalizedPackagesConfigPath = Path.Join(discoveryResult.Path, projectDirectory, "packages.config").NormalizePathToUnix().EnsurePrefix("/"); + + if (File.Exists(packagesConfigPath)) + { + var updatedPackagesConfigContent = await File.ReadAllTextAsync(packagesConfigPath); + var originalPackagesConfigContent = originalDependencyFileContents[normalizedPackagesConfigPath]; + + if (updatedPackagesConfigContent != originalPackagesConfigContent) + { + updatedDependencyFiles.Add(new DependencyFile() + { + Name = Path.Join(projectDirectory!, "packages.config"), + Content = updatedPackagesConfigContent, + Directory = Path.GetDirectoryName(normalizedPackagesConfigPath)!.NormalizeUnixPathParts(), + }); + } + } } if (updatedDependencyFiles.Count > 0) @@ -253,14 +296,14 @@ await _apiHandler.IncrementMetric(new() { Name = Path.GetFileName(kvp.Key), Content = Convert.ToBase64String(Encoding.UTF8.GetBytes(kvp.Value)), - Directory = Path.GetDirectoryName(kvp.Key)!.NormalizePathToUnix(), + Directory = Path.GetFullPath(Path.GetDirectoryName(kvp.Key)!).NormalizePathToUnix(), }).ToArray(), BaseCommitSha = baseCommitSha, }; return result; } - internal static UpdatedDependencyList GetUpdatedDependencyListFromDiscovery(WorkspaceDiscoveryResult discoveryResult) + internal static UpdatedDependencyList GetUpdatedDependencyListFromDiscovery(WorkspaceDiscoveryResult discoveryResult, string pathToContents) { string GetFullRepoPath(string path) { @@ -282,6 +325,17 @@ string GetFullRepoPath(string path) auxiliaryFiles.Add(GetFullRepoPath(discoveryResult.DirectoryPackagesProps.FilePath)); } + foreach (var project in discoveryResult.Projects) + { + var projectDirectory = Path.GetDirectoryName(project.FilePath); + var pathToPackagesConfig = Path.Join(pathToContents, discoveryResult.Path, projectDirectory, "packages.config").NormalizePathToUnix().EnsurePrefix("/"); + + if (File.Exists(pathToPackagesConfig)) + { + auxiliaryFiles.Add(GetFullRepoPath(Path.Join(projectDirectory, "packages.config"))); + } + } + var updatedDependencyList = new UpdatedDependencyList() { Dependencies = discoveryResult.Projects.SelectMany(p => @@ -292,7 +346,7 @@ string GetFullRepoPath(string path) Name = d.Name, Requirements = d.IsTransitive ? [] : [new ReportedRequirement() { - File = GetFullRepoPath(p.FilePath), + File = d.Type == DependencyType.PackagesConfig ? Path.Combine(Path.GetDirectoryName(GetFullRepoPath(p.FilePath))!, "packages.config"): GetFullRepoPath(p.FilePath), Requirement = d.Version!, Groups = ["dependencies"], }],