Skip to content

ResolvePackageAssets fails when targeting Core 3.0 #3004

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

Closed
sa-exe opened this issue Mar 4, 2019 · 5 comments
Closed

ResolvePackageAssets fails when targeting Core 3.0 #3004

sa-exe opened this issue Mar 4, 2019 · 5 comments
Assignees
Milestone

Comments

@sa-exe
Copy link

sa-exe commented Mar 4, 2019

Error	MSB4018	The "ResolvePackageAssets" task failed unexpectedly.
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at Microsoft.NET.Build.Tasks.LockFileExtensions.CollectDependencies(IDictionary`2 libraryLookup, IEnumerable`1 dependencies, HashSet`1 exclusionList) in /_/src/Tasks/Microsoft.NET.Build.Tasks/LockFileExtensions.cs:line 193
   at Microsoft.NET.Build.Tasks.LockFileExtensions.CollectDependencies(IDictionary`2 libraryLookup, IEnumerable`1 dependencies, HashSet`1 exclusionList) in /_/src/Tasks/Microsoft.NET.Build.Tasks/LockFileExtensions.cs:line 180
   at Microsoft.NET.Build.Tasks.LockFileExtensions.GetPlatformExclusionList(LockFileTarget lockFileTarget, LockFileTargetLibrary platformLibrary, IDictionary`2 libraryLookup) in /_/src/Tasks/Microsoft.NET.Build.Tasks/LockFileExtensions.cs:line 153
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.GetPlatformPackageExclusions() in /_/src/Tasks/Microsoft.NET.Build.Tasks/ResolvePackageAssets.cs:line 1191
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter..ctor(ResolvePackageAssets task, Stream stream) in /_/src/Tasks/Microsoft.NET.Build.Tasks/ResolvePackageAssets.cs:line 610
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader.CreateReaderFromDisk(ResolvePackageAssets task, Byte[] settingsHash) in /_/src/Tasks/Microsoft.NET.Build.Tasks/ResolvePackageAssets.cs:line 483
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task) in /_/src/Tasks/Microsoft.NET.Build.Tasks/ResolvePackageAssets.cs:line 434
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups() in /_/src/Tasks/Microsoft.NET.Build.Tasks/ResolvePackageAssets.cs:line 279
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore() in /_/src/Tasks/Microsoft.NET.Build.Tasks/ResolvePackageAssets.cs:line 271
   at Microsoft.NET.Build.Tasks.TaskBase.Execute() in /_/src/Tasks/Common/TaskBase.cs:line 35
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()	NitroSharpDbg	C:\Program Files\dotnet\sdk\3.0.100-preview4-010582\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets	228	

Steps to reproduce:

  1. Create a new console netcoreapp3.0 project
  2. Clone https://github.com/mellinoe/veldrid.git
  3. Add a reference Veldrid.ImGui.csproj
<ItemGroup>
  <ProjectReference Include="..\veldrid\src\Veldrid.ImGui\Veldrid.ImGui.csproj" />
</ItemGroup>
  1. Build the project.

The build should fail. However, there's no issues when targeting netcoreapp2.2 or when using the NuGet package instead of referencing the project.

dotnet --info output:

.NET Core SDK (reflecting any global.json):
 Version:   3.0.100-preview4-010582
 Commit:    a643588b29

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17763
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.0.100-preview4-010582\

Host (useful for support):
  Version: 3.0.0-preview4-27502-7
  Commit:  12aa3da961

.NET Core SDKs installed:
  2.2.104 [C:\Program Files\dotnet\sdk]
  3.0.100-preview4-010582 [C:\Program Files\dotnet\sdk]
@livarcocc
Copy link
Contributor

@dsplaisted can you take a look?

@livarcocc livarcocc added this to the 3.0.1xx milestone Mar 4, 2019
@dsplaisted dsplaisted self-assigned this Mar 4, 2019
@dsplaisted
Copy link
Member

The issue is related to the fact that MicrosoftNETPlatformLibrary is set to Microsoft.NETCore.App, which we don't reference any more. In this repro, there is a transitive reference to version 1.0.5 of the package, and when it tries to walk those dependencies in the assets file, it can't find them listed.

The solution is probably that we shouldn't set MicrosoftNETPlatformLibrary at all when targeting .NET Core 3.0 - it's purpose was to exclude assets which were in the shared framework, but in 3.0 those assets are in targeting and runtime packs and don't flow through the assets file anyway.

@dsplaisted
Copy link
Member

I looked at the places where MicrosoftNETPlatformLibrary is used in order to see what the impact would be if we don't set it for projects targeting .NET Core 3 or higher:

  • It's used by the GenerateDepsFile, GenerateRuntimeConfigurationFiles, and ResolveCopyLocalAssets tasks. These all simply pass it to LockFileExtensions.CreateProjectContext. In that method, it's used as part of the check to determine if the app is framework dependent:
    bool isFrameworkDependent = (platformLibrary != null || runtimeFrameworks?.Any() == true) &&
        (!isSelfContained || string.IsNullOrEmpty(lockFileTarget.RuntimeIdentifier));
    Note that for .NET Core 3.0 and higher, the ResolveFrameworkReferences should add RuntimeFramework items, so the isFrameworkDependent calculation should still work.
  • In the created ProjectContext, the GetRuntimeLibraries method excludes assets from the platform library for framework dependent apps.
  • The GenerateRuntimeConfigurationFiles task also uses the platform library from the ProjectContext in order to write the runtimeconfig file, but only if there aren't any RuntimeFrameworks.
  • The ResolvePackageAssets task excludes assets from the platform library in GetPlatformPackageExclusions. (It also excludes assets from libraries matching names of RuntimeFrameworks, which I believe we should now remove, as those assets will come from runtime packs and won't be in the assets file anyway now).
  • The _RestoreCrossgen and PrepforRestoreForComposeStore use the platform library name. These are both part of support for dotnet store, which we are considering dropping, and which will need a lot of work in any case if we want it to work when targeting .NET Core 3

dsplaisted added a commit to dsplaisted/sdk that referenced this issue Mar 12, 2019
… and higher, which uses runtime and targeting packs instead

Fixes dotnet#3004
@doboczyakos
Copy link

This issue still occurs if I add package reference to https://www.nuget.org/packages/System.Diagnostics.PerformanceCounter/ from a .net standard 2.0 project which is used in a .net core 2.1 project.

@livarcocc
Copy link
Contributor

Please, file a separate issue for this with repro steps and preferably, a repro repo that we can clone and run to reproduce the problem.

dsplaisted pushed a commit to dsplaisted/sdk that referenced this issue Feb 19, 2020
* Update dependencies from https://github.com/dotnet/cli build 20190930.5

- Microsoft.DotNet.Cli.Runtime - 3.1.100-preview1.19480.5

* Update dependencies from https://github.com/dotnet/cli build 20191001.2

- Microsoft.DotNet.Cli.Runtime - 3.1.100-preview1.19501.2

* Update dependencies from https://github.com/dotnet/cli build 20191001.4

- Microsoft.DotNet.Cli.Runtime - 3.1.100-preview1.19501.4

* Update dependencies from https://github.com/dotnet/cli build 20191001.5

- Microsoft.DotNet.Cli.Runtime - 3.1.100-preview1.19501.5

* Retarget to netcoreapp3.1

* Update to 3.1 SDK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants