Azure Pipelines中dotnet push路径斜杠兼容问题咨询
解决Azure Pipelines中dotnet nuget Push路径匹配问题
核心问题分析
报错本质源于两个关键点:
- 文件名大小写不匹配:打包生成的文件是
Ayush.search.0.0.4.nupkg,但Push时使用的通配符是Ayush.Search.*.nupkg,大小写差异导致通配符无法命中目标文件 - Windows系统下的斜杠兼容性是次要问题,正斜杠本身可被dotnet命令识别,核心矛盾还是大小写不匹配
解决方案
1. 强制统一NuGet包ID的大小写
在项目的.csproj文件中明确指定PackageId的大小写,确保打包生成的文件名与Push时的通配符完全一致:
<PropertyGroup> <PackageId>Ayush.Search</PackageId> <!-- 保留其他原有配置 --> </PropertyGroup>
修改后,dotnet pack生成的包文件名会固定为Ayush.Search.0.0.4.nupkg,从根源上解决通配符匹配问题。
2. 直接使用正斜杠路径的标准写法
只要包文件名大小写匹配,Windows代理上的dotnet命令完全支持正斜杠路径,直接在YAML中使用标准写法即可:
steps: - task: DotNetCoreCLI@2 displayName: 'dotnet pack' inputs: command: 'pack' packagesToPack: '**/*.csproj' versioningScheme: 'byBuildNumber' outputDir: '$(Build.StagingDirectory)' - task: DotNetCoreCLI@2 displayName: 'dotnet nuget push' inputs: command: 'push' packagesToPush: '$(Build.StagingDirectory)/Ayush.Search.*.nupkg' nuGetFeedType: 'internal' publishVstsFeed: '你的内部Feed名称'
3. 可选:用PowerShell生成标准正斜杠路径
如果需要确保路径格式完全统一为正斜杠,可在Push步骤前添加PowerShell任务预处理路径变量:
- powershell: | $standardPath = $env:BUILD_STAGINGDIRECTORY.Replace('\', '/') Write-Host "##vso[task.setvariable variable=StandardStagingDir]$standardPath" displayName: '生成正斜杠格式的 staging 路径' - task: DotNetCoreCLI@2 displayName: 'dotnet nuget push' inputs: command: 'push' packagesToPush: '$(StandardStagingDir)/Ayush.Search.*.nupkg' nuGetFeedType: 'internal' publishVstsFeed: '你的内部Feed名称'
内容的提问来源于stack exchange,提问作者Ayush Singh
相关产品推荐
相关产品推荐

