Skip to content

Commit e398d14

Browse files
fix: false positives from transitive deps (#233)
1 parent 71556ce commit e398d14

File tree

7 files changed

+840
-3
lines changed

7 files changed

+840
-3
lines changed

lib/nuget-parser/parsers/dotnet-core-v2-parser.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function getRestoredProjectName(
110110
);
111111
}
112112

113-
export function extractLocalProjects(libs: Record<string, any>): string[] {
113+
function extractLocalProjects(libs: Record<string, any>): string[] {
114114
const localPackages: string[] = [];
115115

116116
for (const [key, value] of Object.entries(libs)) {
@@ -126,6 +126,10 @@ export function extractLocalProjects(libs: Record<string, any>): string[] {
126126
return localPackages;
127127
}
128128

129+
function getDllName(depName: string): string {
130+
return `${depName}.dll`;
131+
}
132+
129133
function buildGraph(
130134
projectName: string,
131135
projectAssets: ProjectAssets,
@@ -201,20 +205,33 @@ function buildGraph(
201205
publishedProjectDeps.libraries,
202206
);
203207

204-
// Overwriting the runtime versions with the versions declared in the manifest files.
205208
const targets = publishedProjectDeps.targets[runtimeTarget];
209+
210+
// Overwriting the runtime versions with the values used in local projects.
206211
for (const pgkName of localPackagesNames) {
207212
if (targets[pgkName]?.dependencies) {
208213
for (const [key, value] of Object.entries(
209214
targets[pgkName].dependencies,
210215
)) {
211-
const dllName = `${key}.dll`;
216+
const dllName = getDllName(key);
212217
if (runtimeAssembly[dllName]) {
213218
runtimeAssembly[dllName] = value as string;
214219
}
215220
}
216221
}
217222
}
223+
224+
// Overwriting the runtime versions with the values used in fetched packages.
225+
for (const [key, value] of Object.entries(targets)) {
226+
if (value && Object.keys(value).length === 0) {
227+
const [depName, depVersion] = key.split('/');
228+
const dllName = getDllName(depName);
229+
// NuGet’s dependency resolution mechanism will choose the higher available version.
230+
if (runtimeAssembly[dllName] && depVersion > runtimeAssembly[dllName]) {
231+
runtimeAssembly[dllName] = depVersion as string;
232+
}
233+
}
234+
}
218235
}
219236

220237
recursivelyPopulateNodes(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net8.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Aspire.RabbitMQ.Client" Version="8.2.2" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference
13+
Include="..\SecondProject\dotnet_8_second_project.csproj"
14+
/>
15+
</ItemGroup>
16+
</Project>

0 commit comments

Comments
 (0)