From 949158bf8d2439e2478b905617ee56237defa52e Mon Sep 17 00:00:00 2001 From: Michael Waddell Date: Wed, 26 Jan 2022 10:20:40 -0600 Subject: [PATCH 1/5] Adding "devDependencies" support for nuget projects. - Addresses issue #4659 - Supports `ItemGroup > DevelopmentDependency` groups in `.csproj` files - Supports `developmentDependency="true"` in `packages.config` - Does **not** support development dependencies specified using the `Condition=` property in ``, etc. --- .../file_parser/packages_config_parser.rb | 8 ++- .../nuget/file_parser/project_file_parser.rb | 24 ++++++-- .../packages_config_parser_spec.rb | 21 ++++++- .../file_parser/project_file_parser_spec.rb | 61 ++++++++++++++----- .../spec/dependabot/nuget/file_parser_spec.rb | 58 +++++++++++++++--- ...packages_config_declaration_finder_spec.rb | 2 +- .../project_file_declaration_finder_spec.rb | 2 +- .../dependabot/nuget/file_updater_spec.rb | 32 +++++----- .../dependabot/nuget/metadata_finder_spec.rb | 2 +- .../update_checker/repository_finder_spec.rb | 2 +- .../requirements_updater_spec.rb | 12 ++-- .../update_checker/version_finder_spec.rb | 8 ++- .../dependabot/nuget/update_checker_spec.rb | 28 ++++----- nuget/spec/fixtures/csproj/basic.nuproj | 3 + .../fixtures/packages_configs/packages.config | 2 +- 15 files changed, 189 insertions(+), 76 deletions(-) diff --git a/nuget/lib/dependabot/nuget/file_parser/packages_config_parser.rb b/nuget/lib/dependabot/nuget/file_parser/packages_config_parser.rb index b45935bf5d..8e3dc1323b 100644 --- a/nuget/lib/dependabot/nuget/file_parser/packages_config_parser.rb +++ b/nuget/lib/dependabot/nuget/file_parser/packages_config_parser.rb @@ -33,7 +33,7 @@ def dependency_set requirements: [{ requirement: dependency_version(dependency_node), file: packages_config.name, - groups: [], + groups: [dependency_type(dependency_node)], source: nil }] ) @@ -57,6 +57,12 @@ def dependency_version(dependency_node) dependency_node.attribute("version")&.value&.strip || dependency_node.at_xpath("./version")&.content&.strip end + + def dependency_type(dependency_node) + val = dependency_node.attribute("developmentDependency")&.value&.strip || + dependency_node.at_xpath("./developmentDependency")&.content&.strip + val.to_s.downcase == "true" ? "devDependencies" : "dependencies" + end end end end diff --git a/nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb b/nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb index 8e53432a5c..2d1628c73c 100644 --- a/nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb +++ b/nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb @@ -17,8 +17,8 @@ class ProjectFileParser DEPENDENCY_SELECTOR = "ItemGroup > PackageReference, "\ "ItemGroup > GlobalPackageReference, "\ "ItemGroup > PackageVersion, "\ - "ItemGroup > Dependency, "\ - "ItemGroup > DevelopmentDependency" + "ItemGroup > Dependency" + DEV_SELECTOR = "ItemGroup > DevelopmentDependency" PROJECT_SDK_REGEX = %r{^([^/]+)/(\d+(?:[.]\d+(?:[.]\d+)?)?(?:[+-].*)?)$}.freeze PROPERTY_REGEX = /\$\((?.*?)\)/.freeze @@ -33,7 +33,7 @@ def dependency_set(project_file:) doc = Nokogiri::XML(project_file.content) doc.remove_namespaces! - # Look for regular package references + # Look for regular package references (production) doc.css(DEPENDENCY_SELECTOR).each do |dependency_node| name = dependency_name(dependency_node, project_file) req = dependency_requirement(dependency_node, project_file) @@ -43,6 +43,18 @@ def dependency_set(project_file:) dependency = build_dependency(name, req, version, prop_name, project_file) dependency_set << dependency if dependency end + + # Look for regular package references (development) + doc.css(DEV_SELECTOR).each do |dependency_node| + name = dependency_name(dependency_node, project_file) + req = dependency_requirement(dependency_node, project_file) + version = dependency_version(dependency_node, project_file) + prop_name = req_property_name(dependency_node) + + dependency = build_dependency(name, req, version, prop_name, project_file, true) + dependency_set << dependency if dependency + end + # Look for SDK references; see: # https://docs.microsoft.com/en-us/visualstudio/msbuild/how-to-use-project-sdk add_sdk_references(doc, dependency_set, project_file) @@ -109,7 +121,8 @@ def add_sdk_refs_from_sdk_tags(doc, dependency_set, project_file) end end - def build_dependency(name, req, version, prop_name, project_file) + # rubocop:disable Metrics/ParameterLists + def build_dependency(name, req, version, prop_name, project_file, dev = false) return unless name # Exclude any dependencies specified using interpolation @@ -118,7 +131,7 @@ def build_dependency(name, req, version, prop_name, project_file) requirement = { requirement: req, file: project_file.name, - groups: [], + groups: [dev ? "devDependencies" : "dependencies"], source: nil } @@ -137,6 +150,7 @@ def build_dependency(name, req, version, prop_name, project_file) requirements: [requirement] ) end + # rubocop:enable Metrics/ParameterLists # rubocop:disable Metrics/PerceivedComplexity def dependency_name(dependency_node, project_file) diff --git a/nuget/spec/dependabot/nuget/file_parser/packages_config_parser_spec.rb b/nuget/spec/dependabot/nuget/file_parser/packages_config_parser_spec.rb index 58bd0bfebd..9a4f6ac6d2 100644 --- a/nuget/spec/dependabot/nuget/file_parser/packages_config_parser_spec.rb +++ b/nuget/spec/dependabot/nuget/file_parser/packages_config_parser_spec.rb @@ -34,7 +34,26 @@ [{ requirement: "1.0.0", file: "packages.config", - groups: [], + groups: ["dependencies"], + source: nil + }] + ) + end + end + + describe "the second dependency" do + subject(:dependency) { dependencies.at(1) } + + it "has the right details" do + expect(dependency).to be_a(Dependabot::Dependency) + expect(dependency.name). + to eq("Microsoft.Net.Compilers") + expect(dependency.version).to eq("1.0.1") + expect(dependency.requirements).to eq( + [{ + requirement: "1.0.1", + file: "packages.config", + groups: ["devDependencies"], source: nil }] ) diff --git a/nuget/spec/dependabot/nuget/file_parser/project_file_parser_spec.rb b/nuget/spec/dependabot/nuget/file_parser/project_file_parser_spec.rb index 8c43fb2c3f..1adfd496e2 100644 --- a/nuget/spec/dependabot/nuget/file_parser/project_file_parser_spec.rb +++ b/nuget/spec/dependabot/nuget/file_parser/project_file_parser_spec.rb @@ -33,7 +33,7 @@ [{ requirement: "1.1.1", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil }] ) @@ -51,7 +51,7 @@ [{ requirement: nil, file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil }] ) @@ -69,7 +69,7 @@ [{ requirement: "4.3.0", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil }] ) @@ -167,7 +167,7 @@ [{ requirement: "0.1.434", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil, metadata: { property_name: "NukeVersion" } }] @@ -192,7 +192,7 @@ [{ requirement: "0.1.434", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil, metadata: { property_name: "NukeVersion" } }] @@ -218,7 +218,7 @@ [{ requirement: "$(UnknownVersion)", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil, metadata: { property_name: "UnknownVersion" } }] @@ -231,9 +231,40 @@ context "with a nuproj" do let(:file_body) { fixture("csproj", "basic.nuproj") } - it "has the right details" do - expect(dependencies.map(&:name)). - to match_array(%w(nanoFramework.CoreLibrary)) + it "gets the right number of dependencies" do + expect(dependencies.count).to eq(2) + end + + describe "the first dependency" do + subject(:dependency) { dependencies.first } + + it "has the right details" do + expect(dependency).to be_a(Dependabot::Dependency) + expect(dependency.name).to eq("nanoFramework.CoreLibrary") + expect(dependency.version).to eq("1.0.0-preview062") + expect(dependency.requirements).to eq([{ + requirement: "[1.0.0-preview062]", + file: "my.csproj", + groups: ["dependencies"], + source: nil + }]) + end + end + + describe "the second dependency" do + subject(:dependency) { dependencies.at(1) } + + it "has the right details" do + expect(dependency).to be_a(Dependabot::Dependency) + expect(dependency.name).to eq("nanoFramework.CoreExtra") + expect(dependency.version).to eq("1.0.0-preview061") + expect(dependency.requirements).to eq([{ + requirement: "[1.0.0-preview061]", + file: "my.csproj", + groups: ["devDependencies"], + source: nil + }]) + end end end @@ -261,7 +292,7 @@ expect(dependency.requirements).to eq([{ requirement: "1.2.3", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil }]) end @@ -277,7 +308,7 @@ expect(dependency.requirements).to eq([{ requirement: "0.1.0-beta", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil }]) end @@ -299,7 +330,7 @@ expect(dependency.requirements).to eq([{ requirement: "1.2.3", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil }]) end @@ -315,7 +346,7 @@ expect(dependency.requirements).to eq([{ requirement: "0.1.0-beta", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil }]) end @@ -337,7 +368,7 @@ expect(dependency.requirements).to eq([{ requirement: "1.2.3", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil }]) end @@ -353,7 +384,7 @@ expect(dependency.requirements).to eq([{ requirement: "0.1.0-beta", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil }]) end diff --git a/nuget/spec/dependabot/nuget/file_parser_spec.rb b/nuget/spec/dependabot/nuget/file_parser_spec.rb index e1b3c8fc3d..5ebfc621fc 100644 --- a/nuget/spec/dependabot/nuget/file_parser_spec.rb +++ b/nuget/spec/dependabot/nuget/file_parser_spec.rb @@ -38,7 +38,7 @@ [{ requirement: "1.1.1", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil }] ) @@ -56,7 +56,7 @@ [{ requirement: "4.3.0", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil }] ) @@ -85,12 +85,12 @@ [{ requirement: "1.1.1", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil }, { requirement: "1.0.1", file: "my.vbproj", - groups: [], + groups: ["dependencies"], source: nil }] ) @@ -108,7 +108,7 @@ [{ requirement: "2.3.0", file: "my.vbproj", - groups: [], + groups: ["dependencies"], source: nil }] ) @@ -139,7 +139,26 @@ [{ requirement: "1.0.0", file: "packages.config", - groups: [], + groups: ["dependencies"], + source: nil + }] + ) + end + end + + describe "the second dependency" do + subject(:dependency) { dependencies.at(1) } + + it "has the right details" do + expect(dependency).to be_a(Dependabot::Dependency) + expect(dependency.name). + to eq("Microsoft.Net.Compilers") + expect(dependency.version).to eq("1.0.1") + expect(dependency.requirements).to eq( + [{ + requirement: "1.0.1", + file: "packages.config", + groups: ["devDependencies"], source: nil }] ) @@ -167,7 +186,26 @@ [{ requirement: "1.0.0", file: "dir/packages.config", - groups: [], + groups: ["dependencies"], + source: nil + }] + ) + end + end + + describe "the second dependency" do + subject(:dependency) { dependencies.at(1) } + + it "has the right details" do + expect(dependency).to be_a(Dependabot::Dependency) + expect(dependency.name). + to eq("Microsoft.Net.Compilers") + expect(dependency.version).to eq("1.0.1") + expect(dependency.requirements).to eq( + [{ + requirement: "1.0.1", + file: "dir/packages.config", + groups: ["devDependencies"], source: nil }] ) @@ -234,7 +272,7 @@ [{ requirement: "2.3.0", file: "commonprops.props", - groups: [], + groups: ["dependencies"], source: nil }] ) @@ -264,7 +302,7 @@ [{ requirement: "1.1.1", file: "packages.props", - groups: [], + groups: ["dependencies"], source: nil }] ) @@ -294,7 +332,7 @@ [{ requirement: "1.1.1", file: "directory.packages.props", - groups: [], + groups: ["dependencies"], source: nil }] ) diff --git a/nuget/spec/dependabot/nuget/file_updater/packages_config_declaration_finder_spec.rb b/nuget/spec/dependabot/nuget/file_updater/packages_config_declaration_finder_spec.rb index af40d20a2d..93dac985e8 100644 --- a/nuget/spec/dependabot/nuget/file_updater/packages_config_declaration_finder_spec.rb +++ b/nuget/spec/dependabot/nuget/file_updater/packages_config_declaration_finder_spec.rb @@ -20,7 +20,7 @@ { requirement: declaring_requirement_string, file: "packages.config", - groups: [], + groups: ["dependencies"], source: nil } end diff --git a/nuget/spec/dependabot/nuget/file_updater/project_file_declaration_finder_spec.rb b/nuget/spec/dependabot/nuget/file_updater/project_file_declaration_finder_spec.rb index 9b63f85a34..a1fbe8b83d 100644 --- a/nuget/spec/dependabot/nuget/file_updater/project_file_declaration_finder_spec.rb +++ b/nuget/spec/dependabot/nuget/file_updater/project_file_declaration_finder_spec.rb @@ -20,7 +20,7 @@ { requirement: declaring_requirement_string, file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil } end diff --git a/nuget/spec/dependabot/nuget/file_updater_spec.rb b/nuget/spec/dependabot/nuget/file_updater_spec.rb index 32d69ea67d..f35518ae58 100644 --- a/nuget/spec/dependabot/nuget/file_updater_spec.rb +++ b/nuget/spec/dependabot/nuget/file_updater_spec.rb @@ -44,7 +44,7 @@ [{ file: "my.csproj", requirement: "1.1.2", - groups: [], + groups: ["dependencies"], source: nil }] end @@ -52,7 +52,7 @@ [{ file: "my.csproj", requirement: "1.1.1", - groups: [], + groups: ["dependencies"], source: nil }] end @@ -87,7 +87,7 @@ [{ file: "my.csproj", requirement: "[1.0,2.1]", - groups: [], + groups: ["dependencies"], source: nil }] end @@ -95,7 +95,7 @@ [{ file: "my.csproj", requirement: "[1.0,2.0]", - groups: [], + groups: ["dependencies"], source: nil }] end @@ -114,7 +114,7 @@ [{ requirement: "0.1.500", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil, metadata: { property_name: "NukeVersion" } }] @@ -123,7 +123,7 @@ [{ requirement: "0.1.434", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil, metadata: { property_name: "NukeVersion" } }] @@ -147,7 +147,7 @@ [{ requirement: "1.2.3", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil }] end @@ -155,7 +155,7 @@ [{ requirement: "1.1.1", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil }] end @@ -195,7 +195,7 @@ [{ file: "packages.config", requirement: "8.0.4", - groups: [], + groups: ["dependencies"], source: nil }] end @@ -203,7 +203,7 @@ [{ file: "packages.config", requirement: "8.0.3", - groups: [], + groups: ["dependencies"], source: nil }] end @@ -237,7 +237,7 @@ [{ file: "dir/packages.config", requirement: "8.0.4", - groups: [], + groups: ["dependencies"], source: nil }] end @@ -245,7 +245,7 @@ [{ file: "dir/packages.config", requirement: "8.0.3", - groups: [], + groups: ["dependencies"], source: nil }] end @@ -281,23 +281,23 @@ requirements: [{ file: "my.csproj", requirement: "1.1.2", - groups: [], + groups: ["dependencies"], source: nil }, { file: "my.vbproj", requirement: "1.1.*", - groups: [], + groups: ["dependencies"], source: nil }], previous_requirements: [{ file: "my.csproj", requirement: "1.1.1", - groups: [], + groups: ["dependencies"], source: nil }, { file: "my.vbproj", requirement: "1.0.1", - groups: [], + groups: ["dependencies"], source: nil }], package_manager: "nuget" diff --git a/nuget/spec/dependabot/nuget/metadata_finder_spec.rb b/nuget/spec/dependabot/nuget/metadata_finder_spec.rb index ec185f4d94..d6028dc099 100644 --- a/nuget/spec/dependabot/nuget/metadata_finder_spec.rb +++ b/nuget/spec/dependabot/nuget/metadata_finder_spec.rb @@ -15,7 +15,7 @@ requirements: [{ file: "my.csproj", requirement: dependency_version, - groups: [], + groups: ["dependencies"], source: source }], package_manager: "nuget" diff --git a/nuget/spec/dependabot/nuget/update_checker/repository_finder_spec.rb b/nuget/spec/dependabot/nuget/update_checker/repository_finder_spec.rb index 3e44591f33..e26c465cac 100644 --- a/nuget/spec/dependabot/nuget/update_checker/repository_finder_spec.rb +++ b/nuget/spec/dependabot/nuget/update_checker/repository_finder_spec.rb @@ -29,7 +29,7 @@ requirements: [{ requirement: "1.1.1", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil }], package_manager: "nuget" diff --git a/nuget/spec/dependabot/nuget/update_checker/requirements_updater_spec.rb b/nuget/spec/dependabot/nuget/update_checker/requirements_updater_spec.rb index 74960d974b..556371eede 100644 --- a/nuget/spec/dependabot/nuget/update_checker/requirements_updater_spec.rb +++ b/nuget/spec/dependabot/nuget/update_checker/requirements_updater_spec.rb @@ -17,7 +17,7 @@ { file: "my.csproj", requirement: csproj_req_string, - groups: [], + groups: ["dependencies"], source: nil } end @@ -100,7 +100,7 @@ { file: "another/my.csproj", requirement: other_requirement_string, - groups: [], + groups: ["dependencies"], source: nil } end @@ -112,7 +112,7 @@ [{ file: "my.csproj", requirement: "23.6-jre", - groups: [], + groups: ["dependencies"], source: { type: "nuget_repo", url: "https://api.nuget.org/v3/index.json", @@ -124,7 +124,7 @@ }, { file: "another/my.csproj", requirement: "[23.6-jre]", - groups: [], + groups: ["dependencies"], source: { type: "nuget_repo", url: "https://api.nuget.org/v3/index.json", @@ -145,7 +145,7 @@ [{ file: "my.csproj", requirement: "23.6-jre", - groups: [], + groups: ["dependencies"], source: { type: "nuget_repo", url: "https://api.nuget.org/v3/index.json", @@ -157,7 +157,7 @@ }, { file: "another/my.csproj", requirement: "[23.0,)", - groups: [], + groups: ["dependencies"], source: nil }] ) diff --git a/nuget/spec/dependabot/nuget/update_checker/version_finder_spec.rb b/nuget/spec/dependabot/nuget/update_checker/version_finder_spec.rb index da7dc7de9d..3b4cc626eb 100644 --- a/nuget/spec/dependabot/nuget/update_checker/version_finder_spec.rb +++ b/nuget/spec/dependabot/nuget/update_checker/version_finder_spec.rb @@ -26,7 +26,7 @@ ) end let(:dependency_requirements) do - [{ file: "my.csproj", requirement: "1.1.1", groups: [], source: nil }] + [{ file: "my.csproj", requirement: "1.1.1", groups: ["dependencies"], source: nil }] end let(:dependency_name) { "Microsoft.Extensions.DependencyModel" } let(:dependency_version) { "1.1.1" } @@ -286,7 +286,9 @@ context "with a package that returns paginated api results when using the v2 nuget api", :vcr do let(:dependency_files) { project_dependency_files("paginated_package_v2_api") } - let(:dependency_requirements) { [{ file: "my.csproj", requirement: "4.7.1", groups: [], source: nil }] } + let(:dependency_requirements) do + [{ file: "my.csproj", requirement: "4.7.1", groups: ["dependencies"], source: nil }] + end let(:dependency_name) { "FakeItEasy" } let(:dependency_version) { "4.7.1" } @@ -361,7 +363,7 @@ let(:dependency_files) { project_dependency_files("version_range") } let(:dependency_version) { "1.1.0" } let(:dependency_requirements) do - [{ file: "my.csproj", requirement: "[1.1.0, 3.0.0)", groups: [], source: nil }] + [{ file: "my.csproj", requirement: "[1.1.0, 3.0.0)", groups: ["dependencies"], source: nil }] end its([:version]) { is_expected.to eq(version_class.new("2.1.0")) } diff --git a/nuget/spec/dependabot/nuget/update_checker_spec.rb b/nuget/spec/dependabot/nuget/update_checker_spec.rb index fddb16211d..52c811f5f8 100644 --- a/nuget/spec/dependabot/nuget/update_checker_spec.rb +++ b/nuget/spec/dependabot/nuget/update_checker_spec.rb @@ -28,7 +28,7 @@ ) end let(:dependency_requirements) do - [{ file: "my.csproj", requirement: "1.1.1", groups: [], source: nil }] + [{ file: "my.csproj", requirement: "1.1.1", groups: ["dependencies"], source: nil }] end let(:dependency_name) { "Microsoft.Extensions.DependencyModel" } let(:dependency_version) { "1.1.1" } @@ -83,7 +83,7 @@ [{ requirement: "$(NukeVersion)", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil, metadata: { property_name: "NukeVersion" } }] @@ -150,7 +150,7 @@ [{ requirement: "0.1.434", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil, metadata: { property_name: "NukeVersion" } }] @@ -216,7 +216,7 @@ [{ requirement: "0.1.434", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil, metadata: { property_name: "NukeVersion" } }] @@ -294,7 +294,7 @@ [{ file: "my.csproj", requirement: "2.1.0", - groups: [], + groups: ["dependencies"], source: { type: "nuget_repo", url: "https://api.nuget.org/v3/index.json", @@ -335,7 +335,7 @@ [{ file: "my.csproj", requirement: "2.0.0", - groups: [], + groups: ["dependencies"], source: { type: "nuget_repo", url: "https://api.nuget.org/v3/index.json", @@ -425,7 +425,7 @@ [{ file: "my.csproj", requirement: "4.8.1", - groups: [], + groups: ["dependencies"], source: { type: "nuget_repo", url: "https://www.nuget.org/api/v2", @@ -449,7 +449,7 @@ [{ requirement: "0.1.434", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil, metadata: { property_name: "NukeVersion" } }] @@ -464,7 +464,7 @@ [{ requirement: "$(NukeVersion)", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil, metadata: { property_name: "NukeVersion" } }] @@ -486,7 +486,7 @@ [{ requirement: "0.1.434", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil, metadata: { property_name: "NukeVersion" } }] @@ -531,7 +531,7 @@ requirements: [{ requirement: "0.9.0", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: { type: "nuget_repo", url: "https://api.nuget.org/v3/index.json", @@ -544,7 +544,7 @@ previous_requirements: [{ requirement: "0.1.434", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil, metadata: { property_name: "NukeVersion" } }], @@ -557,7 +557,7 @@ requirements: [{ requirement: "0.9.0", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: { type: "nuget_repo", url: "https://api.nuget.org/v3/index.json", @@ -570,7 +570,7 @@ previous_requirements: [{ requirement: "0.1.434", file: "my.csproj", - groups: [], + groups: ["dependencies"], source: nil, metadata: { property_name: "NukeVersion" } }], diff --git a/nuget/spec/fixtures/csproj/basic.nuproj b/nuget/spec/fixtures/csproj/basic.nuproj index f560855004..704eaba8a9 100644 --- a/nuget/spec/fixtures/csproj/basic.nuproj +++ b/nuget/spec/fixtures/csproj/basic.nuproj @@ -34,6 +34,9 @@ [1.0.0-preview062] + + [1.0.0-preview061] + 43cd93bb-c6c4-4f8e-b1ed-406469d9db42 diff --git a/nuget/spec/fixtures/packages_configs/packages.config b/nuget/spec/fixtures/packages_configs/packages.config index 3ca4c9c08d..050da0e9e9 100644 --- a/nuget/spec/fixtures/packages_configs/packages.config +++ b/nuget/spec/fixtures/packages_configs/packages.config @@ -1,7 +1,7 @@ - + From d9e2f5f96bbe80b3190ebcbbd869c62ecbf1f9ae Mon Sep 17 00:00:00 2001 From: Michael Waddell Date: Wed, 26 Jan 2022 11:34:56 -0600 Subject: [PATCH 2/5] Update nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb Co-authored-by: Philip Harrison --- nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb b/nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb index 2d1628c73c..c55b096fa7 100644 --- a/nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb +++ b/nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb @@ -122,7 +122,7 @@ def add_sdk_refs_from_sdk_tags(doc, dependency_set, project_file) end # rubocop:disable Metrics/ParameterLists - def build_dependency(name, req, version, prop_name, project_file, dev = false) + def build_dependency(name, req, version, prop_name, project_file, dev: false) return unless name # Exclude any dependencies specified using interpolation From 6d6d17e3e8ea7b743527846a202a31cad2024c9e Mon Sep 17 00:00:00 2001 From: Michael Waddell Date: Wed, 26 Jan 2022 11:35:18 -0600 Subject: [PATCH 3/5] Update nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb Co-authored-by: Philip Harrison --- nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb b/nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb index c55b096fa7..92173c435f 100644 --- a/nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb +++ b/nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb @@ -51,7 +51,7 @@ def dependency_set(project_file:) version = dependency_version(dependency_node, project_file) prop_name = req_property_name(dependency_node) - dependency = build_dependency(name, req, version, prop_name, project_file, true) + dependency = build_dependency(name, req, version, prop_name, project_file, dev: true) dependency_set << dependency if dependency end From 2b06b3212bb5f9d0617ff9828c30cd2b8910042e Mon Sep 17 00:00:00 2001 From: Michael Waddell Date: Wed, 26 Jan 2022 12:04:03 -0600 Subject: [PATCH 4/5] Consolidating DEV_SELECTOR back into the existing selector --- .../nuget/file_parser/project_file_parser.rb | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb b/nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb index 92173c435f..cfade5747d 100644 --- a/nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb +++ b/nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb @@ -17,8 +17,8 @@ class ProjectFileParser DEPENDENCY_SELECTOR = "ItemGroup > PackageReference, "\ "ItemGroup > GlobalPackageReference, "\ "ItemGroup > PackageVersion, "\ - "ItemGroup > Dependency" - DEV_SELECTOR = "ItemGroup > DevelopmentDependency" + "ItemGroup > Dependency, "\ + "ItemGroup > DevelopmentDependency" PROJECT_SDK_REGEX = %r{^([^/]+)/(\d+(?:[.]\d+(?:[.]\d+)?)?(?:[+-].*)?)$}.freeze PROPERTY_REGEX = /\$\((?.*?)\)/.freeze @@ -33,25 +33,15 @@ def dependency_set(project_file:) doc = Nokogiri::XML(project_file.content) doc.remove_namespaces! - # Look for regular package references (production) + # Look for regular package references doc.css(DEPENDENCY_SELECTOR).each do |dependency_node| name = dependency_name(dependency_node, project_file) req = dependency_requirement(dependency_node, project_file) version = dependency_version(dependency_node, project_file) prop_name = req_property_name(dependency_node) + is_dev = dependency_node.name == "DevelopmentDependency" - dependency = build_dependency(name, req, version, prop_name, project_file) - dependency_set << dependency if dependency - end - - # Look for regular package references (development) - doc.css(DEV_SELECTOR).each do |dependency_node| - name = dependency_name(dependency_node, project_file) - req = dependency_requirement(dependency_node, project_file) - version = dependency_version(dependency_node, project_file) - prop_name = req_property_name(dependency_node) - - dependency = build_dependency(name, req, version, prop_name, project_file, dev: true) + dependency = build_dependency(name, req, version, prop_name, project_file, dev: is_dev) dependency_set << dependency if dependency end From b54332d95039ce0c8491cd42c3092406f287b4b5 Mon Sep 17 00:00:00 2001 From: Michael Waddell Date: Wed, 26 Jan 2022 13:06:00 -0600 Subject: [PATCH 5/5] fixing rubocop warning --- nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb b/nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb index cfade5747d..46edf754e5 100644 --- a/nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb +++ b/nuget/lib/dependabot/nuget/file_parser/project_file_parser.rb @@ -111,7 +111,6 @@ def add_sdk_refs_from_sdk_tags(doc, dependency_set, project_file) end end - # rubocop:disable Metrics/ParameterLists def build_dependency(name, req, version, prop_name, project_file, dev: false) return unless name @@ -140,7 +139,6 @@ def build_dependency(name, req, version, prop_name, project_file, dev: false) requirements: [requirement] ) end - # rubocop:enable Metrics/ParameterLists # rubocop:disable Metrics/PerceivedComplexity def dependency_name(dependency_node, project_file)