diff --git a/lib/manager/nuget/__fixtures__/with-lower-case-config-file/nuget.config b/lib/manager/nuget/__fixtures__/with-lower-case-config-file/nuget.config new file mode 100644 index 0000000000000000000000000000000000000000..6cb726de41c628cffdf4b33723bed9e7eb70610c --- /dev/null +++ b/lib/manager/nuget/__fixtures__/with-lower-case-config-file/nuget.config @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="utf-8"?> +<configuration> + <packageSources> + <clear /> + <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> + <add key="Contoso" value="https://contoso.com/packages/" /> + </packageSources> +</configuration> diff --git a/lib/manager/nuget/__fixtures__/with-lower-case-config-file/with-lower-case-config-file.csproj b/lib/manager/nuget/__fixtures__/with-lower-case-config-file/with-lower-case-config-file.csproj new file mode 100644 index 0000000000000000000000000000000000000000..d554a5fcdeb65ee3f06c9d5cc5f48ce6db3d1d3a --- /dev/null +++ b/lib/manager/nuget/__fixtures__/with-lower-case-config-file/with-lower-case-config-file.csproj @@ -0,0 +1,11 @@ +<Project Sdk="Microsoft.NET.Sdk.Web"> + + <PropertyGroup> + <TargetFramework>netcoreapp1.1</TargetFramework> + <Version>0.1.0</Version> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Autofac" Version="4.5.0" /> + </ItemGroup> +</Project> diff --git a/lib/manager/nuget/__fixtures__/with-pascal-case-config-file/NuGet.Config b/lib/manager/nuget/__fixtures__/with-pascal-case-config-file/NuGet.Config new file mode 100644 index 0000000000000000000000000000000000000000..6cb726de41c628cffdf4b33723bed9e7eb70610c --- /dev/null +++ b/lib/manager/nuget/__fixtures__/with-pascal-case-config-file/NuGet.Config @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="utf-8"?> +<configuration> + <packageSources> + <clear /> + <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> + <add key="Contoso" value="https://contoso.com/packages/" /> + </packageSources> +</configuration> diff --git a/lib/manager/nuget/__fixtures__/with-pascal-case-config-file/with-pascal-case-config-file.csproj b/lib/manager/nuget/__fixtures__/with-pascal-case-config-file/with-pascal-case-config-file.csproj new file mode 100644 index 0000000000000000000000000000000000000000..d554a5fcdeb65ee3f06c9d5cc5f48ce6db3d1d3a --- /dev/null +++ b/lib/manager/nuget/__fixtures__/with-pascal-case-config-file/with-pascal-case-config-file.csproj @@ -0,0 +1,11 @@ +<Project Sdk="Microsoft.NET.Sdk.Web"> + + <PropertyGroup> + <TargetFramework>netcoreapp1.1</TargetFramework> + <Version>0.1.0</Version> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Autofac" Version="4.5.0" /> + </ItemGroup> +</Project> diff --git a/lib/manager/nuget/__snapshots__/extract.spec.ts.snap b/lib/manager/nuget/__snapshots__/extract.spec.ts.snap index d11b650802c3035e41677ab252149aa4821ee2cf..fd536f459aea0ba25c2a5c64ed93706c0f458d6b 100644 --- a/lib/manager/nuget/__snapshots__/extract.spec.ts.snap +++ b/lib/manager/nuget/__snapshots__/extract.spec.ts.snap @@ -17,6 +17,40 @@ Object { } `; +exports[`lib/manager/nuget/extract extractPackageFile() considers lower-case nuget.config 1`] = ` +Object { + "deps": Array [ + Object { + "currentValue": "4.5.0", + "datasource": "nuget", + "depName": "Autofac", + "depType": "nuget", + "registryUrls": Array [ + "https://api.nuget.org/v3/index.json#protocolVersion=3", + "https://contoso.com/packages/", + ], + }, + ], +} +`; + +exports[`lib/manager/nuget/extract extractPackageFile() considers pascal-case NuGet.Config 1`] = ` +Object { + "deps": Array [ + Object { + "currentValue": "4.5.0", + "datasource": "nuget", + "depName": "Autofac", + "depType": "nuget", + "registryUrls": Array [ + "https://api.nuget.org/v3/index.json#protocolVersion=3", + "https://contoso.com/packages/", + ], + }, + ], +} +`; + exports[`lib/manager/nuget/extract extractPackageFile() extracts all dependencies 1`] = ` Array [ Object { diff --git a/lib/manager/nuget/extract.spec.ts b/lib/manager/nuget/extract.spec.ts index dc470b481f336848e41dcf1066ab9050f8614cc6..e7733fb42003b6c6116ea5c85a58cff52922b0a2 100644 --- a/lib/manager/nuget/extract.spec.ts +++ b/lib/manager/nuget/extract.spec.ts @@ -24,6 +24,7 @@ describe('lib/manager/nuget/extract', () => { const res = await extractPackageFile(sample, packageFile, config); expect(res.deps).toMatchSnapshot(); }); + it('considers NuGet.config', async () => { const packageFile = 'with-config-file/with-config-file.csproj'; const contents = readFileSync( @@ -35,6 +36,30 @@ describe('lib/manager/nuget/extract', () => { await extractPackageFile(contents, packageFile, config) ).toMatchSnapshot(); }); + it('considers lower-case nuget.config', async () => { + const packageFile = + 'with-lower-case-config-file/with-lower-case-config-file.csproj'; + const contents = readFileSync( + path.join(config.localDir, packageFile), + 'utf8' + ); + + expect( + await extractPackageFile(contents, packageFile, config) + ).toMatchSnapshot(); + }); + it('considers pascal-case NuGet.Config', async () => { + const packageFile = + 'with-pascal-case-config-file/with-pascal-case-config-file.csproj'; + const contents = readFileSync( + path.join(config.localDir, packageFile), + 'utf8' + ); + + expect( + await extractPackageFile(contents, packageFile, config) + ).toMatchSnapshot(); + }); it('handles malformed NuGet.config', async () => { const packageFile = 'with-malformed-config-file/with-malformed-config-file.csproj'; diff --git a/lib/manager/nuget/extract.ts b/lib/manager/nuget/extract.ts index 6c2a87287c5a7f7705f31169886587bc8205b19f..ea190eae9ecc377c3ba4514e552941988124e982 100644 --- a/lib/manager/nuget/extract.ts +++ b/lib/manager/nuget/extract.ts @@ -22,7 +22,9 @@ async function determineRegistryUrls( packageFile: string, localDir: string ): Promise<string[]> { - const nuGetConfigPath = await findUp('NuGet.config', { + // Valid file names taken from https://github.com/NuGet/NuGet.Client/blob/f64621487c0b454eda4b98af853bf4a528bef72a/src/NuGet.Core/NuGet.Configuration/Settings/Settings.cs#L34 + const nuGetConfigFileNames = ['nuget.config', 'NuGet.config', 'NuGet.Config']; + const nuGetConfigPath = await findUp(nuGetConfigFileNames, { cwd: path.dirname(path.join(localDir, packageFile)), type: 'file', });