github / codeql-action

Actions for running CodeQL analysis
MIT License
1.14k stars 316 forks source link

Assets file '...' doesn't have a target for '.NETFramework,Version=v8.0'. Ensure that restore has run and that you have included 'net80' in the TargetFrameworks for your projec #2341

Closed nd1012 closed 3 months ago

nd1012 commented 3 months ago

I've enables CodeQL for many repositories now, but for this one the action fails during "Analyze: csharp":

/usr/lib/mono/msbuild/Current/bin/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1005: Assets file '/home/runner/work/wan24-Crypto-BC/wan24-Crypto-BC/src/wan24-Crypto-BC/obj/project.assets.json' doesn't have a target for '.NETFramework,Version=v8.0'. Ensure that restore has run and that you have included 'net80' in the TargetFrameworks for your project. [/home/runner/work/wan24-Crypto-BC/wan24-Crypto-BC/src/wan24-Crypto-BC/wan24-Crypto-BC.csproj]

The full output can be found here: https://github.com/nd1012/wan24-Crypto-BC/actions/runs/9538548919/job/26288111824

Now, if you have a look into the file wan24-Crypto-BC.csproj, you'll clearly find the tag <TargetFramework>net8.0</TargetFramework>. It's not net80 exactly, but it works with other projects without any problem. So I'm wondering what could cause the error for this specific project?

aeisenberg commented 3 months ago

Good question. I'm not exactly sure. It looks like the src/wan24-Crypto-BC/wan24-Crypto-BC.csproj subproject built properly. I'll ask our engineering team about this.

michaelnebel commented 3 months ago

The reason the autobuilder fails is because the solution file references projects that are not located in this repository and then the autobuilder doesn't attempt to build using dotnet. If

Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wan24-Core", "..\..\wan24-Core\src\Wan24-Core\Wan24-Core.csproj", "{678B09FC-7C24-4801-AF72-1800E4C7CD38}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "wan24-Crypto", "..\..\wan24-Crypto\src\wan24-Crypto\wan24-Crypto.csproj", "{C77DD1B2-571E-4BA2-94E7-7F9073F084B9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "wan24-Compression", "..\..\wan24-Compression\src\wan24-Compression\wan24-Compression.csproj", "{D1EFBD7D-2321-403D-AE88-586E4BB6D455}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ObjectValidation", "..\..\ObjectValidation\src\ObjectValidation\ObjectValidation.csproj", "{2490B026-D9E6-4A5D-830D-CDA9F85A984C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stream-Serializer-Extensions", "..\..\Stream-Serializer-Extensions\src\Stream-Serializer-Extensions\Stream-Serializer-Extensions.csproj", "{21705885-E17E-4265-9CE7-C00AB7FB63B0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MappingObject", "..\..\Mapping-Object\src\MappingObject\MappingObject.csproj", "{2668557E-CAD7-44CA-921A-A5A6329906D4}"
EndProject

is deleted from the solution file the autobuilder succeeds.

nd1012 commented 3 months ago

I guess you're right, the error message I tried to follow was a bit misleading. When I switch the CodeQL setup to "advanced" and create a codeql.yml file with a manual build command, the process does complete with success.

The solution contains projects which are not part of the repository, but used when doing a build with the "Trunk" build configuration, which I use for testing changes to code of referenced NuGet libraries before an updated NuGet package is available. So removing those projects isn't an option for my setup. But the manual build commands in the codeql.yml file ignores missing sources, which seems to be still fine for for CodeQL process.