我們的一位開發人員創建了一個專案,該專案在他的 PC 上使用 Visual Studio 2017 成功構建。我想從 Azure Pipeline 在 Azure 虛擬機上構建專案。由于它將來自管道,因此我無法使用 Visual Studio UI。所以我首先嘗試從命令列構建它,如果可行,我將添加一個管道任務來完成它。
這個專案使用 NuGet 來安裝一些 MongoDB 包。這種復雜情況起初使故障排除感到困惑,因為它似乎是 MongoDB 問題,但事實并非如此。
第一個問題:
"C:\workspace\xxxxx\xxxxx.sln" (default target) (1) ->
"C:\workspace\xxxxx\xxxxx.csproj" (default target) (2) ->
C:\workspace\xxxxx\packages\MongoDB.Libmongocrypt.1.0.0\build\MongoDB.Libmongocrypt.targets(4,16):
error MSB4186: Invalid static method invocation syntax: "MSBuild]::IsOsPlatform('Windows')".
Method '[MSBuild]::IsOsPlatform' not found. Static method invocation should be of the form:
$([FullTypeName]::Method()), e.g. $([System.IO.Path]::Combine(`a`, `b`)).`
我在網上找不到有關此錯誤訊息的太多資訊,但在閱讀了我找到的內容后(例如,這個MongoDB Jira entry,聽起來我可能需要更新 MSBuild.
- 構建成功的 PC 上的 MSBuild:版本 15.9.21。
- 構建失敗的 VM 上的 MSBuild:版本 15.1.155
從這個 StackOverflow 執行緒中,我得出結論,嘗試自行更新 MSBuild 或采取零碎的方法是危險的。我選擇更新整個 VS 2017 應用程式。
Azure VM 是自托管的標準 DS3 v2 機器,計劃為 VS-2017-Ent-WS2016。它安裝了 VS 2017。我去了 Windows“功能和應用程式”,選擇了 VS 2017,并從那里更新了整個應用程式。
現在 Azure VM 上的 MSBuild 是 15.9.21 版。錯誤消失。第一個問題解決了。
第二個問題:
構建仍然失敗,但出現了不同的錯誤。
"C:\workspace\xxxxx\xxxxx.sln" (default target) (1) ->
"C:\workspace\xxxxx\xxxxx.csproj" (default target) (2) ->
(GetReferenceAssemblyPaths target) ->
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\
bin\Microsoft.Common.CurrentVersion.targets(1179,5):
error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.7.2" were not found.
To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application
to a version of the framework for which you have the SDK or Targeting Pack installed.
Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies.
Therefore your assembly may not be correctly targeted for the framework you intend.
[C:\workspace\xxxxxx\xxxxx.csproj]
如何修復第二個構建錯誤?
附加資料
由于我的 VS2017 更新,該命令ls C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework將最新的框架列為 v4.6.1、v4.6.2、v4.7.1 和 v4.X,所有這些都在今天加上時間戳。
我從官方網站下載了 Microsoft .NET Framework v4.7.2 安裝程式ndp472-kb4054531-web.exe。當我嘗試運行它時,安裝被阻止,原因是“.NET Framework 4.7.2 或更高版本的更新已安裝在這臺計算機上”。
uj5u.com熱心網友回復:
要修復錯誤:
未找到框架“.NETFramework,Version=v4.7.2”的參考程式集。要解決此問題,請為此框架版本安裝 SDK 或 Targeting Pack
下載/安裝包含目標包的4.7.2 SDK 。另請參閱安裝 .NET Framework Developer Pack 或 Targeting Pack
以下是一些可能有用的其他資源:
- 使用 .vsconfig 在整個組織中配置 Visual Studio
- 如何使用指定的組態檔從命令列 vs2019 for C ?
- Azure 上的 Visual Studio 映像(安裝了哪些功能)
- Visual Studio 安裝的命令列引數示例
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/494471.html
標籤:C# mongodb 天蓝色 构建 视觉工作室 2017
