为什么来自 VSTS nuget feed 的 nuget 想要多次安装同一个包并抛出错误?

Why nuget from VSTS nuget feed wants to install the same package multiple times and throwing error?

我有一个 REST Api 在 Azure 中使用 Durable Function App 实现,它使用 netstandard2.0,我在这个解决方案中还有其他 class 库也使用 netstandard2.0 .其中之一是合同项目。

还有另一种解决方案,UAT 测试用于此解决方案。这样做的原因是 Specflow 仍然不适用于 .Net Core,它仅适用于 .Net Framework。能够测试 Api 我需要 Api 的合同。这就是我需要包括 REST Api 解决方案 Contracts 项目(这个是 netstandard2.0)的原因。此依赖项由 nuget 管理。

当我想在 Specflow 项目(使用 .Net Framework 4.7.1)中安装 Contracts 包(使用 netstandard2.0)时,出现以下错误。

我尝试了什么:

如何解决这个问题?我从 .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:\Users\username\.nuget\packages\REST.api.0.0-20180305-154726\lib\netstandard2.0\REST.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:\Users\username\.nuget\packages\REST.api.0.0-20180305-154726\lib\netstandard2.0\REST.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:\VSTS\REST.QA.Features\src\packages'

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:\Users\username\.nuget\packages\REST.api.0.0-20180305-154726\lib\netstandard2.0\REST.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\netstandard2.0\Contracts.dll" />
    <file src="..." target="lib\netstandard2.0\Contracts.dll" />
    <file src="..." target="lib\netstandard2.0\Contracts.dll" />
  </files>
</package>