0

Azure Pipeline for NuGet Pack 任务使用 SDK 格式时出错,.csproj该格式会自动生成.nuspec文件:

The process cannot access the file 'D:\a\1\a\*.nupkg' because it is being used by another process.

System.IO.IOException: The process cannot access the file 'D:\a\1\a\*.nupkg' because it is being used by another process.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.InternalDelete(String path, Boolean checkHost)
   at NuGet.Commands.PackCommandRunner.BuildPackage(PackageBuilder builder, String outputPath, Boolean symbolsPackage)
   at NuGet.Commands.PackCommandRunner.BuildFromProjectFile(String path)
   at NuGet.CommandLine.PackCommand.ExecuteCommand()
   at NuGet.CommandLine.Command.ExecuteCommandAsync()
   at NuGet.CommandLine.Command.Execute()
   at NuGet.CommandLine.Program.MainCore(String workingDirectory, String[] args))
##[error]An error occurred while trying to pack the files.

.csproj正在构建的文件使用TargetsForTfmSpecificBuildOutput

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <Description>Provides a .....</Description>
  </PropertyGroup>


<PropertyGroup>
    <TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
  </PropertyGroup>
  <Target Name="CopyProjectReferencesToPackage" DependsOnTargets="BuildOnlySettings;ResolveReferences">
    <ItemGroup>
      <!-- Filter out unnecessary files -->
      <_ReferenceCopyLocalPaths Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference')->WithMetadataValue('PrivateAssets', 'All'))" />
    </ItemGroup>
    <!-- Print batches for debug purposes -->
    <Message Text="Batch for .nupkg: ReferenceCopyLocalPaths = @(_ReferenceCopyLocalPaths), ReferenceCopyLocalPaths.DestinationSubDirectory = %(_ReferenceCopyLocalPaths.DestinationSubDirectory) Filename = %(_ReferenceCopyLocalPaths.Filename) Extension = %(_ReferenceCopyLocalPaths.Extension)" Importance="High" Condition="'@(_ReferenceCopyLocalPaths)' != ''" />
    <ItemGroup>
      <!-- Add file to package with consideration of sub folder. If empty, the root folder is chosen. -->
      <BuildOutputInPackage Include="@(_ReferenceCopyLocalPaths)" TargetPath="%(_ReferenceCopyLocalPaths.DestinationSubDirectory)" />
    </ItemGroup>
  </Target>

.csproj由于需要构建 legacydll不能自行打包,因此需要对文件进行上述修改。但基于这个答案:https ://stackoverflow.com/a/59893520/1231374

注意:删除自定义包步骤仍然会导致错误。

在此之前还有一个额外的错误,不确定这是否相关。

Error NU5128: Some target frameworks declared in the dependencies group of the nuspec and the lib/ref folder do not have exact matches in the other location. Consult the list of actions below: 
- Add a dependency group for .NETStandard2.0 to the nuspec 

请参阅下面的任务配置:

在此处输入图像描述

请参阅 Nuget 安装程序任务,这是安装程序运行的第一个任务:

Nuget 安装程序任务 - 5.8.x

4

2 回答 2

1

我终于找到了这个问题的“原因”。我不能在我这边使用 dotnet cli,因为我的项目不兼容,但我找到了解决方法。

它似乎与https://github.com/NuGet/Home/issues/8713有关,所以我使用“Nuget Tool Installer”强制版本“5.2.x”,它按预期工作。

我不明白为什么自 5 个次要版本以来就存在此问题!

于 2020-12-16T14:36:23.643 回答
0

我的问题的解决方案是使用dotnet pack(因为我正在使用 .NetStandard 和 .NetCore 项目)而不是nuget pack.

dotnet 包任务

特别是启用不构建选项。作为上一步,在其中构建解决方案和项目。

于 2020-12-14T22:57:43.040 回答