簡體   English   中英

使用不正確版本的 MSBuild 的自托管代理(用於 Azure 管道)

[英]Self-hosted agent (for Azure pipelines) using incorrect version of MSBuild

在使用 Azure 的自托管構建代理構建解決方案時,我明確設置了要使用的 MSBuild 版本,既在管道中的 MSBuild 任務中,也作為構建參數的一部分。

但是,在執行構建時,它使用的是更舊版本的 MSBuild,但我無法確定原因。 Azure 設置如此;

Azure 構建設置

我還驗證了正在運行的v12.0 ,正如我在diagnostic mode的日志中看到的那樣;

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 version 12.0的內容。 如何強制代理使用17.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

更新

我在評論中應用了以下幾項建議,並獲得了以下結果;

1 嘗試了什么

安裝新的構建代理

1 個結果

使用最新版本的 Azure 代理並將其安裝到同一個 azure 池,仍然會導致代理選擇 MSBuild V 12 ,而不是管道任務中配置的設置。


2 嘗試了什么

將生成任務更改為 Visual Studio 生成。

2 結果

該構建仍然選擇 MSBuild V 12來自行構建。


3 嘗試了什么

指定msbuild.exe的位置,而不是指定版本。

3 結果

確實在指定的位置選擇了正確的msbuild.exe ,但現在構建中斷尋找targets文件......在 v 12 MSBuild 文件夾中。 錯誤信息是;

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.

4 嘗試了什么

在 Visual Studio 版本上運行修復

4 結果

沒有效果。 仍在選擇錯誤版本的msbuild.exe


5 嘗試了什么

針對代理下載的解決方案手動運行正確版本的msbuild.exe

5 結果

構建失敗...但實際上構建了大部分項目。 它在解決方案中的 9/~60 個項目上失敗。 每個失敗項目的消息如下所示;

"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]

幾乎可以工作。 但是仍然有一些東西重定向了構建的一部分。


6 嘗試了什么

創建一個基本測試項目並針對該項目運行msbuild

6 結果

這有效並成功完成。 它表明解決方案或解決方案的構建配置中可能存在導致構建代理選擇 v12 的msbuild的內容。

這個虛擬機上都安裝了哪些版本的Visual Studio? 一位客戶遇到了類似的問題,他們重新安裝了 visual studio。

您能否檢查在代理功能中設置的版本:

https://stackoverflow.com/a/52828794/8843952

此外,這看起來有點相同:

https://developercommunity.visualstudio.com/t/azure-pipelines-msbuild-vstest-cannot-find-msbuild/937549

更新

由於您認為 VS2022 安裝弄亂了您的 VM,因此這些鏈接可能對搜索 MSBuild 很有用:

來自 wade Zhou msft 的額外建議

升級到 vsbuild: https ://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/vsbuild-v1?view=azure-pipelines

僅供參考,我剛剛檢查了我們重新安裝的客戶,他們現在正在使用 vsbuild 的所有 yaml 管道。 這也可能對您有用。

最后,我無法確定錯誤使用路徑的原因,最終從干凈的操作系統映像創建了一個新的虛擬機,然后安裝了 VS2019 和 VS2022。

雖然這最終奏效了,但我確實注意到,當 VM 配置為連接到 Azure 代理池,並且 MSBuild 任務指定要使用的版本 (17) 時,命令行開關/p:VisualStudioVersion=16.0的使用導致它覆蓋msbuild自己的設置。

就我而言,我需要其他程序集來編譯.sqlproj 這些(正確地)存儲在C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft.Data.Tools.Schema.SqlTasks.targets中。

然后,此文件在msbuild的 v17 中引用了所需的程序集。 但是,該開關導致它修改存儲在其配置文件中的設置並覆蓋程序集路徑的\17\部分並將其替換為\16\ 這隨后破壞了構建,因為已解析的路徑沒有指向有效位置。

雖然不是最初的問題,但它確實表明在msbuild解決這些問題時肯定存在...奇怪的...路徑操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM