.net MSB 4018错误-解析包依赖项和解析包资产任务意外失败,net 5- Visual Studio 22

wfveoks0  于 2023-02-10  发布在  .NET
关注(0)|答案(2)|浏览(345)

我有一个.net5项目,我需要调试此项目使用的库。为此,我已卸载了库的NuGet包,并将项目引用添加到项目中。现在,我无法生成该项目。生成后,我收到以下错误:

The "ResolvePackageDependencies" task failed unexpectedly.
System.ArgumentException: An item with the same key has already been added.
   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.GetPackageAndFileDependencies(LockFileTarget target)
   at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.RaiseLockFileTargets()
   at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.ExecuteCore()
   at Microsoft.NET.Build.Tasks.TaskBase.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() Project.Namespace C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets    C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets

还有

The "ResolvePackageAssets" task failed unexpectedly
System.ArgumentException: An item with the same key has already been added.
   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at Microsoft.NET.Build.Tasks.ProjectContext.GetTopLevelDependencies(LockFile lockFile, LockFileTarget lockFileTarget)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter.ComputePackageExclusions()
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter..ctor(ResolvePackageAssets task)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader.CreateReaderFromDisk(ResolvePackageAssets task, Byte[] settingsHash)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task)
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups()
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore()
   at Microsoft.NET.Build.Tasks.TaskBase.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() Project.Namespace   C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets  C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets

csproj中没有重复的包。如何解决这个问题?我已经尝试过:

  • 删除bin、obj和. vs文件夹
  • 还原Nuget软件包
  • 清除所有NuGet缓存

谢谢。

jgwigjjp

jgwigjjp1#

我找到了解决方案。问题是另一个Solution项目仍然引用NuGet包而不是本地项目。因此,删除依赖项并添加对本地包的引用就足够了。

vh0rcniy

vh0rcniy2#

我的问题是Nuget套餐不存在。

<PackageReference Include="System.Collections.Immutable" Version="1.2.5.0" />

溶液

<PackageReference Include="System.Collections.Immutable" Version="7.0.0" />

相关问题