You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Pipelines自托管代理误用旧版MSBuild,如何强制使用v17.0?

Azure自托管构建代理强制使用MSBuild v17.0的问题

我在使用Azure自托管构建代理构建解决方案时,已在流水线的MSBuild任务及构建参数中明确指定要使用MSBuild v17.0,但实际执行构建时却调用了旧版本MSBuild(v12.0),且无法定位原因。

通过诊断模式日志已确认确实在运行v12.0:

39>GenerateTargetFrameworkMonikerAttribute:
   Skipping target "GenerateTargetFrameworkMonikerAttribute" because all 
   output files are up-to-date with respect to the input files.
   CoreCompile:
     C:\Program Files (x86)\MSBuild\12.0\bin\Csc.exe 
     /noconfig /nowarn:1701,1702 
     /nostdlib+ /platform:x86 
     /errorreport:prompt /warn:4 
     /highentropyva+ 
     /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\mscorlib.dll" 
     /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.Configuration.dll" 
     /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.Core.dll" 
     /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.dll" 
     /reference:C:\Users\<user>\Files\BuildAgents\ProdAgent1\_work\12\s\src\packages\Thinktecture.IdentityModel.Owin.ResourceAuthorization.1.1.0\lib\net45\Thinktecture.IdentityModel.Owin.ResourceAuthorization.dll 
     /debug:pdbonly /filealign:512 
     /optimize+ /out:obj\Release\Common.Security.dll 
     /subsystemversion:6.00 
     /target:library 
     /utf8output Authorization\CoreAuthorizationManager.cs 
                 Configuration\FrameworkMode.cs 
                 Configuration\IdentityConstants.cs                      
                 Configuration\LoggingConfig.cs                      
                 Configuration\SecurityConfig.cs                      
                 Configuration\Settings\ConfigFileLoggingSettingsProvider.cs                      
                 Configuration\Settings\ConfigFileSecuritySettingsProvider.cs                      
                 Configuration\Settings\ILoggingSettingsProvider.cs                      
                 Configuration\Settings\ISecuritySettingsProvider.cs                      
                 Configuration\Settings\LoggingSettings.cs                      
                 Configuration\Settings\SecuritySettings.cs                      
                 Configuration\Settings\SettingsHelper.cs                      
                 Configuration\TokenClientConfig.cs                      
                 Configuration\WebClientConfig.cs                      
                 Diagnostics\ILogger.cs                      
                 Diagnostics\Logger.cs                      
                 Diagnostics\LogHelper.cs                      
                 Diagnostics\LogHelper.Exceptions.cs                      
                 Extensions\ClaimsExtensions.cs                      
                 Extensions\ResourceAuthorizationContextExtensions.cs                      
                 Properties\AssemblyInfo.cs                      
                 SecurityFrameworkException.cs "C:\Users\{user}\AppData\Local\Temp\.NETFramework,Version=v4.8.AssemblyAttributes.cs"

我已检查用户及系统环境变量,未发现明确引用MSBuild v12.0的配置。如何强制代理使用MSBuild v17.0?

MSBuild任务的YAML配置如下:

steps:
- task: MSBuild@1
  displayName: 'MSBuild solution src/{sln}.sln'
  inputs:
    solution: src/{sln}.sln
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    msbuildArguments: '/verbosity:normal/p:VisualStudioVersion=17.0 /m:1 /p:GenerateSerializationAssemblies=Off /p:Platform="Auto"'
    clean: true
    createLogFile: true

更新:
我尝试了以下方案,结果如下:

  • 安装新构建代理:使用最新版Azure代理并加入同一池,仍调用MSBuild v12.0
  • 切换为Visual Studio构建任务:仍使用MSBuild v12.0执行构建
  • 指定msbuild.exe路径:虽调用了正确路径的msbuild.exe,但构建失败,提示在v12.0目录中找不到targets文件:
C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(67,3): 
Error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.NETFramework.props" was not found. 
Confirm that the expression in the Import declaration "Microsoft.NETFramework.props" is correct, and that the file exists on disk.
  • 修复Visual Studio版本:无效果,仍使用错误版本的msbuild.exe
  • 手动用正确版本msbuild.exe构建代理下载的解决方案:大部分项目构建成功,但约9个项目失败,错误信息如下:
"C:\agent\_work\1\s\src\{sln}.sln" (default target) (1) ->
"C:\agent\_work\1\s\src\Tools\MakeTestSmartCard\MakeTestSmartCard.csproj" (default target) (133) ->
  C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(67,3): 
error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.NETFramework.props" was 
   not found. Confirm that the expression in the Import declaration "Microsoft.NETFramework.props" 
   is correct, and that the file exists on disk. 
[C:\agent\_work\1\s\src\Tools\MakeTestSmartCard\MakeTestSmartCard.csproj]

仍有部分构建被重定向至旧版本。

  • 创建基础测试项目并执行msbuild:构建成功,说明问题可能出在解决方案或其构建配置中。

内容的提问来源于stack exchange,提问作者DiskJunky

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 05:40:41