2016-05-03 5 views
0

AzureFunctionsでGetDefinitionAsync()を使用しようとすると、次のエラーが発生し、VSTSからデータを取得できませんでした。AzureFunctionsはMicrosoft.TeamFoundation.Core.WebApiを参照できません

関数実行中の例外:Functions.VSTSWebhookCSharp。 Microsoft.Azure.WebJobs.Script:1つまたは複数のエラーが発生しました。 mscorlib:ファイルまたはアセンブリ 'Microsoft.TeamFoundation.Core.WebApi、Version = 14.0.0.0、Culture = neutral、PublicKeyToken = b03f5f7f11d50a3a'またはその依存関係の1つを読み込めませんでした。システムは、指定されたファイルを見つけることができません。

私は.dllはAzureFunctionsによって復元nugetされているかどうかをチェックし、それがD」に存在する:\ホーム\データ\関数\パッケージ\ nuget \ Microsoft.TeamFoundationServer.Client \ 14.89.0 \ libに\ net45 \ Microsoft.TeamFoundation.Core.WebApi.dll "

このエラーはありますか?

私が試したコードは次のとおりです。 (成功して、ASP.NETウェブフックを実行している。)

#r "Newtonsoft.Json" 
#r "System.Configuration" 

using System; 
using System.Collections.Generic; 
using System.Configuration; 
using System.Diagnostics; 
using System.IO; 
using System.Linq; 
using System.Net; 
using System.Net.Http; 
using System.Text; 
using System.Text.RegularExpressions; 
using System.Threading.Tasks; 
using Microsoft.TeamFoundation.Build.WebApi; 
using Microsoft.VisualStudio.Services.Common; 
using Newtonsoft.Json; 
using Newtonsoft.Json.Linq; 

public static async Task<object> Run(HttpRequestMessage req, TraceWriter log) 
{ 
    string jsonContent = await req.Content.ReadAsStringAsync(); 

    // Deserialize Json 
    var jsonObject = JsonConvert.DeserializeObject<VSTSWebHook>(jsonContent); 

    // From ApplicationSettings 
    var vstsUser = ConfigurationManager.AppSettings["VstsUser"]; 
    var vstsPassword = ConfigurationManager.AppSettings["VstsPassword"]; 

    // Create VSTS Connection from Json Value 
    var project = new Guid(jsonObject.resource.definition.project.id); 
    var definitionId = jsonObject.resource.definition.id; 
    var result = jsonObject.resource.result; 
    var buildId = jsonObject.resource.id; 
    var build = new BuildHttpClient(new Uri("https://<YOUR TENANT>.VisualStudio.com/DefaultCollection/"), new VssBasicCredential(vstsUser, vstsPassword)); 

    // Exception will happen at here. 
    // Obrain definition from VSTS 
    var buildDefinition = await build.GetDefinitionAsync(project, definitionId); 

    return req.CreateResponse(HttpStatusCode.OK, new { 
     body = $"Test Complete.", 
    }); 
} 

public class VSTSWebHook 
{ 
    public string subscriptionId { get; set; } 
    public int notificationId { get; set; } 
    public string id { get; set; } 
    public string eventType { get; set; } 
    public string publisherId { get; set; } 
    public Message message { get; set; } 
    public Detailedmessage detailedMessage { get; set; } 
    public Resource resource { get; set; } 
    public string resourceVersion { get; set; } 
    public Resourcecontainers resourceContainers { get; set; } 
    public DateTime createdDate { get; set; } 
} 

public class Message 
{ 
    public string text { get; set; } 
    public string html { get; set; } 
    public string markdown { get; set; } 
} 

public class Detailedmessage 
{ 
    public string text { get; set; } 
    public string html { get; set; } 
    public string markdown { get; set; } 
} 

public class Resource 
{ 
    public int id { get; set; } 
    public string status { get; set; } 
    public string result { get; set; } 
    public DateTime queueTime { get; set; } 
    public DateTime startTime { get; set; } 
    public DateTime finishTime { get; set; } 
    public string url { get; set; } 
    public Definition definition { get; set; } 
    public string uri { get; set; } 
    public string sourceBranch { get; set; } 
    public string sourceVersion { get; set; } 
    public Queue queue { get; set; } 
    public string priority { get; set; } 
    public string reason { get; set; } 
    public Requestedfor requestedFor { get; set; } 
    public Requestedby requestedBy { get; set; } 
    public DateTime lastChangedDate { get; set; } 
    public Lastchangedby lastChangedBy { get; set; } 
    public Orchestrationplan orchestrationPlan { get; set; } 
    public Logs logs { get; set; } 
    public Repository repository { get; set; } 
} 

public class Definition 
{ 
    public string type { get; set; } 
    public int revision { get; set; } 
    public int id { get; set; } 
    public string name { get; set; } 
    public string url { get; set; } 
    public Project project { get; set; } 
} 

public class Project 
{ 
    public string id { get; set; } 
    public string name { get; set; } 
    public string url { get; set; } 
    public string state { get; set; } 
} 

public class Queue 
{ 
    public object pool { get; set; } 
    public int id { get; set; } 
    public string name { get; set; } 
} 

public class Requestedfor 
{ 
    public string id { get; set; } 
    public string displayName { get; set; } 
    public string uniqueName { get; set; } 
    public string url { get; set; } 
    public string imageUrl { get; set; } 
} 

public class Requestedby 
{ 
    public string id { get; set; } 
    public string displayName { get; set; } 
    public string uniqueName { get; set; } 
    public string url { get; set; } 
    public string imageUrl { get; set; } 
    public bool isContainer { get; set; } 
} 

public class Lastchangedby 
{ 
    public string id { get; set; } 
    public string displayName { get; set; } 
    public string uniqueName { get; set; } 
    public string url { get; set; } 
    public string imageUrl { get; set; } 
    public bool isContainer { get; set; } 
} 

public class Orchestrationplan 
{ 
    public string planId { get; set; } 
} 

public class Logs 
{ 
    public int id { get; set; } 
    public string type { get; set; } 
    public string url { get; set; } 
} 

public class Repository 
{ 
    public string id { get; set; } 
    public string type { get; set; } 
    public object clean { get; set; } 
    public bool checkoutSubmodules { get; set; } 
} 

public class Resourcecontainers 
{ 
    public Collection collection { get; set; } 
    public Account account { get; set; } 
    public Project1 project { get; set; } 
} 

public class Collection 
{ 
    public string id { get; set; } 
} 

public class Account 
{ 
    public string id { get; set; } 
} 

public class Project1 
{ 
    public string id { get; set; } 
} 

UPDATE

はここに私のproject.jsonです。

{ 
"frameworks": { 
    "net46":{ 
    "dependencies": { 
     "Microsoft.TeamFoundationServer.Client" : "14.89.0", 
     "Microsoft.VisualStudio.Services.Client" : "14.89.0" 
    } 
    } 
} 
} 

それはBuildHttpClienseBaseクラスに含まGetDefinitionAsync()方法のように思えます。だから問題は、DLLをロードするのだろうか?

var t = typeof(Microsoft.TeamFoundation.Build.WebApi.BuildHttpClientBase); 
var member = t.GetMembers(
    BindingFlags.Public | BindingFlags.NonPublic | 
    BindingFlags.Instance | BindingFlags.Static | 
    BindingFlags.DeclaredOnly 
); 

結果は、それがAzureFunctions 0.2で解決

Method : CreateArtifactAsync 
Method : CreateArtifactAsync 
Method : CreateArtifactAsync 
Method : GetArtifactAsync 
Method : GetArtifactAsync 
Method : GetArtifactAsync 
Method : GetArtifactContentZipAsync 
Method : GetArtifactContentZipAsync 
Method : GetArtifactContentZipAsync 
Method : GetArtifactsAsync 
Method : GetArtifactsAsync 
Method : GetArtifactsAsync 
Method : GetBadgeAsync 
Method : DeleteBuildAsync 
Method : DeleteBuildAsync 
Method : DeleteBuildAsync 
Method : GetBuildAsync 
Method : GetBuildAsync 
Method : GetBuildAsync 
Method : GetBuildsAsync 
Method : GetBuildsAsync 
Method : GetBuildsAsync 
Method : QueueBuildAsync 
Method : QueueBuildAsync 
Method : QueueBuildAsync 
Method : UpdateBuildAsync 
Method : UpdateBuildAsync 
Method : UpdateBuildAsync 
Method : GetBuildCommitsAsync 
Method : GetBuildCommitsAsync 
Method : GetChangesBetweenBuildsAsync 
Method : GetChangesBetweenBuildsAsync 
Method : GetBuildControllerAsync 
Method : GetBuildControllersAsync 
Method : CreateDefinitionAsync 
Method : CreateDefinitionAsync 
Method : CreateDefinitionAsync 
Method : DeleteDefinitionAsync 
Method : DeleteDefinitionAsync 
Method : DeleteDefinitionAsync 
Method : GetDefinitionAsync 
Method : GetDefinitionAsync 
Method : GetDefinitionAsync 
Method : GetDefinitionsAsync 
Method : GetDefinitionsAsync 
Method : GetDefinitionsAsync 
Method : UpdateDefinitionAsync 
Method : UpdateDefinitionAsync 
Method : UpdateDefinitionAsync 
Method : GetBuildDeploymentsAsync 
Method : GetBuildDeploymentsAsync 
Method : GetBuildLogAsync 
Method : GetBuildLogAsync 
Method : GetBuildLogsAsync 
Method : GetBuildLogsAsync 
Method : GetBuildLogsZipAsync 
Method : GetBuildLogsZipAsync 
Method : GetBuildOptionDefinitionsAsync 
Method : CreateQueueAsync 
Method : DeleteQueueAsync 
Method : GetAgentPoolQueueAsync 
Method : GetQueuesAsync 
Method : GetResourceUsageAsync 
Method : GetDefinitionRevisionsAsync 
Method : GetDefinitionRevisionsAsync 
Method : GetBuildSettingsAsync 
Method : UpdateBuildSettingsAsync 
Method : AddBuildTagAsync 
Method : AddBuildTagAsync 
Method : AddBuildTagsAsync 
Method : AddBuildTagsAsync 
Method : DeleteBuildTagAsync 
Method : DeleteBuildTagAsync 
Method : GetBuildTagsAsync 
Method : GetBuildTagsAsync 
Method : GetTagsAsync 
Method : GetTagsAsync 
Method : DeleteTemplateAsync 
Method : DeleteTemplateAsync 
Method : GetTemplateAsync 
Method : GetTemplateAsync 
Method : GetTemplatesAsync 
Method : GetTemplatesAsync 
Method : SaveTemplateAsync 
Method : SaveTemplateAsync 
Method : GetBuildTimelineAsync 
Method : GetBuildTimelineAsync 
Method : GetBuildWorkItemsRefsAsync 
Method : GetBuildWorkItemsRefsAsync 
Method : GetBuildWorkItemsRefsFromCommitsAsync 
Method : GetBuildWorkItemsRefsFromCommitsAsync 
Method : GetWorkItemsBetweenBuildsAsync 
Method : GetWorkItemsBetweenBuildsAsync 
Constructor : .ctor 
Constructor : .ctor 
Constructor : .ctor 
Constructor : .ctor 
Constructor : .ctor 
NestedType : <GetArtifactContentZipAsync>d__11 
NestedType : <GetArtifactContentZipAsync>d__12 
NestedType : <GetArtifactContentZipAsync>d__13 
NestedType : <GetBuildLogAsync>d__56 
NestedType : <GetBuildLogAsync>d__57 
NestedType : <GetBuildLogsZipAsync>d__60 
NestedType : <GetBuildLogsZipAsync>d__61 
+0

復元後にproject.jsonとproject.lock.jsonの内容を共有してもよろしいですか? –

+0

@FabioCavalcante確かに、私は更新しました。 – guitarrapc

答えて

1

ました。

問題なくメソッドが正常に呼び出されました。

+0

完全に修正されていないようです。しかし、再起動ではなく、WebAppを停止/開始することで作業することができます。 – guitarrapc

関連する問題