【发布时间】: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