Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On dotnet publish for Mac, getting unclear error "error MSB4018: The "GenerateDepsFile" task failed unexpectedly... System.InvalidOperationException: Unrecognized AssetType 'resource' " #40015

Closed
idigra opened this issue Apr 4, 2024 · 6 comments · Fixed by #44612
Assignees
Labels
Area-NetSDK needs team triage Requires a full team discussion

Comments

@idigra
Copy link

idigra commented Apr 4, 2024

Describe the bug

When trying to dotnet publish a project with dependencies, I'm getting the MSBuild exception below.
Based on looking at dotnet code, I guess that the error is probably due to some typo in the package creation, where instead of resources, the word resource was used (I understood it by the code around the exception thrown here:
https://github.com/dotnet/sdk/blob/a1fdd359f85eaa8a7ebb68b4856b0dc559543a93/src/Tasks/Microsoft.NET.Build.Tasks/ResolvedFile.cs#L75C17-L76C1)

However I can't I understand from the exception and the code around where should I look for that typo in our code or even in the binary or package metadata.

Short term - please advice what exactly should I look at.
Long term - consider providing clearer error message.

To Reproduce

Dependency tree is complex and due to the unclear error message I don't know how to minimize the code into simple repro, sorry.
On private call I'll be able to provide the faulty package and to share the environment where I reproduced the bug.

Exceptions (if any)

(Obfuscated some private paths from the logs below)

/usr/local/share/dotnet/sdk/8.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018: The "GenerateDepsFile" task failed unexpectedly. [MyProject.csproj::TargetFramework=net8.0]
/usr/local/share/dotnet/sdk/8.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018: System.InvalidOperationException: Unrecognized AssetType 'resource' for /Volumes/.../%NugetMachineInstallRoot%/.pkgref/PackageName/2.127.7249-prerelease-007/runtimes/osx/lib/net6.0/ar/BinaryName.resources.dll [MyProject.csproj::TargetFramework=net8.0]
/usr/local/share/dotnet/sdk/8.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvedFile..ctor(ITaskItem item, Boolean isRuntimeTarget) [MyProject.csproj::TargetFramework=net8.0]
/usr/local/share/dotnet/sdk/8.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018:    at Microsoft.NET.Build.Tasks.GenerateDepsFile.<>c.<WriteDepsFile>b__120_3(ITaskItem f) [MyProject.csproj::TargetFramework=net8.0]
/usr/local/share/dotnet/sdk/8.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018:    at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext() [MyProject.csproj::TargetFramework=net8.0]
/usr/local/share/dotnet/sdk/8.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018:    at System.Linq.Enumerable.ConcatIterator`1.MoveNext() [MyProject.csproj::TargetFramework=net8.0]
/usr/local/share/dotnet/sdk/8.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018:    at System.Linq.Lookup`2.Create(IEnumerable`1 source, Func`2 keySelector, IEqualityComparer`1 comparer) [MyProject.csproj::TargetFramework=net8.0]
/usr/local/share/dotnet/sdk/8.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018:    at System.Linq.GroupedEnumerable`2.GetEnumerator() [MyProject.csproj::TargetFramework=net8.0]
/usr/local/share/dotnet/sdk/8.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018:    at Microsoft.NET.Build.Tasks.DependencyContextBuilder.WithResolvedNuGetFiles(IEnumerable`1 resolvedNuGetFiles) [MyProject.csproj::TargetFramework=net8.0]
/usr/local/share/dotnet/sdk/8.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018:    at Microsoft.NET.Build.Tasks.GenerateDepsFile.WriteDepsFile(String depsFilePath) [MyProject.csproj::TargetFramework=net8.0]
/usr/local/share/dotnet/sdk/8.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute() [MyProject.csproj::TargetFramework=net8.0]
/usr/local/share/dotnet/sdk/8.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [MyProject.csproj::TargetFramework=net8.0]
/usr/local/share/dotnet/sdk/8.0.202/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [MyProject.csproj::TargetFramework=net8.0]

Further technical details

- Include the output of `dotnet --info`
.NET SDK:
 Version:           8.0.202
 Commit:            25674bb2f4
 Workload version:  8.0.200-manifests.4e94be9c

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  14.4
 OS Platform: Darwin
 RID:         osx-arm64
 Base Path:   /usr/local/share/dotnet/sdk/8.0.202/

.NET workloads installed:
There are no installed workloads to display.

Host:
  Version:      8.0.3
  Architecture: arm64
  Commit:       9f4b1f5d66

.NET SDKs installed:
  6.0.420 [/usr/local/share/dotnet/sdk]
  7.0.407 [/usr/local/share/dotnet/sdk]
  8.0.202 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.28 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.17 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.28 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.17 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  x64   [/usr/local/share/dotnet/x64]
    registered at [/etc/dotnet/install_location_x64]

Environment variables:
  Not set

global.json file:
  /Volumes/.../global.json

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version
    No IDE, running the following line from command line:
    dotnet publish --interactive -c Debug-Mac -f net8.0 <project-path>
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-NetSDK untriaged Request triage from a team member labels Apr 4, 2024
@idigra
Copy link
Author

idigra commented Apr 8, 2024

After some deep look and discussions with developers in my team, turns out that we did some non standard stuff in the consumed package. I'm leaving this bug opened just in case you find it interesting for any other reasons, feel free to close if not.

@nagilson nagilson added needs team triage Requires a full team discussion and removed untriaged Request triage from a team member labels Jun 4, 2024
@marcpopMSFT
Copy link
Member

Triage: We'll close for now and we if we get more feedback around improving the error experience for malformed packages, we can take a look in the future.

@marcpopMSFT marcpopMSFT closed this as not planned Won't fix, can't repro, duplicate, stale Jun 4, 2024
@dsplaisted
Copy link
Member

@nkolev92 It looks like here an invalid asset type (resource instead of resources) is flowing from the NuGet package into the assets file. Should NuGet be failing or ignoring this instead of passing it through? Or are both values supposed to be supported?

@nkolev92
Copy link
Contributor

I see the 3 types being added as runtime, resource and native.

https://github.com/NuGet/NuGet.Client/blob/20f05435be385abfe74737b6433dc80fd3b3b504/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/LockFileUtils.cs#L374-L399

The SDK seems to have been using resources, since the beginning:

.

I'm guessing resources is the correct though right?

The "safe" approach might be for the SDK to support both, but given that NuGet and SDK seems to have been looking at a different thing at least 3 years back, not sure there's a big risk if NuGet changed.

This is all the product of a short investigation, so I could be missing something.

@YehezkelShB
Copy link
Contributor

I created a PR with the "safer" fix, that won't add any backward compatibility issues. I'd appreciate your feedback on it.
#44612

If it is accepted, we'd like it to be backported to 8.* (preferably 8.0.401), and naturally also 9.*

@marcpopMSFT @nagilson @nkolev92 @idigra

YehezkelShB added a commit to YehezkelShB/dotnet-sdk that referenced this issue Nov 4, 2024
@YehezkelShB
Copy link
Contributor

For completeness:
It seems that switching from RuntimeIdentifiers definition in the project to using separated RuntimeIdentifier definitions, avoids this issue. From investigating NuGet code linked above it seems like adding RID to the files in the project creating the package would also avoid this code path and thus they don't get the non-standard assetType in the generated project.assets.json file, which might be a different way to avoid it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-NetSDK needs team triage Requires a full team discussion
Projects
None yet
6 participants