Azure DevOps YAML流水线打包NuGet遇NU5012错误:路径异常修复
修复Azure DevOps NuGet Pack路径错误问题
问题根源
- 缺少前置构建任务:NuGet Pack依赖已编译生成的DLL,当前流水线未先执行项目构建,导致NuGet无法定位正确的输出文件。
buildProperties参数干扰路径生成:手动指定该参数后,NuGet错误将Configuration=$(buildConfiguration)解析为目录名Configuration=Debug,而非使用项目默认的Debug目录结构。packagesToPack通配符匹配偏差:正确路径为.framework,但配置中写的*.framework可能导致路径匹配错误。
修复步骤
1. 添加前置项目构建任务
先通过VSBuild编译项目,确保DLL生成到bin\x86\Debug的标准路径:
- task: VSBuild@1 displayName: '编译Visual Basic项目' inputs: solution: '.framework/Software/ServerComponents/*.Framework.VisualBasic/*.Framework.VisualBasic.vbproj' platform: '$(buildPlatform)' configuration: '$(buildConfiguration)'
2. 修正NuGet Pack任务配置
移除干扰路径的buildProperties参数,同时修正packagesToPack的通配符:
- task: NuGetCommand@2 displayName: 'NuGet Pack' inputs: command: 'pack' # 修正通配符为实际目录名.framework packagesToPack: '.framework/Software/ServerComponents/*.Framework.VisualBasic/*.Framework.VisualBasic.vbproj' versioningScheme: 'byEnvVar' versionEnvVar: 'BUILD_BUILDNUMBER' outputDir: '$(Build.ArtifactStagingDirectory)'
3. 验证项目输出路径(可选)
打开.vbproj文件,确认输出路径配置为标准格式:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> <OutputPath>bin\x86\Debug\</OutputPath> </PropertyGroup>
说明
- 先执行VSBuild构建,能确保DLL生成符合项目配置的路径,NuGet Pack时会自动识别该路径,无需手动指定
buildProperties。 - 移除
buildProperties后,可避免NuGet生成Configuration=Debug这类异常目录结构。
内容的提问来源于stack exchange,提问作者sreenadh




