今からでも間に合う

技術を学ぶのは今からでも遅くない

Using Azure DevOps REST API Without Personal Access Token

Use azure devops rest api without personal access token.

personal access tokenを使ったアプリは運用が面倒なのでこっちのほうがよさげ。

環境

  • Visual Studio 2022 Community
  • .NET Framework 4.8 Console App

nugetパッケージ

Microsoft.TeamFoundationServer.Client [19.255.1]

Microsoft.TeamFoundationServer.InteractiveClient [19.255.1]

事前準備

azure devops側でPersonal Access Tokenを取得しておく

コード

VssClientCredentialsを使ってアクセスすると、認証が通っていないときは認証画面が挟まってくるようになる。

        static void Main(string[] args)
        {
            var uri = new Uri(Define.URL);//https://dev.azure.com/{organization}/
            var credentials = new VssClientCredentials();
  
            var connection = new VssConnection(uri, credentials);
            // サービスごとのクライアント取得
            using (var c = connection.GetClient<ProfileHttpClient>())
            {
                var p = c.GetProfileAsync(new Microsoft.VisualStudio.Services.Profile.ProfileQueryContext(Microsoft.VisualStudio.Services.Profile.AttributesScope.Core)).Result;
            }
        }

参考

基本的に使用するクライアントは以下のリファレンスと対照性があるので、やりたいことをリファレンスで調べてからコードに落としていくと楽。

learn.microsoft.com

プライバシーポリシー


d払いポイントGETモール