{"record":{"id":"aad6531b39f2d0e4","repo":"microsoft/aspire","slug":"multiple-nuget-config-files-found-in-directory-fullname","errorCode":null,"errorMessage":"Multiple NuGet.config files found in '{directory.FullName}' differing only by case.","messagePattern":"Multiple NuGet\\.config files found in '(.+?)' differing only by case\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Packaging/NuGetConfigMerger.cs","lineNumber":935,"sourceCode":"        catch\n        {\n            // If we can't read the file, assume sources are missing\n            return true;\n        }\n    }\n\n    internal static bool TryFindNuGetConfigInDirectory(DirectoryInfo directory, [NotNullWhen(true)] out FileInfo? nugetConfigFile)\n    {\n        ArgumentNullException.ThrowIfNull(directory);\n        // Find all files whose name matches \"nuget.config\" ignoring case in the top-level directory only\n        var matches = directory\n            .EnumerateFiles(\"*\", SearchOption.TopDirectoryOnly)\n            .Where(f => string.Equals(f.Name, \"nuget.config\", StringComparison.OrdinalIgnoreCase))\n            .ToArray();\n\n        if (matches.Length > 1)\n        {\n            throw new InvalidOperationException($\"Multiple NuGet.config files found in '{directory.FullName}' differing only by case.\");\n        }\n\n        nugetConfigFile = matches.SingleOrDefault();\n        return matches.Length == 1;\n    }\n\n    private static async Task AddGlobalPackagesFolderToConfigAsync(FileInfo configFile)\n    {\n        XDocument doc;\n        await using (var stream = configFile.OpenRead())\n        {\n            doc = XDocument.Load(stream);\n        }\n\n        var configuration = doc.Root ?? throw new InvalidOperationException(\"Invalid NuGet config structure\");\n        AddGlobalPackagesFolderConfiguration(configuration);\n\n        await using (var writeStream = configFile.Open(FileMode.Create, FileAccess.Write, FileShare.None))","sourceCodeStart":917,"sourceCodeEnd":953,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Packaging/NuGetConfigMerger.cs#L917-L953","documentation":"NuGetConfigMerger scans a directory (top-level only) for files named nuget.config case-insensitively; if it finds more than one that differ only by case (e.g. NuGet.config and nuget.config), it throws because the correct file to merge into is ambiguous. The merge refuses to guess which config to modify.","triggerScenarios":"Running any NuGetConfigMerger operation (Create/merge flow) in a project or directory that contains both `NuGet.config` and `nuget.config` (or `NUGET.CONFIG`, etc.) at the top level.","commonSituations":"A repo created on a case-insensitive OS (Windows/macOS) later checked out on Linux showing both casings; manual edits adding a second config with different casing; tooling generated one and a developer hand-added another.","solutions":["Delete or rename one of the duplicate configs so only a single `nuget.config` remains.","Merge the contents of both files into one canonical `NuGet.config`.","Use `git ls-files | grep -i nuget.config` to find case-duplicated files tracked by git.","On git, fix tracked casing with `git mv -f nuget.config NuGet.config` if the wrong casing is committed."],"exampleFix":"// before (directory contains NuGet.config AND nuget.config)\n// after: keep one canonical file\n// git mv -f nuget.config NuGet.config\n// git commit -m \"Deduplicate NuGet.config casing\"","handlingStrategy":"validation","validationCode":"var dupes = Directory.EnumerateFiles(dir, \"*\", SearchOption.TopDirectoryOnly)\n    .Where(f => string.Equals(Path.GetFileName(f), \"nuget.config\", StringComparison.OrdinalIgnoreCase))\n    .ToList();\nif (dupes.Count > 1) throw new InvalidOperationException($\"Multiple NuGet.config casings found: {string.Join(\", \", dupes)}\");","typeGuard":null,"tryCatchPattern":"try\n{\n    await merger.MergeAsync(targetDir, sources, ct);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Multiple NuGet.config files\"))\n{\n    Console.Error.WriteLine(\"Deduplicate NuGet.config casings before merging.\");\n}","preventionTips":["Standardize on one casing (NuGet.config) repo-wide","On Windows/macOS, check git for case-only duplicates before pushing to Linux CI","Add a CI lint that fails on case-ambiguous config filenames"],"tags":["nuget","nuget-config","case-sensitivity","filesystem"],"backgroundTag":"file-already-exists","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}