我们正在从 NetFramework 项目切换到具有多个 TargetFrameworks 的 NetCore 项目。如果 TargetFramework 包含为 net40 或 net35 编写的代码,则这需要 Directory.Build.Props 文件。Directory.Build.Props 中引用的 NuGet 包来自 NuGet.org。
由于 NuGetCommand 是为 NetFramework 构建的,我们正尝试在 yaml 管道中从使用 NuGetCommand 切换到 DotNetCoreCLI。但是,DotNetCoreCLI 'restore' 似乎没有在 Directory.Build.props 中包含 NuGet 包。恢复任务有效,但构建任务失败并出现以下错误:
Determining projects to restore...
Failed to download package 'Microsoft.NETFramework.ReferenceAssemblies.net20.1.0.0' from 'https://pkgs.dev.azure.com/organizationName/34aabd4f-e198-4449-8f63-4bc7afc96f97/_packaging/a5bd5a70-fb61-4e6a-b586-6828474df9df/nuget/v3/flat2/microsoft.netframework.referenceassemblies.net20/1.0.0/microsoft.netframework.referenceassemblies.net20.1.0.0.nupkg'.
Response status code does not indicate success: 401 (Unauthorized).
Failed to download package 'Microsoft.NETFramework.ReferenceAssemblies.net40.1.0.0' from 'https://pkgs.dev.azure.com/organizationName/34aabd4f-e198-4449-8f63-4bc7afc96f97/_packaging/a5bd5a70-fb61-4e6a-b586-6828474df9df/nuget/v3/flat2/microsoft.netframework.referenceassemblies.net40/1.0.0/microsoft.netframework.referenceassemblies.net40.1.0.0.nupkg'.
Response status code does not indicate success: 401 (Unauthorized).
Failed to download package 'Microsoft.NETFramework.ReferenceAssemblies.net40.1.0.0' from 'https://pkgs.dev.azure.com/organizationName/34aabd4f-e198-4449-8f63-4bc7afc96f97/_packaging/a5bd5a70-fb61-4e6a-b586-6828474df9df/nuget/v3/flat2/microsoft.netframework.referenceassemblies.net40/1.0.0/microsoft.netframework.referenceassemblies.net40.1.0.0.nupkg'.
Response status code does not indicate success: 401 (Unauthorized).
Failed to download package 'Microsoft.NETFramework.ReferenceAssemblies.net20.1.0.0' from 'https://pkgs.dev.azure.com/organizationName/34aabd4f-e198-4449-8f63-4bc7afc96f97/_packaging/a5bd5a70-fb61-4e6a-b586-6828474df9df/nuget/v3/flat2/microsoft.netframework.referenceassemblies.net20/1.0.0/microsoft.netframework.referenceassemblies.net20.1.0.0.nupkg'.
Response status code does not indicate success: 401 (Unauthorized).
##[error]C:\Program Files\dotnet\sdk\5.0.202\NuGet.targets(131,5): Error : Failed to download package 'Microsoft.NETFramework.ReferenceAssemblies.net40.1.0.0' from 'https://pkgs.dev.azure.com/organizationName/34aabd4f-e198-4449-8f63-4bc7afc96f97/_packaging/a5bd5a70-fb61-4e6a-b586-6828474df9df/nuget/v3/flat2/microsoft.netframework.referenceassemblies.net40/1.0.0/microsoft.netframework.referenceassemblies.net40.1.0.0.nupkg'.
Response status code does not indicate success: 401 (Unauthorized).
NuGet 命令:
- task: NuGetCommand@2
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'config'
nugetConfigPath: 'NuGet.config'
DotNetCoreCLI
- task: DotNetCoreCLI@2
displayName: DotNetCoreCLI NuGet restore
inputs:
command: 'restore'
projects: '**/*.csproj'
feedsToUse: 'config'
nugetConfigPath: 'NuGet.config'
NuGet.Config 包括以下内容
<packageSources>
...
<add key="nuget.org" value="https://api.nuget.org/v3/index.json"/>
</packageSources>
目录.Build.props
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="all" />
<PackageReference Include="jnm2.ReferenceAssemblies.net35" Version="1.0.1" PrivateAssets="all" />
</ItemGroup>
</Project>