2017-08-29 65 views
2

我正在構建一個簡單的Web鉤子函數,它使用C#資源管理器API對Azure資源執行一些工作。預編譯的Azure函數依賴項錯誤

.nuget\packages\microsoft.net.sdk.functions\1.0.2\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(31,5): error : Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified. 

我檢查了,一切都拉Newtonsoft.Json 9.0.1:與構建失敗。我猜這是由於我的Nuget包中有一些不匹配,但不知道如何挖掘?

我:

  • Microsoft.Azure.Management.ResourceManager 1.6.0預覽
  • Microsoft.NET.Sdk.Functions 1.0.2
  • Microsoft.Rest.ClientRuntime.Azure.Authentication 2.3.1

using System.Collections.Generic; 
using System.Net; 
using Newtonsoft.Json; 
using System.Net.Http; 
using System.Threading.Tasks; 
using Microsoft.Azure.Management.ResourceManager; 
using Microsoft.Azure.Management.ResourceManager.Models; 
using Microsoft.Azure.WebJobs; 
using Microsoft.Azure.WebJobs.Host; 
using Newtonsoft.Json.Linq; 
using Microsoft.Rest.Azure.Authentication;  

使用VS2 017 15.3.3

+0

您是否嘗試安裝較高版本的Newtonsoft.Json並將其降級爲Newtonsoft.Json 9.0.1版本?我們還可以從路徑C:\ Users \ username \ .nuget \ packages \ microsoft.net.sdk.functions \ 1.0.2 \ build \ netstandard1.0中獲取Microsoft.NET.Sdk.Functions.Build.targets文件。然後我們可以獲得更多關於這方面的信息 –

+0

你看過文件「packages.config」來驗證沒有引用舊版本嗎?還可以查看根項目文件夾下的「軟件包」目錄,並查看是否存在任何舊版本。你也可以在你的項目中查看你的引用:右鍵單擊Newtonsoft.Json並檢查那裏的版本以驗證它不是舊版本。 – Architekt

回答

0

這一切都歸結到預覽資源管理器包。

  • Microsoft.Azure.Management.ResourceManager 1.6.0預覽

由於這是我到GitHub的項目,並檢查它的開源。基本上來說,它需要一個特定版本的NewtonSoft。我通過將使用資源管理器API的代碼放入一個程序集中並使用它來解決了我的問題。這現在可以在Azure函數中正常工作。
總之,看看依賴關係,將它們隔離在一個程序集中,然後將其包含在項目中。