Skip to content

Commit 556dde5

Browse files
authored
fix: [OSM-1797] Fixing bug that caused a failure when running snyk test in a multi-project folder (#213)
* fix: adding test fixture to provoke error * fix: getting the project path from the assets file
1 parent b262389 commit 556dde5

File tree

7 files changed

+2798
-4
lines changed

7 files changed

+2798
-4
lines changed

lib/nuget-parser/index.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,23 @@ Will attempt to build dependency graph anyway, but the operation might fail.`);
188188
const nugetFrameworksParserLocation = nugetFrameworksParser.generate();
189189
await dotnet.restore(nugetFrameworksParserLocation);
190190

191+
// Access the path of this project, to ensure we get the right .csproj file, in case of multiples present
192+
const projectPath = projectAssets.project.restore.projectPath;
193+
if (!projectPath) {
194+
console.log(
195+
`\x1b[33m⚠ WARNING\x1b[0m: Could not detect any projectPath in the project assets file, if your solution contains multiple projects in the same folder, this operation might fail.`,
196+
);
197+
}
198+
191199
// Loop through all TargetFrameworks supplied and generate a dependency graph for each.
192200
const results: DotnetCoreV2Results = [];
193201
for (const decidedTargetFramework of decidedTargetFrameworks) {
194202
// Run `dotnet publish` to create a self-contained publishable binary with included .dlls for assembly version inspection.
195-
const publishDir = await dotnet.publish(safeRoot, decidedTargetFramework);
203+
const publishDir = await dotnet.publish(
204+
// Attempt to feed it the full path to the project file itself, as multiple could exist. If that fails, don't break the flow, just send the folder as previously
205+
projectPath || safeRoot,
206+
decidedTargetFramework,
207+
);
196208

197209
// Then inspect the dependency graph for the runtimepackage's assembly versions.
198210
const filename = `${projectNameFromManifestFile}.deps.json`;

lib/nuget-parser/types.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,20 @@ export enum ManifestType {
5454
PAKET = 'paket',
5555
}
5656

57+
interface Restore {
58+
projectUniqueName: string;
59+
projectName: string;
60+
projectPath: string;
61+
packagesPath: string;
62+
outputPath: string;
63+
projectStyle: string;
64+
configFilePaths: string[];
65+
originalTargetFrameworks: string[];
66+
}
67+
5768
interface Project {
5869
version: string;
59-
restore: Record<string, any>;
70+
restore: Restore;
6071
frameworks: Record<string, any>;
6172
runtimeIdentifierGraphPath: string;
6273
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<PackageReference Include="NSubstitute" Version="4.3.0" />
9+
</ItemGroup>
10+
</Project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<PackageReference Include="NSubstitute" Version="4.3.0" />
9+
</ItemGroup>
10+
</Project>

0 commit comments

Comments
 (0)