为什么来自VSTS nuget feed的nuget想要多次安装相同的包并抛出错误?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为什么来自VSTS nuget feed的nuget想要多次安装相同的包并抛出错误?相关的知识,希望对你有一定的参考价值。
我在Azure中使用Durable Function App实现了REST Api,它使用了netstandard2.0
,我在此解决方案中也使用了netstandard2.0
。其中之一是合同项目。
还有另一种解决方案,UAT测试为此解决方案。原因是,Specflow仍然不适用于.Net Core
,它仅适用于.Net Framework
。能够测试Api我需要Api的合同。这就是我需要包含REST Api解决方案合同项目(这个是netstandard2.0
)的原因。这种依赖关系由nuget管理。
当我想在Specflow项目(使用netstandard2.0
)中安装Contracts包(使用.Net Framework 4.7.1
)时,我得到以下错误。
我尝试了什么:
- 我重新启动Visual Studio几次,因为我经历过,当.Net Core或.Net Standard项目正在使用时,它有时会变得疯狂。重启没有帮助。
- 我从JetBrains Rider打开了这个项目,但它没有在存储库中看到
netstandard2.0
nuget包。我认为这是因为该项目使用.Net Framework 4.7.1
而不是Net Standard 2.0 - 我看到了错误
Cannot create "C:...REST.Api.dll" because a file or directory with the same name already exists.
。所以,我删除了解决方案包目录下的所有包。我还在Visual Studio中删除了缓存。但是,下次我启动Visual Studio并尝试安装包时,再次出现相同的错误。 - 我还尝试在我的机器上使用控制台安装软件包(nuget.exe install ...)。错误是一样的。
如何解决这个问题?我从.Net Framework 4.6
及以上读过,.Net Core
可以参考.Net Standard
库。
Attempting to gather dependency information for package 'REST.Api.1.0.0-20180305-154726' with respect to project 'MasterData.Features.HttpClient', targeting '.NETFramework,Version=v4.7.1'
Gathering dependency information took 861.8 ms
Attempting to resolve dependencies for package 'REST.Api.1.0.0-20180305-154726' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'REST.Api.1.0.0-20180305-154726'
Resolved actions to install package 'REST.Api.1.0.0-20180305-154726'
GET https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg
Retrieving package 'REST.Api 1.0.0-20180305-154726' from 'Sayusi Ando's Digital Library Packages'.
OK https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg 2343ms
Installing REST.Api 1.0.0-20180305-154726.
Error downloading 'REST.Api.1.0.0-20180305-154726' from 'https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg'.
Cannot create "C:Usersusername.nugetpackagesREST.api1.0.0-20180305-154726lib
etstandard2.0REST.Api.dll" because a file or directory with the same name already exists.
GET https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg
OK https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg 462ms
Installing REST.Api 1.0.0-20180305-154726.
Error downloading 'REST.Api.1.0.0-20180305-154726' from 'https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg'.
Cannot create "C:Usersusername.nugetpackagesREST.api1.0.0-20180305-154726lib
etstandard2.0REST.Api.dll" because a file or directory with the same name already exists.
GET https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg
OK https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg 464ms
Installing REST.Api 1.0.0-20180305-154726.
Install failed. Rolling back...
Package 'REST.Api.1.0.0-20180305-154726' does not exist in project 'MasterData.Features.HttpClient'
Package 'REST.Api.1.0.0-20180305-154726' does not exist in folder 'C:VSTSREST.QA.Featuressrcpackages'
Executing nuget actions took 3.51 sec
Error downloading 'REST.Api.1.0.0-20180305-154726' from 'https://xyzrepository.visualstudio.com/_packaging/689a2aa0-1e6a-4f39-8389-250b4ad44db8/nuget/v3/flat2/REST.api/1.0.0-20180305-154726/REST.api.1.0.0-20180305-154726.nupkg'.
Cannot create "C:Usersusername.nugetpackagesREST.api1.0.0-20180305-154726lib
etstandard2.0REST.Api.dll" because a file or directory with the same name already exists.
Time Elapsed: 00:00:05.5462783
答案
问题的根源是目标属性与另一个文件名冲突。 (名字缩短)
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<!-- package stuff -->
<dependencies>
<group targetFramework=".NETStandard2.0" />
</dependencies>
</metadata>
<files>
<file src="..." target="lib
etstandard2.0Contracts.dll" />
<file src="..." target="lib
etstandard2.0Contracts.dll" />
<file src="..." target="lib
etstandard2.0Contracts.dll" />
</files>
</package>
以上是关于为什么来自VSTS nuget feed的nuget想要多次安装相同的包并抛出错误?的主要内容,如果未能解决你的问题,请参考以下文章
Nuget 包 - 提要 (VSTS):尝试添加源时抛出异常“System.AggregateException”