snyk / snyk-nuget-plugin

Basic Snyk CLI plugin for .NET support.
Other
5 stars 14 forks source link

targetFrameworkSource.split is not a function #141

Closed dave0783 closed 7 months ago

dave0783 commented 1 year ago

https://github.com/snyk/snyk-nuget-plugin/blob/f433837303b7fedb769e46a12dcb81e4d362d34f/lib/nuget-parser/csproj-parser.ts#L44

When running monitor I am getting targetFrameworkSource.split is not a function.

our .csproj files looks something like:

<Project Sdk="Microsoft.NET.Sdk">
  <Import Project="..\..\build\common.props" />
  <PropertyGroup>
    <TargetFrameworks Condition=" '$([MSBuild]::IsOsPlatform(Windows))' == 'true' ">netstandard1.1;netstandard2.1;net451</TargetFrameworks>
    <TargetFrameworks Condition=" '$([MSBuild]::IsOsPlatform(Windows))' == 'false' ">netstandard1.1;netstandard2.1</TargetFrameworks>
    <DebugType>portable</DebugType>
    <LangVersion>latest</LangVersion>
  </PropertyGroup>
</Project>
dave0783 commented 1 year ago

Any updates on this?

Aandree5 commented 12 months ago

I was getting the same issue and was able to find a workaround. I had two <TargetFrameworks>...</TargetFrameworks> lines, and one of them had a condition <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net7.0-windows10.0.19041.0</TargetFrameworks>, by removing the condition it started working without any errors.

I'm not sure but the issue might be in lib/nuget-parser/csproj-parser.ts where propertyGroup?.TargetFrameworks?.[0] appears to be reading only the first value of TargetFrameworks which I would guess it's the condition (which is not a string probably).

dotkas commented 10 months ago

@dave0783 @Aandree5 could you try running this with our new beta solution? snyk monitor --all-projects --dotnet-runtime-resolution and see if this gives you better results?