diff --git a/lib/manager/nuget/__fixtures__/packages.props b/lib/manager/nuget/__fixtures__/packages.props new file mode 100644 index 0000000000000000000000000000000000000000..5f910a5ecf9708001b0b06d8276078611bc426ce --- /dev/null +++ b/lib/manager/nuget/__fixtures__/packages.props @@ -0,0 +1,30 @@ +<Project> + <ItemGroup> + <GlobalPackageReference Include="Roslynator.Analyzers" Version="2.0.0" /> + </ItemGroup> + <ItemGroup> + <PackageReference Update="Autofac" Version="4.5.0" /> + <PackageReference Update="Autofac.Extensions.DependencyInjection" Version="4.1.0" /> + <PackageReference Update="Microsoft.AspNetCore.Hosting" Version="1.1.2" /> + <PackageReference Update="Microsoft.AspNetCore.Mvc.Core" Version="1.1.3" /> + <PackageReference Update="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.2" /> + <PackageReference Update="Microsoft.Extensions.Configuration.Json" Version="1.1.2" /> + <PackageReference Update="Microsoft.Extensions.Logging.Debug" Version="1.1.2" /> + <PackageReference Update="Newtonsoft.Json" Version="10.0.2" /> + <PackageReference Update="Serilog" Version="2.4.0" /> + <PackageReference Update="Serilog.Extensions.Logging" Version="1.4.0" /> + <PackageReference Update="Serilog.Sinks.Literate" Version="2.1.0" /> + <PackageReference Update="Stateless" Version="3.1.0.5" /> + <PackageReference Update="Range1" Version="[1.2.3]" /> + <PackageReference Update="Range2" Version="[1.2.3,]" /> + <PackageReference Update="Range3" Version="[1.2.3,)" /> + <PackageReference Update="NotUpdatable1" Version="[,1.2.3)" /> + <PackageReference Update="NotUpdatable2" Version="(1.2.3,)" /> + <PackageReference Update="NotUpdatable3" Version="(1.2.3, 3.2.1)" /> + <PackageReference Update="NotUpdatable3" Version="[1.2.3, 3.2.1]" /> + <PackageReference Update="NotUpdatable3" Version="[1.2.3, 3.2.1)" /> + </ItemGroup> + <ItemGroup> + <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" /> + </ItemGroup> +</Project> diff --git a/lib/manager/nuget/__fixtures__/sample.csproj b/lib/manager/nuget/__fixtures__/sample.csproj index 4cf2b5330988484dd7e1665185137c8b2db69835..168c0ae5c0c43a8e9c3df32890c064aecb27d52a 100644 --- a/lib/manager/nuget/__fixtures__/sample.csproj +++ b/lib/manager/nuget/__fixtures__/sample.csproj @@ -17,7 +17,7 @@ <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.2" /> <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.2" /> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" /> - <PackageReference Include="Newtonsoft.Json" Version="10.0.2" /> + <PackageReference Include="Newtonsoft.Json" VersionOverride="10.0.2" /> <PackageReference Include="Serilog" Version="2.4.0" /> <PackageReference Include="Serilog.Extensions.Logging" Version="1.4.0" /> <PackageReference Include="Serilog.Sinks.Literate" Version="2.1.0" /> diff --git a/lib/manager/nuget/__snapshots__/extract.spec.ts.snap b/lib/manager/nuget/__snapshots__/extract.spec.ts.snap index 0fe675cd4a82d404b6a6bd5dcd1c9f0e61192f85..a43c2df0d522a18d68b1c9554ad286f32fed7796 100644 --- a/lib/manager/nuget/__snapshots__/extract.spec.ts.snap +++ b/lib/manager/nuget/__snapshots__/extract.spec.ts.snap @@ -217,6 +217,114 @@ Object { } `; +exports[`lib/manager/nuget/extract extractPackageFile() extracts all dependencies from global packages file 1`] = ` +Array [ + Object { + "currentValue": "2.0.0", + "datasource": "nuget", + "depName": "Roslynator.Analyzers", + "depType": "nuget", + }, + Object { + "currentValue": "4.5.0", + "datasource": "nuget", + "depName": "Autofac", + "depType": "nuget", + }, + Object { + "currentValue": "4.1.0", + "datasource": "nuget", + "depName": "Autofac.Extensions.DependencyInjection", + "depType": "nuget", + }, + Object { + "currentValue": "1.1.2", + "datasource": "nuget", + "depName": "Microsoft.AspNetCore.Hosting", + "depType": "nuget", + }, + Object { + "currentValue": "1.1.3", + "datasource": "nuget", + "depName": "Microsoft.AspNetCore.Mvc.Core", + "depType": "nuget", + }, + Object { + "currentValue": "1.1.2", + "datasource": "nuget", + "depName": "Microsoft.AspNetCore.Server.Kestrel", + "depType": "nuget", + }, + Object { + "currentValue": "1.1.2", + "datasource": "nuget", + "depName": "Microsoft.Extensions.Configuration.Json", + "depType": "nuget", + }, + Object { + "currentValue": "1.1.2", + "datasource": "nuget", + "depName": "Microsoft.Extensions.Logging.Debug", + "depType": "nuget", + }, + Object { + "currentValue": "10.0.2", + "datasource": "nuget", + "depName": "Newtonsoft.Json", + "depType": "nuget", + }, + Object { + "currentValue": "2.4.0", + "datasource": "nuget", + "depName": "Serilog", + "depType": "nuget", + }, + Object { + "currentValue": "1.4.0", + "datasource": "nuget", + "depName": "Serilog.Extensions.Logging", + "depType": "nuget", + }, + Object { + "currentValue": "2.1.0", + "datasource": "nuget", + "depName": "Serilog.Sinks.Literate", + "depType": "nuget", + }, + Object { + "currentValue": "3.1.0.5", + "datasource": "nuget", + "depName": "Stateless", + "depType": "nuget", + "skipReason": "not-a-version", + }, + Object { + "currentValue": "1.2.3", + "datasource": "nuget", + "depName": "Range1", + "depType": "nuget", + }, + Object { + "currentValue": "1.2.3", + "datasource": "nuget", + "depName": "Range2", + "depType": "nuget", + }, + Object { + "currentValue": "1.2.3", + "datasource": "nuget", + "depName": "Range3", + "depType": "nuget", + }, + Object { + "currentValue": "1.0.0", + "datasource": "nuget", + "depName": "Microsoft.VisualStudio.Web.CodeGeneration.Tools", + "depType": "nuget", + }, +] +`; + exports[`lib/manager/nuget/extract extractPackageFile() handles NuGet.config without package sources 1`] = ` Object { "deps": Array [ diff --git a/lib/manager/nuget/extract.spec.ts b/lib/manager/nuget/extract.spec.ts index f8ffec06c7a75d0ec891f33fb49f4649b09d9e1b..dc5a8477b9514ca15ee32ea97623717ca183f14e 100644 --- a/lib/manager/nuget/extract.spec.ts +++ b/lib/manager/nuget/extract.spec.ts @@ -25,7 +25,15 @@ describe('lib/manager/nuget/extract', () => { const res = await extractPackageFile(sample, packageFile, config); expect(res.deps).toMatchSnapshot(); }); - + it('extracts all dependencies from global packages file', async () => { + const packageFile = 'packages.props'; + const sample = readFileSync( + path.join(config.localDir, packageFile), + 'utf8' + ); + 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( diff --git a/lib/manager/nuget/extract.ts b/lib/manager/nuget/extract.ts index a6c31c46f512fb2bd17027557cda80be4ba796ea..0b7a2b4228925e1b96ab1152b55323e17d77c54d 100644 --- a/lib/manager/nuget/extract.ts +++ b/lib/manager/nuget/extract.ts @@ -74,7 +74,7 @@ async function determineRegistryUrls( return registryUrls; } -const packageRe = /<(?:PackageReference|DotNetCliToolReference).*Include\s*=\s*"([^"]+)".*Version\s*=\s*"(?:[[])?(?:([^"(,[\]]+)\s*(?:,\s*[)\]]|])?)"/; +const packageRe = /<(?:PackageReference|DotNetCliToolReference|GlobalPackageReference).*(?:Include|Update)\s*=\s*"(?<depName>[^"]+)".*(?:Version|VersionOverride)\s*=\s*"(?:[[])?(?:(?<currentValue>[^"(,[\]]+)\s*(?:,\s*[)\]]|])?)"/; export async function extractPackageFile( content: string, packageFile: string, @@ -138,8 +138,7 @@ export async function extractPackageFile( const match = packageRe.exec(line); if (match) { - const depName = match[1]; - const currentValue = match[2]; + const { currentValue, depName } = match.groups; const dep: PackageDependency = { depType: 'nuget', depName,