我正在尝试在包含一个DevOps的.NET框架4.7.2解决方案的基础上设置一个Azure Visual Studio安装程序项目构建管道。我已经在WindowsServer2019VM上设置了一个自托管代理,该服务器安装了VisualStudio2019社区。构建管道包含NuGet安装程序任务,然后是NuGet任务,设置为恢复引用的NuGet包。下面是YAML片段:
- task: NuGetCommand@2
inputs:
command: 'restore'
restoreSolution: '$(solution)'但是,使用此配置运行生成会导致生成日志中出现以下错误:
errorThe nuget命令失败,退出代码(1)和错误(C:##############.vdproj(1,1):error MSB4025:无法加载项目文件)。根级的数据无效。第1行,位置1.)
这似乎是由于在较新版本的nuget.exe中提高了性能。基于这 GitHub问题的建议是启用使用RestoreUseSkipNonexistentTargets MSBuild设置跳过不存在的包目标。
GitHub问题提到使用NUGET_RESTORE_MSBUILD_ARGS NuGet CLI环境变量来设置该属性,但我不知道如何通过NuGet构建任务来实现这一点。
由于NuGet现在与MSBuild集成,所以我尝试通过NuGet任务的命令行参数将该属性设置为false。我修改了YAML,将命令设置为custom,以便传递参数。我基于MSBuild还原文档的语法。现在的情况如下:
- task: NuGetCommand@2
inputs:
command: 'custom'
arguments: 'restore "$(solution)" -p:RestoreUseSkipNonexistentTargets=false'此生成配置导致以下错误:
退出代码(1)和错误(未知选项:'-p:RestoreUseSkipNonexistentTargets=false') ) errorThe nuget命令失败
我的问题是,如何让NuGet还原任务跳过.vdproj项目的包恢复?
编辑
解决方案中的另一个项目是C# WinForms .NET Framework项目。我们使用的是packages.config而不是PackageReference。
发布于 2019-12-20 15:33:27
至于你的原版: MSB4025
正如您前面提到的,这是一个悬而未决的这里。任何对此感兴趣的人都可以在那里追踪这个问题。
errorThe nuget命令失败,退出代码(1)和错误(未知选项:'-p:RestoreUseSkipNonexistentTargets=false')
nuget还原命令不会识别msbuild属性。请参阅类似的问题和更多细节这里。
自The other project in the solution is a C# WinForms .NET Framework project. We're using packages.config rather than PackageReference.以来
解决此问题的方法是使用nuget自定义命令,如下所示:
- task: NuGetCommand@2
inputs:
command: 'custom'
arguments: 'restore YourProjectName\packages.config -PackagesDirectory $(Build.SourcesDirectory)\packages'这可以跳过安装程序项目的还原步骤。
发布于 2020-05-14 19:43:59
通常,您不再需要显式地调用nuget restore。MSBuild会自动将其作为构建的一部分来完成(因此您可能会执行两次)。可以将p:RestoreUseSkipNonexistentTargets=false属性添加到VSBuild任务或DotNet生成或发布任务的VSBuild参数中:
- task: DotNetCoreCLI@2
displayName: Build/Publish
inputs:
command: 'publish'
publishWebProjects: false
projects: '$(solution)'
arguments: '-r $(runtimeIdentifier) /p:RestoreUseSkipNonexistentTargets=false'
zipAfterPublish: false
modifyOutputPath: false发布于 2022-06-12 14:53:15
我发现的最佳方法:在vs2022托管映像上测试的管道上使用3个任务
所有任务都使用VisualStudio2022开发人员PowerShell。
任务1-忽略不支持的vdproj任务2的错误恢复nuget -使用msbuild构建解决方案将不会构建vdproj任务3-只使用DevEnv构建vdproj。
- task: PowerShell@2
displayName: "restore nuget"
inputs:
targetType: 'inline'
script: |
& 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\Launch-VsDevShell.ps1'
msbuild -t:restore .\<solution>.sln -p:RestoreUseSkipNonexistentTargets=false
ignoreLASTEXITCODE: true
pwsh: true
- task: PowerShell@2
displayName: "build solution"
inputs:
targetType: 'inline'
script: |
& 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\Launch-VsDevShell.ps1'
msbuild .\<solution>.sln
pwsh: true
- task: PowerShell@2
displayName: "create install "
inputs:
targetType: 'inline'
script: |
& 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\Launch-VsDevShell.ps1'
devenv ".\<project>.vdproj" /Build
pwsh: truehttps://stackoverflow.com/questions/59419416
复制相似问题