MSB4018 错误 - 解决包依赖关系和解决包资产任务意外失败 .net5 - Visual Studio 22
MSB4018 Error - Resolve Package Dependencies and Resolve Package Assets tasks failed unexpectedly .net5 - Visual Studio 22
我有一个 .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.0.202\Sdks\Microsoft.NET.Sdk\targets C:\Program Files\dotnet\sdk.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.0.202\Sdks\Microsoft.NET.Sdk\targets C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets
csproj 中没有重复的包。
我该如何解决这个问题?
我已经尝试过:
- 删除 bin、obj 和 .vs 文件夹
- 恢复 Nuget 包
- 清除所有 NuGet 缓存
谢谢。
我找到了解决方案。问题是另一个解决方案项目仍然引用 NuGet 包而不是本地项目。所以删除依赖并添加对本地包的引用就足够了。
我有一个 .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.0.202\Sdks\Microsoft.NET.Sdk\targets C:\Program Files\dotnet\sdk.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.0.202\Sdks\Microsoft.NET.Sdk\targets C:\Program Files\dotnet\sdk.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets
csproj 中没有重复的包。 我该如何解决这个问题? 我已经尝试过:
- 删除 bin、obj 和 .vs 文件夹
- 恢复 Nuget 包
- 清除所有 NuGet 缓存
谢谢。
我找到了解决方案。问题是另一个解决方案项目仍然引用 NuGet 包而不是本地项目。所以删除依赖并添加对本地包的引用就足够了。