【问题标题】:Nuget Pack Failure - The process cannot access the file 'D:\a\1\a\*.nupkg'Nuget Pack 失败 - 进程无法访问文件 'D:\a\1\a\*.nupkg'
【发布时间】:2020-11-26 21:43:58
【问题描述】:

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 文件进行上述修改,因为需要构建旧版dll,无法自行打包。但基于这个答案: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 安装程序任务,这是安装程序运行的第一个任务:

【问题讨论】:

  • 您是否针对多个框架?
  • 不,这只是一个 .netstandard2.0 库.csproj。自动生成的.nuspec 文件也有正确的依赖组targetFramework=".NETStandard2.0"。
  • 嗨@nealsu,您能否升级Nuget版本(例如5.8.0)并重试,然后在这里分享结果吗?它对我有用。
  • 我在 NuGet 5.8.0 上也看到了同样的情况。同样的 NU5128 错误。
  • 不,我没有。您可能想尝试以下一些解决方法。

标签: azure-devops nuget azure-pipelines nuget-package azure-pipelines-tasks


【解决方案1】:

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

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

我不明白为什么在 5 个小版本之后就出现了这个问题!

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2021-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多