<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>chandan.anjani</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/chandananjani/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/chandananjani/feed.xml</link>
    <description />
    <lastBuildDate>Wed, 17 Apr 2019 03:19:15 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>How to undelete releases of a release definition?</title>
      <link>https://docs.microsoft.com/archive/blogs/chandananjani/how-to-undelete-releases-of-a-release-definition</link>
      <pubDate>Thu, 29 Mar 2018 10:34:15 GMT</pubDate>
      <dc:creator><![CDATA[Chandan Anjani]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/chandananjani/?p=285</guid>
      <description><![CDATA[One of our customer have reported as he has deleted few releases of a given release definition...]]></description>
      <content:encoded><![CDATA[One of our customer have reported as he has deleted few releases of a given release definition accidentally and wanted to know a way to bulk un-delete those releases. The undelete can be done within 15 days of the soft delete and after that releases are permanently deleted. It can be un-deleted either using Powershell or C# program.

Using powershell:-

===============
<!-- HTML generated using hilite.me -->
<div style="background: #ffffff;overflow: auto;width: auto;border: solid gray;border-width: .1em .1em .1em .8em;padding: .2em .6em">
<pre style="margin: 0;line-height: 125%"><span style="color: #008800;font-weight: bold">param</span> (
[<span style="color: #008800;font-weight: bold">Parameter</span>(<span style="color: #008800;font-weight: bold">Mandatory</span>=<span style="color: #996633">$true</span>)]
[ValidateNotNullOrEmpty()]
<span style="color: #003366;font-weight: bold">[string]</span> <span style="color: #996633">$token</span>,
<span style="color: #003366;font-weight: bold">[int32]</span> <span style="color: #996633">$definitionId</span>
)

<span style="color: #888888">## Construct a basic auth head using PAT</span>
<span style="color: #008800;font-weight: bold">function</span> BasicAuthHeader()
{

<span style="color: #008800;font-weight: bold">  param</span>(<span style="color: #003366;font-weight: bold">[string]</span><span style="color: #996633">$authtoken</span>)
<span style="color: #996633">  $ba</span> = (<span style="background-color: #fff0f0">":{0}"</span> <span style="color: #333333">-f</span> <span style="color: #996633">$authtoken</span>)
<span style="color: #996633">  $ba</span> = <span style="color: #003366;font-weight: bold">[System.Text.Encoding]</span><span style="color: #ff0000;background-color: #ffaaaa">::</span>UTF8.GetBytes(<span style="color: #996633">$ba</span>)
<span style="color: #996633">  $ba</span> = <span style="color: #003366;font-weight: bold">[System.Convert]</span><span style="color: #ff0000;background-color: #ffaaaa">::</span>ToBase64String(<span style="color: #996633">$ba</span>)
<span style="color: #996633">  $h</span> = <span style="color: #ff0000;background-color: #ffaaaa">@</span>{Authorization=(<span style="background-color: #fff0f0">"Basic{0}"</span> <span style="color: #333333">-f</span> <span style="color: #996633">$ba</span>)<span style="color: #ff0000;background-color: #ffaaaa">;</span>ContentType=<span style="background-color: #fff0f0">"application/json"</span>}
<span style="color: #008800;font-weight: bold">  return</span> <span style="color: #996633">$h</span>
}

<span style="color: #888888"># Fill in your account name/project name/definition name</span>
<span style="color: #996633">$accountName</span> = <span style="background-color: #fff0f0">"anjani1"</span>
<span style="color: #996633">$projectName</span> = <span style="background-color: #fff0f0">"TFVCProj"</span>
<span style="color: #996633">$definitionNameToRecover</span> = <span style="background-color: #fff0f0">"New Release Definition"</span>
<span style="color: #888888"># Find the Id of release definition that got deleted</span>
<span style="color: #996633">$deletedReleasesUri</span> = <span style="background-color: #fff0f0">"https://$accountName.vsrm.visualstudio.com/$projectName/_apis/Release/releases?api-version=4.1-preview.6&amp;isDeleted=true&amp;definitionId=$definitionId"</span>
<span style="color: #996633">$h</span> = BasicAuthHeader <span style="color: #996633">$token</span>
<span style="color: #996633">$deletedReleases</span> = <span style="color: #007020">Invoke-RestMethod</span> -Uri <span style="color: #996633">$deletedReleasesUri</span> -Headers <span style="color: #996633">$h</span> -ContentType <span style="color: #ff0000;background-color: #ffaaaa">“</span>application/json<span style="background-color: #fff0f0">" -Method Get</span>
<span style="background-color: #fff0f0">$deletedReleasesIds = $deletedReleases.value.id # | ConvertTo-Json -Depth 100</span>
<span style="background-color: #fff0f0">write-host "</span>Found the total deleted releases <span style="color: #ff0000;background-color: #ffaaaa">:</span> <span style="color: #996633">$deletedReleasesIds</span>.count<span style="background-color: #fff0f0">"</span>
<span style="background-color: #fff0f0">For ($i=0; $i -lt $deletedReleasesIds.count; $i++)</span>
<span style="background-color: #fff0f0">{</span>
<span style="background-color: #fff0f0">$deletedReleaseId = $deletedReleasesIds[$i];</span>
<span style="background-color: #fff0f0">Write-Host "</span>Found the deleted id <span style="color: #ff0000;background-color: #ffaaaa">:</span> <span style="color: #996633">$deletedReleaseId</span><span style="background-color: #fff0f0">";</span>
<span style="background-color: #fff0f0"># Recover the deleted release</span>
<span style="background-color: #fff0f0">$undeleteReason = '{ "</span>Comment<span style="background-color: #fff0f0">" : "</span>Deleted by mistake<span style="background-color: #fff0f0">" }'</span>
<span style="background-color: #fff0f0">$undeleteReleaseUri = "</span>https<span style="color: #ff0000;background-color: #ffaaaa">:</span>//<span style="color: #996633">$accountName</span>.vsrm.visualstudio.com/<span style="color: #996633">$projectName</span>/_apis/Release/releases/<span style="color: #996633">$deletedReleaseId</span>`<span style="color: #008800;font-weight: bold">?</span>comment=<span style="color: #996633">$undeleteReason</span>&amp;api-version=4.1-preview.6<span style="background-color: #fff0f0">"</span>
<span style="background-color: #fff0f0">$undeletedDefinition = Invoke-RestMethod -Uri $undeleteReleaseUri -Headers $h -ContentType “application/json"</span> -Method Put -Body <span style="color: #996633">$undeleteReason</span>
<span style="color: #007020">write-host</span> <span style="background-color: #fff0f0">"Release id: $deletedReleaseId recovered successfully"</span>
}
</pre>
</div>
&nbsp;

Using C# You may refer the blog <a href="https://blogs.msdn.microsoft.com/chandananjani/2016/04/27/using-releasehttpclient-for-interacting-with-releasemanagement-service/">link </a>to know as how to program using ReleaseManagement client

==============

<!-- HTML generated using hilite.me -->
<div style="background: #ffffff;overflow: auto;width: auto;border: solid gray;border-width: .1em .1em .1em .8em;padding: .2em .6em">
<pre style="margin: 0;line-height: 125%"><span style="color: #008800;font-weight: bold">using</span> <span style="color: #0e84b5;font-weight: bold">System</span>;
<span style="color: #008800;font-weight: bold">using</span> <span style="color: #0e84b5;font-weight: bold">Microsoft.VisualStudio.Services.Client</span>;
<span style="color: #008800;font-weight: bold">using</span> <span style="color: #0e84b5;font-weight: bold">Microsoft.VisualStudio.Services.Common</span>;
<span style="color: #008800;font-weight: bold">using</span> <span style="color: #0e84b5;font-weight: bold">Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Clients</span>;
<span style="color: #008800;font-weight: bold">using</span> <span style="color: #0e84b5;font-weight: bold">Microsoft.VisualStudio.Services.WebApi</span>;
<span style="color: #008800;font-weight: bold">using</span> <span style="color: #0e84b5;font-weight: bold">Microsoft.VisualStudio.Services.ReleaseManagement.WebApi</span>;
<span style="color: #008800;font-weight: bold">using</span> <span style="color: #0e84b5;font-weight: bold">Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Contracts</span>;
<span style="color: #008800;font-weight: bold">using</span> <span style="color: #0e84b5;font-weight: bold">System.Diagnostics</span>;

<span style="color: #008800;font-weight: bold">namespace</span> <span style="color: #0e84b5;font-weight: bold">ReleaseHttpClientSample</span>
{
<span style="color: #008800;font-weight: bold"> class</span> <span style="color: #bb0066;font-weight: bold">Program</span>
 {

<span style="color: #008800;font-weight: bold">  static</span> <span style="color: #008800;font-weight: bold">void</span> <span style="color: #0066bb;font-weight: bold">Main</span>(<span style="color: #333399;font-weight: bold">string</span>[] args)

    {

      Uri serverUrl = <span style="color: #008800;font-weight: bold">new</span> Uri(<span style="background-color: #fff0f0">"https://anjani1.visualstudio.com"</span>);
<span style="color: #333399;font-weight: bold">      var</span> project = <span style="background-color: #fff0f0">"TFVCProj"</span>;
      VssCredentials credentials = <span style="color: #008800;font-weight: bold">new</span> VssClientCredentials();
      credentials.Storage = <span style="color: #008800;font-weight: bold">new</span> VssClientCredentialStorage();
      VssConnection connection = <span style="color: #008800;font-weight: bold">new</span> VssConnection(serverUrl, credentials);
      ReleaseHttpClient rmClient = connection.GetClient&lt;ReleaseHttpClient&gt;();
<span style="color: #333399;font-weight: bold">      var</span> releases = rmClient.GetReleasesAsync(project, definitionId: <span style="color: #6600ee;font-weight: bold">1</span>, isDeleted: <span style="color: #008800;font-weight: bold">true</span>).Result;
<span style="color: #008800;font-weight: bold">      foreach</span>(<span style="color: #333399;font-weight: bold">var</span> release <span style="color: #008800;font-weight: bold">in</span> releases)
          {
             rmClient.UndeleteReleaseAsync(project, release.Id, <span style="background-color: #fff0f0">"Deleted by mistake"</span>).SyncResult();
          }
    }
 }
}
</pre>
</div>]]></content:encoded>
    </item>
    <item>
      <title>Cancelling all InProgress/Queued environment between two days</title>
      <link>https://docs.microsoft.com/archive/blogs/chandananjani/cancelling-all-inprogressqueued-environment-between-two-days</link>
      <pubDate>Mon, 25 Dec 2017 02:38:07 GMT</pubDate>
      <dc:creator><![CDATA[Chandan Anjani]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/chandananjani/?p=265</guid>
      <description><![CDATA[Recently one of our internal customer 'OneDrive' reported as they have many InProgress/Queued...]]></description>
      <content:encoded><![CDATA[Recently one of our internal customer 'OneDrive' reported as they have many InProgress/Queued environments. And they wanted to cancel all such environments and asked us to help. So I have written a program which would take account url, project name, definition id, <span style="color: #032f62;font-family: Consolas">NumberOfDaysBefore and NumberOfDaysAfter and Cancel the environment.</span>

<strong>How to do</strong>:-
<ol>
 	<li>GetReleases2Async() takes parameter as minCreatedTime, maxCreatedTime, top and continuationToken, so get all releases between specified time period and then iterate over each release and then to each environment and find inprogress or queued environment.</li>
 	<li>Cancel the inprogress/queued environment. You may choose to delete the release as well so that retention can clear them off.</li>
</ol>
<strong>Code snippet</strong>:-
<!-- HTML generated using hilite.me -->
<div style="background: #ffffff;overflow: auto;width: auto;border: solid gray;border-width: .1em .1em .1em .8em;padding: .2em .6em">
<pre style="margin: 0;line-height: 125%"><span style="color: #008800;font-weight: bold">public</span> <span style="color: #008800;font-weight: bold">static</span> <span style="color: #008800;font-weight: bold">void</span> <span style="color: #0066bb;font-weight: bold">CancelAllInProgressReleases</span>(ReleaseHttpClient2 rmClient)
        {
            <span style="color: #333399;font-weight: bold">var</span> maxModifiedTime = DateTime.Now.AddDays(-numberOfDaysBefore);
            <span style="color: #333399;font-weight: bold">var</span> minModifiedTime = DateTime.Now.AddDays(-numberOfDaysAfter);

            <span style="color: #008800;font-weight: bold">try</span>
            {
                <span style="color: #333399;font-weight: bold">int</span> ctn = <span style="color: #6600ee;font-weight: bold">0</span>;
                IPagedCollection&lt;Release&gt; releases = <span style="color: #008800;font-weight: bold">null</span>;
                <span style="color: #008800;font-weight: bold">do</span>
                {
                    releases = rmClient.GetReleasesAsync2(
                    definitionId: definitionId,
                    statusFilter: ReleaseStatus.Active,
                    minCreatedTime: minModifiedTime,
                    maxCreatedTime: maxModifiedTime,
                    top: <span style="color: #6600ee;font-weight: bold">100</span>,
                    continuationToken: ctn,
                    expand: ReleaseExpands.Environments).Result;

                    ReleaseEnvironmentUpdateMetadata envMetaData = <span style="color: #008800;font-weight: bold">new</span> ReleaseEnvironmentUpdateMetadata();
                    envMetaData.Status = EnvironmentStatus.Canceled;
                    envMetaData.Comment = <span style="background-color: #fff0f0">"Good to cancel as it's pretty old"</span>;

                    <span style="color: #008800;font-weight: bold">foreach</span> (<span style="color: #333399;font-weight: bold">var</span> release <span style="color: #008800;font-weight: bold">in</span> releases)
                    {
                        <span style="color: #008800;font-weight: bold">foreach</span> (<span style="color: #333399;font-weight: bold">var</span> environment <span style="color: #008800;font-weight: bold">in</span> release.Environments)
                        {
                            <span style="color: #008800;font-weight: bold">if</span> (environment.Status == EnvironmentStatus.Queued || environment.Status == EnvironmentStatus.InProgress)
                            {
                                <span style="color: #008800;font-weight: bold">try</span>
                                {
                                    totalDeploymentToCancel++;
                                    Console.WriteLine(<span style="background-color: #fff0f0">"Cancelling the environment with releaseId: {0} ReleaseEnvironmentId: {1} "</span>, release.Id, environment.Id);
                                    <span style="color: #333399;font-weight: bold">var</span> result = rmClient.UpdateReleaseEnvironmentAsync(envMetaData, projectName, release.Id, environment.Id).Result;
                                    <span style="color: #888888">// rmClient.DeleteReleaseAsync(projectName, release.Id).SyncResult();</span>
                                }
                                <span style="color: #008800;font-weight: bold">catch</span> (Exception ex)
                                {
                                    Console.WriteLine(<span style="background-color: #fff0f0">"======================="</span>);
                                    Console.WriteLine(<span style="background-color: #fff0f0">"Not Cancelling the deployment with releaseId: {0} ReleaseEnvironmentId: {1} "</span>, release.Id, environment.Id);
                                    Console.WriteLine(ex.Message);
                                    Console.WriteLine(<span style="background-color: #fff0f0">"======================="</span>);
                                }
                            }
                        }
                    }

                    <span style="color: #333399;font-weight: bold">int</span>.TryParse(releases.ContinuationToken, <span style="color: #008800;font-weight: bold">out</span> ctn);
                } <span style="color: #008800;font-weight: bold">while</span> (releases.ContinuationToken != <span style="color: #008800;font-weight: bold">null</span>);

                Console.WriteLine(<span style="background-color: #fff0f0">"Total cancelled environments: {0}"</span>, totalDeploymentToCancel);
            }
            <span style="color: #008800;font-weight: bold">catch</span>(Exception ex)
            {
                Console.WriteLine(<span style="background-color: #fff0f0">"Could not get releases with given information"</span>);
            }
        }
    }
</pre>
</div>
<strong>Complete code</strong> :- <a href="https://github.com/chandan-anjani/VSTSRMAPISample/blob/master/OneDriveCancelReleases/OnDriveCancelReleases/Program.cs">https://github.com/chandan-anjani/VSTSRMAPISample/blob/master/OneDriveCancelReleases/OnDriveCancelReleases/Program.cs</a>

<strong>Usage</strong>:- OneDriveCancelReleases.exe &lt;ServerUrl&gt; &lt;ProjectName&gt; &lt;DefinitionId&gt; &lt;NumberOfDaysBefore&gt; &lt;NumberOfDaysAfter&gt;]]></content:encoded>
    </item>
    <item>
      <title>Compute changeset difference between two releases using API's</title>
      <link>https://docs.microsoft.com/archive/blogs/chandananjani/compute-changeset-difference-between-two-releases-using-apis</link>
      <pubDate>Tue, 04 Jul 2017 08:40:44 GMT</pubDate>
      <dc:creator><![CDATA[Chandan Anjani]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/chandananjani/?p=226</guid>
      <description><![CDATA[Below are the steps which can be followed to compute changeset difference between two releases for...]]></description>
      <content:encoded><![CDATA[<strong>Below are the steps which can be followed to compute changeset difference between two releases for TFVC project </strong>

===========================================================================================

<strong>Step1</strong>: Get details of the primary build artifact for the current release  using build API. Store 'sourceVersion' say as 'currentReleaseBuildVersion'

https://{account}.visualstudio.com/{project}/_apis/build/builds/{buildId}

e.g. https://testking123.visualstudio.com/3a607d2a-d6c9-4274-9d13-d83c544d5063/_apis/build/builds/2348

<strong>Step2</strong>: Get details of the primary build artifact for the older release. Store 'sourceVersion' say as 'baseReleaseBuildVersion'

<strong>Step3</strong>: Make sure as build definition for both the builds in Step#1 and Step#2 are same

<strong>Step4</strong>: Get the build definition details for above builds using API to get 'tfvcMapping' for further filtering

https://{account}.visualstudio.com/{project}/_apis/build/Definitions/{definitionId}

e.g. https://testking123.visualstudio.com/3a607d2a-d6c9-4274-9d13-d83c544d5063/_apis/build/Definitions/288

<strong>Step5</strong>: Make <a href="https://www.visualstudio.com/en-us/docs/integrate/api/tfvc/changesets">TFVC API</a> to find the difference using API

<a href="https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fblackmarble-source.visualstudio.com%2F9bc48086-6780-43c5-9019-b7ae5ad6ba00%2F_apis%2Ftfvc%2Fchangesets%3FsearchCriteria.fromId%3D%253cas&amp;data=02%7C01%7Cchandan.anjani%40microsoft.com%7Cf86b888946d34cfe193f08d47dbf6e72%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636271708545940754&amp;sdata=vPRUvXJA9bU0rfdbRqq3dbzsCyv6%2BOUq1DGi1PSk5sU%3D&amp;reserved=0">https://{account}.visualstudio.com/{project}/_apis/tfvc/changesets?searchCriteria.fromId=&lt;</a>baseReleaseBuildVersion&gt;&amp;searchCriteria.toId=&lt;currentReleaseBuildVersion&gt;&amp;searchCriteria.itemPath=&lt;item path as got in step#3 to filter further&gt;

e.g.

<a href="https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fblackmarble-source.visualstudio.com%2F9bc48086-6780-43c5-9019-b7ae5ad6ba00%2F_apis%2Ftfvc%2Fchangesets%3FsearchCriteria.fromId%3D%253cas&amp;data=02%7C01%7Cchandan.anjani%40microsoft.com%7Cf86b888946d34cfe193f08d47dbf6e72%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636271708545940754&amp;sdata=vPRUvXJA9bU0rfdbRqq3dbzsCyv6%2BOUq1DGi1PSk5sU%3D&amp;reserved=0">https://testking123.visualstudio.com/3a607d2a-d6c9-4274-9d13-d83c544d5063/_apis/tfvc/changesets?searchCriteria.fromId=</a>282&amp;searchCriteria.toId=284

<strong>Step6</strong>: Done!!!!

<strong>Below are the steps which can be followed to compute changeset difference between two releases for TFGIT project </strong>

============================================================================================

<strong>Step1</strong>: Get details of the primary build artifact for the current release  using build API. Store 'sourceVersion' say as 'currentReleaseBuildVersion'

https://{account}.visualstudio.com/{project}/_apis/build/builds/{buildId}

e.g. https://testking123.visualstudio.com/3a607d2a-d6c9-4274-9d13-d83c544d5063/_apis/build/builds/2348

<strong>Step2</strong>: Get details of the primary build artifact for the older release. Store 'sourceVersion' say as 'baseReleaseBuildVersion'

<strong>Step3</strong>: Make sure as build definition and repositoryId for both the builds in Step#1 and Step#2 are same. Store ''repository.Id' say as repositoryId.

<strong>Step4</strong>: Make POST call using  <a href="https://www.visualstudio.com/en-us/docs/integrate/api/git/commits#between-two-versions">TFGIT API </a>to find the difference using API

https://{account}.visualstudio.com/{project}/_apis/git/repositories/{<span>repository</span>}/commitsBatch?api-version=1.0

Request body: {"itemVersion":{"versionType":"commit","version":"<em>fromCommitGUIDHere</em>"},"compareVersion":{"versionType":"commit","version":"<em>toCommitGUIDHere</em>"}}

e.g. https://testking123.visualstudio.com/3a607d2a-d6c9-4274-9d13-d83c544d5063/_apis/git/repositories/<span>278d5cd2-584d-4b63-824a-2ba458937249</span>/commitsBatch?api-version=1.0

Request body: {"itemVersion":{"versionType":"commit","version":"currentReleaseBuildVersion"},"compareVersion":{"versionType":"commit","version":"baseReleaseBuildVersion"}}

<strong>Step5:</strong> Done]]></content:encoded>
    </item>
    <item>
      <title>Utilities methods to use ReleaseManagement REST API's</title>
      <link>https://docs.microsoft.com/archive/blogs/chandananjani/utilities-methods-to-use-releasemanagement-rest-apis</link>
      <pubDate>Thu, 23 Mar 2017 07:14:50 GMT</pubDate>
      <dc:creator><![CDATA[Chandan Anjani]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/chandananjani/?p=205</guid>
      <description><![CDATA[Refer post...]]></description>
      <content:encoded><![CDATA[Refer post <a href="https://blogs.msdn.microsoft.com/chandananjani/2016/04/27/using-releasehttpclient-for-interacting-with-releasemanagement-service/">https://blogs.msdn.microsoft.com/chandananjani/2016/04/27/using-releasehttpclient-for-interacting-with-releasemanagement-service/</a> to know as which nuget package is required to be installed.
<ol>
 	<li><b>How to add secret variable in release definition?</b></li>
</ol>
<!-- HTML generated using hilite.me -->
<div style="background: #ffffff;overflow: auto;width: auto;border: solid gray;border-width: .1em .1em .1em .8em;padding: .2em .6em">
<pre style="margin: 0;line-height: 125%"><span style="color: #008800;font-weight: bold">public</span> <span style="color: #008800;font-weight: bold">static</span> ReleaseDefinition <span style="color: #0066bb;font-weight: bold">AddSecretVariableInReleaseDefinition</span>(ReleaseHttpClient rmClient, <span style="color: #333399;font-weight: bold">string</span> projectName, ReleaseDefinition definition)
        {
            <span style="color: #333399;font-weight: bold">var</span> secretVariableKey = <span style="background-color: #fff0f0">"secretVariableKey"</span>;
           <span style="color: #333399;font-weight: bold">var</span> secretVariableValue = <span style="color: #008800;font-weight: bold">new</span> ConfigurationVariableValue { Value = <span style="background-color: #fff0f0">"secretVariableValue"</span>, IsSecret = <span style="color: #008800;font-weight: bold">true</span> };
            definition.Variables.Add(secretVariableKey, secretVariableValue);
            <span style="color: #333399;font-weight: bold">var</span> updatedDefinition = rmClient.UpdateReleaseDefinitionAsync(definition, projectName).Result;
            <span style="color: #008800;font-weight: bold">return</span> updatedDefinition;
        }
</pre>
</div>]]></content:encoded>
    </item>
    <item>
      <title>Release is failing with ‘Object  reference not set to an instance of an object’</title>
      <link>https://docs.microsoft.com/archive/blogs/chandananjani/release-is-failing-with-object-reference-not-set-to-an-instance-of-an-object-when-tfs-server-is-moved-from-one-server-to-other-with-prepareclone-changeserverid-remapdb-command</link>
      <pubDate>Fri, 12 Aug 2016 05:53:40 GMT</pubDate>
      <dc:creator><![CDATA[Chandan Anjani]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/chandananjani/?p=165</guid>
      <description><![CDATA[In case your release is failing with 'Object reference not set to an instance of an object' post...]]></description>
      <content:encoded><![CDATA[In case your release is failing with 'Object reference not set to an instance of an object' post upgrade of your TFS with below snapshot just after creating the release

<a href="https://msdnshared.blob.core.windows.net/media/2016/08/nullexecption.png"><img width="300" height="144" class="alignnone size-medium wp-image-166" alt="nullexecption" src="https://msdnshared.blob.core.windows.net/media/2016/08/nullexecption-300x144.png" /></a>

In case you have moved your TFS server from one machine to other and ran PrepareClone, ChangeServerID, RemapDb following command <a href="https://www.visualstudio.com/en-us/docs/setup-admin/command-line/tfsconfig-cmd">https://www.visualstudio.com/en-us/docs/setup-admin/command-line/tfsconfig-cmd</a>

<strong>Workaround</strong>: - Create a new project in the same collection and trigger a release which should succeed. Later go back to your old project and trigger release it should work.]]></content:encoded>
    </item>
    <item>
      <title>CryptographicException while adding TFS connection to ReleaseManagement Update-4 client</title>
      <link>https://docs.microsoft.com/archive/blogs/chandananjani/cryptographicexception-while-adding-tfs-connection-to-releasemanagement-update-4-client</link>
      <pubDate>Mon, 16 May 2016 12:18:00 GMT</pubDate>
      <dc:creator><![CDATA[Chandan Anjani]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/chandananjani/2016/05/16/cryptographicexception-while-adding-tfs-connection-to-releasemanagement-update-4-client/</guid>
      <description><![CDATA[One of our customer reported below error :-Issue:- While adding a TFS connection, user were getting...]]></description>
      <content:encoded><![CDATA[<p>One of our customer reported below error :-<p><strong>Issue</strong>:- While adding a TFS connection, user were getting CryptographicException</p><p>Message: Bad Data.<br>: \r\n\r\n&nbsp;&nbsp; at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)<br>&nbsp;&nbsp; at System.Security.Cryptography.RSACryptoServiceProvider.DecryptKey(SafeKeyHandle pKeyContext, Byte[] pbEncryptedKey, Int32 cbEncryptedKey, Boolean fOAEP, ObjectHandleOnStack ohRetDecryptedKey)<br>&nbsp;&nbsp; at System.Security.Cryptography.RSACryptoServiceProvider.Decrypt(Byte[] rgb, Boolean fOAEP)<br>&nbsp;&nbsp; at Microsoft.TeamFoundation.Release.Data.Helpers.CryptoHelper.GetDecryptedValue(String str, String containerName)<br>&nbsp;&nbsp; at Microsoft.TeamFoundation.Release.Data.Helpers.CryptoHelper.DecryptString(String str, String cryptoContainerName, String key, Encryption encryption)<br>&nbsp;&nbsp; at Microsoft.TeamFoundation.Release.Data.Proxy.LocalProxy.EncryptionServiceLocalProxy.&lt;.ctor&gt;b__1(String x)<br>&nbsp;&nbsp; at Microsoft.TeamFoundation.Release.Data.Proxy.LocalProxy.EncryptionServiceLocalProxy.Decrypt(String encryptionLocation)<br>&nbsp;&nbsp; at Microsoft.TeamFoundation.Release.Tfs.TfsHelperBase.SecureCredential.ToNetworkCredential()<br>&nbsp;&nbsp; at Microsoft.TeamFoundation.Release.Tfs.TfsHelperBase.GetCacheCredentialOfTFSServiceAccount(String tfsUrl)<br>&nbsp;&nbsp; at Microsoft.TeamFoundation.Release.Tfs.TfsHelperBase.GetTeamProjectCollectionForServiceUser(String tfsUrl)<br>&nbsp;&nbsp; at Microsoft.TeamFoundation.Release.Tfs.TfsHelperBase.GetTfsDetails(String tfsUrl, String userName, String encryptedPassword)<br>&nbsp;&nbsp; at Microsoft.TeamFoundation.Release.ServiceProcessor.Processor.TfsServiceProcessor.GetTfsDetails(String tfsUrl, String userName, String encryptedPassword, Int32 tfsVersionId)</p><p>&nbsp;</p><p><strong>How it got fixed</strong> :-</p><p>From above call stack, It seems like the crypto key present on the customer machine were corrupt and hence Decrypt() were failing. Perform following steps to fix it (<strong>Note: You might have to re-enter password again at all places in your ReleaseTemplate and all other place</strong>)&nbsp;:-</p><p><span style="font-family: Calibri; font-size: small;">1. Navigate to </span><strong><span style="font-family: Calibri; font-size: small;">%ALLUSERSPROFILE%\Application Data\Microsoft\Crypto\RSA\MachineKeys </span></strong><span style="font-family: Calibri; font-size: small;">on the RM server machine and look for the key that looks like this - </span><strong><span style="font-family: Calibri; font-size: small;">918fda7df45a07822a6a453544ec6f66_&lt;SomeGuid&gt;. </span></strong><span style="font-family: Calibri; font-size: small;">Take a back-up of the key and delete it.</span></p><p>2. Close ReleaseManagement Client and Server window</p><p>3. Re-configure ReleaseManagement server (this will create the give with <strong><span>918fda7df45a07822a6a453544ec6f66_&lt;SomeGuid&gt; again. </span></strong></p><p>4. Try configuring your TFS again. it should work</p><p>5. Done!!!!</p></p>
]]></content:encoded>
    </item>
    <item>
      <title>Writing a ReleaseManagement extension for cloning an existing release definition</title>
      <link>https://docs.microsoft.com/archive/blogs/chandananjani/writing-a-releasemanagement-extension-for-cloning-an-existing-release-definition</link>
      <pubDate>Thu, 05 May 2016 03:17:00 GMT</pubDate>
      <dc:creator><![CDATA[Chandan Anjani]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/chandananjani/2016/05/05/writing-a-releasemanagement-extension-for-cloning-an-existing-release-definition/</guid>
      <description><![CDATA[Code shared :-...]]></description>
      <content:encoded><![CDATA[<strong>Code shared</strong> :- <a target="_blank" href="https://github.com/openalm/vsts-rm-extensions/tree/master/rd-export-import-clone-TFS2015U2" rel="noopener noreferrer" title="https://github.com/openalm/vsts-rm-extensions/tree/master/rd-export-import-clone-TFS2015U2">https://github.com/openalm/vsts-rm-extensions/tree/master/rd-export-import-clone-TFS2015U2</a>

<span style="text-decoration: underline"><strong>How to make Changes</strong>:-</span>

<strong>Step1</strong>: Clone the repository using the link <a target="_blank" href="https://github.com/openalm/vsts-rm-extensions.git" rel="noopener noreferrer" title="https://github.com/openalm/vsts-rm-extensions.git">https://github.com/openalm/vsts-rm-extensions.git</a>

<strong>Step2</strong>: Open a command prompt and go till folder 'rd-export-import-clone-TFS2015U2'

<strong>Step3</strong>: Run 'bower install' [ pre-requsite for running 'bower' can be referred <a target="_blank" href="https://github.com/Microsoft/vsts-extension-samples" rel="noopener noreferrer" title="https://github.com/Microsoft/vsts-extension-samples">https://github.com/Microsoft/vsts-extension-samples</a>] which will download 1.95.2 version of VSS.SDK.js

<strong>Step4</strong>: Make your changes

<strong>Step5</strong>:  Run '<span>tfx extension create</span>' to generate .vsix package in the current directory.  [Refer 'Try the extension in Visual Studio Team Services' section <a target="_blank" href="https://github.com/Microsoft/vsts-extension-samples" rel="noopener noreferrer" title="https://github.com/Microsoft/vsts-extension-samples">https://github.com/Microsoft/vsts-extension-samples</a>]

<strong>Step6</strong>: Done!!!!

<span style="text-decoration: underline"><strong>How to add 'Clone' as contextmenu item for ReleaseDefinition</strong></span>

<em>[A generic how to add item in context menu is explained <a target="_blank" href="https://www.visualstudio.com/en-us/integrate/extensions/develop/add-action" rel="noopener noreferrer" title="https://www.visualstudio.com/en-us/integrate/extensions/develop/add-action">https://www.visualstudio.com/en-us/integrate/extensions/develop/add-action</a>, below steps will explain similarly in context of ReleaseManagement]</em>

<strong>Changes required  in vss-extension.json [ </strong>Refer above shared code<strong>]</strong>

<strong>Step1</strong>: Add below as "scopes" in vss-extension.json  [Read more about ReleaseManagement scopes under 'Scopes' section in https://www.visualstudio.com/en-us/integrate/extensions/develop/manifest

"scopes": ["vso.release_execute"]

<strong>Step2</strong>: As we wanted to add one more item in the release definition context menu hence we will add one contribution (as below) in the vss-extension.json targeting "ms.vss-releaseManagement-web.release-definition-explorer-toolbar-menu" [ to learn more release management contribution point refer <a target="_blank" href="https://www.visualstudio.com/integrate/extensions/reference/targets/overview" rel="noopener noreferrer" title="https://www.visualstudio.com/integrate/extensions/reference/targets/overview">https://www.visualstudio.com/integrate/extensions/reference/targets/overview</a> ]

{
"id": "importDefinitionToolbarMenu",
"type": "ms.vss-web.action",
"description": "Import definition(s) menu",
"targets": [
"ms.vss-releaseManagement-web.release-definition-explorer-toolbar-menu"
],
"properties": {
"title": "Import release definition",
"icon": "images/icon-import-16.png",
"group": "actions",
"uri": "main.html"
}
}

===========================

<strong>Note:-</strong>  In case you are calling RM REST API from any contribution point outside RM hub then you may either of two approach :-

Approach1:- Add '<span>"includes": [ "ms.vss-releaseManagement-web.release-service-data-external" ],' as well. Refer the link <a href="https://github.com/Microsoft/vss-web-extension-sdk/issues/35">https://github.com/Microsoft/vss-web-extension-sdk/issues/35</a> </span>

This will cause RM account to be provisioned.

Approach2:- Add

"properties": {

"content": {

"contributionIds": ["ms.vss-releaseManagement-web.release-service-data-external"]

}

Approach2 is the recommended way and will work for VSTS and TFS2018 onwards.

<span>===========================</span>

<strong>Changes required  in main.js [</strong>Refer method cloneDefinitionContextMenu() in above shared code<strong> ]</strong>

<strong>Step1</strong>:- Create a rmClient using

var rmClient = VSS_Service.getCollectionClient(RM_WebApi.ReleaseHttpClient);

<strong>Step2</strong>: Make a getReleaseDefinition() call to get the definition object for the given id

rmClient.getReleaseDefinition(vsoContext.project.id,sourceItemContext.definition.id)

<strong>Step3</strong>: Update the definition name

definition.name = newDefinitionName;

<strong>Step4</strong>: Create a new definition using updated definition object in Step#3 above

rmClient.createReleaseDefinition(definition, vsoContext.project.id)

<strong>Step5</strong>: Refresh the UI to show the newly created definition

sourceItemContext.view.refresh();

<strong>Step6</strong>: Done!!!!

&nbsp;

<span style="text-decoration: underline"><strong>Complete code for quick reference</strong></span> :-

<!-- HTML generated using hilite.me -->
<div style="background: #ffffff;overflow: auto;width: auto;border: solid gray;border-width: .1em .1em .1em .8em;padding: .2em .6em">
<pre style="margin: 0;line-height: 125%"><span style="color: #008800;font-weight: bold">var</span> cloneDefinitionContextMenu <span style="color: #333333">=</span> (<span style="color: #008800;font-weight: bold">function</span> () {
    <span style="background-color: #fff0f0">"use strict"</span>;

    <span style="color: #008800;font-weight: bold">return</span> {
        execute<span style="color: #333333">:</span> <span style="color: #008800;font-weight: bold">function</span> (sourceItemContext) {
            <span style="color: #888888">// Load VSTS controls and REST client</span>
            VSS.require([<span style="background-color: #fff0f0">"VSS/Controls"</span>, <span style="background-color: #fff0f0">"VSS/Service"</span>, <span style="background-color: #fff0f0">"ReleaseManagement/Core/RestClient"</span>],
            <span style="color: #008800;font-weight: bold">function</span> (Controls, VSS_Service, RM_WebApi) {
                <span style="color: #008800;font-weight: bold">var</span> newDefinitionName <span style="color: #333333">=</span> prompt(<span style="background-color: #fff0f0">"New definition name:"</span>, sourceItemContext.definition.name <span style="color: #333333">+</span> <span style="background-color: #fff0f0">" - Copy"</span>);
                <span style="color: #008800;font-weight: bold">if</span> (newDefinitionName <span style="color: #333333">!=</span> <span style="color: #008800;font-weight: bold">null</span>)
                {
                    sourceItemContext.view.logMessage(<span style="background-color: #fff0f0">"Creating "</span> <span style="color: #333333">+</span> newDefinitionName <span style="color: #333333">+</span> <span style="background-color: #fff0f0">"..."</span>);
                    <span style="color: #008800;font-weight: bold">var</span> vsoContext <span style="color: #333333">=</span> VSS.getWebContext();
                    <span style="color: #888888">// Get a RM client to make REST calls</span>
                    <span style="color: #008800;font-weight: bold">var</span> rmClient <span style="color: #333333">=</span> VSS_Service.getCollectionClient(RM_WebApi.ReleaseHttpClient);
                    rmClient.getReleaseDefinition(vsoContext.project.id,sourceItemContext.definition.id).then(<span style="color: #008800;font-weight: bold">function</span>(definition){
                        definition.name <span style="color: #333333">=</span> newDefinitionName;
						rmClient.createReleaseDefinition(definition, vsoContext.project.id).then(() <span style="color: #333333">=&gt;</span> {
                            sourceItemContext.view.refresh();
                            sourceItemContext.view.logMessage(<span style="background-color: #fff0f0">"Cloned \'"</span><span style="color: #333333">+</span> sourceItemContext.definition.name <span style="color: #333333">+</span><span style="background-color: #fff0f0">"\' and created \'"</span> <span style="color: #333333">+</span> newDefinitionName <span style="color: #333333">+</span> <span style="background-color: #fff0f0">"\'"</span>);
                        }, <span style="color: #008800;font-weight: bold">function</span>(error){
                            sourceItemContext.view.logError(error);
                        });
                    }, <span style="color: #008800;font-weight: bold">function</span>(error){
                        sourceItemContext.view.logError(error);
                    });
                }
            });
        }
    }
}());
</pre>
</div>]]></content:encoded>
    </item>
    <item>
      <title>Using Clone, Export and Import an existing release definition for TFS2015 Update2</title>
      <link>https://docs.microsoft.com/archive/blogs/chandananjani/using-clone-export-and-import-an-existing-release-definition-for-tfs2015-update2</link>
      <pubDate>Thu, 05 May 2016 01:50:00 GMT</pubDate>
      <dc:creator><![CDATA[Chandan Anjani]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/chandananjani/2016/05/05/using-clone-export-and-import-an-existing-release-definition-for-tfs2015-update2/</guid>
      <description><![CDATA[Summary:- A ReleaseManagement extension for Cloning, Importing and Exporting an existing release...]]></description>
      <content:encoded><![CDATA[<p><strong>Summary</strong>:- A ReleaseManagement extension for Cloning, Importing and Exporting an existing release definition is released&nbsp;in the VisualStudio marketplace at <a title="https://marketplace.visualstudio.com/items?itemName=ms-devlabs.rm-clone-rd" href="https://marketplace.visualstudio.com/items?itemName=ms-devlabs.rm-clone-rd">https://marketplace.visualstudio.com/items?itemName=ms-devlabs.rm-clone-rd</a> . But as it uses some improvement done post release of TFS2015U2 hence it doesn't allow to be installed for TFS2015U2. I have tried to write another extension with slight variation of experience (explained below).</p>
<p><strong>How it's different from one released to VisualStudio marketplace</strong> :- Extension published at VisualStudio marketplace open the release definition to be saved after clicking the clone (from context menu)&nbsp;or import (from toolbar). Where as&nbsp;extension for TFS2015U2 makes direct REST call and&nbsp;creates a clone or import of an existing release definition. Following are TFS2015U2&nbsp;behaviour difference:-</p>
<p>&nbsp;- Environment owner will be same as original release definition</p>
<p>&nbsp;- In case of Import, Approver needs to be updated</p>
<p><strong>Code is shared</strong> :&nbsp; <a title="https://github.com/openalm/vsts-rm-extensions/tree/master/rd-export-import-clone-TFS2015U2" href="https://github.com/openalm/vsts-rm-extensions/tree/master/rd-export-import-clone-TFS2015U2">https://github.com/openalm/vsts-rm-extensions/tree/master/rd-export-import-clone-TFS2015U2</a></p>
<p><strong>How to Install it for TFS2015U2</strong> :-</p>
<p>Step1:- Download above mentioned repo which contains already build ms-devlabs.rm-import-export-0.0.1.vsix</p>
<p>Step2: open https://&lt;tfsserverurl&gt;/tfs/_gallery/manage</p>
<p>Step3:- Click on 'Upload new extension'</p>
<p>Step4: Give path to ms-devlabs.rm-import-export-0.0.1.vsix (as downloaded in step#1 above)</p>
<p>Step5: Click on the 'Install' button for the referred extension</p>
<p>Step6:- You should be able to see the Clone, Export in the release definition context menu and Import the new definition toolbar.</p>
<p>Step7: Done</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/69/30/6114.clone-onprem.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-69-30/6114.clone_2D00_onprem.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/69/30/6114.clone-onprem.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/300x400/__key/communityserver-blogs-components-weblogfiles/00-00-01-69-30/6114.clone_2D00_onprem.png" alt="" border="0" /></a></p>]]></content:encoded>
    </item>
    <item>
      <title>Using ReleaseHttpClient for interacting with ReleaseManagement service</title>
      <link>https://docs.microsoft.com/archive/blogs/chandananjani/using-releasehttpclient-for-interacting-with-releasemanagement-service</link>
      <pubDate>Wed, 27 Apr 2016 23:49:00 GMT</pubDate>
      <dc:creator><![CDATA[Chandan Anjani]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/chandananjani/2016/04/27/using-releasehttpclient-for-interacting-with-releasemanagement-service/</guid>
      <description><![CDATA[ReleaseHttpClient is public as nuget package :...]]></description>
      <content:encoded><![CDATA[ReleaseHttpClient is public as nuget package : <a href="https://www.nuget.org/packages/Microsoft.VisualStudio.Services.Release.Client/">https://www.nuget.org/packages/Microsoft.VisualStudio.Services.Release.Client</a>

GitHub samples: https://github.com/chandan-anjani/VSTSRMAPISample

<span style="text-decoration: underline"><strong>Fetching release definitions using given credential</strong></span> :-

<strong>Step1</strong>: Create one 'Windows Console Application' using Visual studio 2015

<strong>Step2</strong>: Goto Tools --&gt;NuGet Package Manager --&gt; Manage NuGet Packages for Solutions --&gt; Browse (make sure Package source: nuget.org)

<strong>Step3</strong>: Search and Install following package to your solution
<ul>
 	<li> Microsoft.VisualStudio.Services.Release.Client</li>
 	<li>Microsoft.VisualStudio.Services.InteractiveClient</li>
</ul>
<strong>Step4</strong>: Add following code to fetch all release definitions for a given project. Please update your tenant and project name in below sample.
<div style="background: #ffffff;overflow: auto;width: auto;border: solid gray;border-width: .1em .1em .1em .8em;padding: .2em .6em">
<pre style="margin: 0;line-height: 125%"><span style="color: #008800;font-weight: bold">using</span> <span style="color: #0e84b5;font-weight: bold">System</span>;
<span style="color: #008800;font-weight: bold">using</span> <span style="color: #0e84b5;font-weight: bold">Microsoft.VisualStudio.Services.Client</span>;
<span style="color: #008800;font-weight: bold">using</span> <span style="color: #0e84b5;font-weight: bold">Microsoft.VisualStudio.Services.Common</span>;
<span style="color: #008800;font-weight: bold">using</span> <span style="color: #0e84b5;font-weight: bold">Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Clients</span>;

<span style="color: #008800;font-weight: bold">namespace</span> <span style="color: #0e84b5;font-weight: bold">ReleaseHttpClientSample</span>
{
    <span style="color: #008800;font-weight: bold">class</span> <span style="color: #bb0066;font-weight: bold">Program</span>
    {
        <span style="color: #008800;font-weight: bold">static</span> <span style="color: #008800;font-weight: bold">void</span> <span style="color: #0066bb;font-weight: bold">Main</span>(<span style="color: #333399;font-weight: bold">string</span>[] args)
        {
            Uri serverUrl = <span style="color: #008800;font-weight: bold">new</span> Uri(<span style="background-color: #fff0f0">"https://{your tenant name}.visualstudio.com"</span>);
            VssCredentials credentials = <span style="color: #008800;font-weight: bold">new</span> VssClientCredentials();
            credentials.Storage = <span style="color: #008800;font-weight: bold">new</span> VssClientCredentialStorage();

            VssConnection connection = <span style="color: #008800;font-weight: bold">new</span> VssConnection(serverUrl, credentials);

            ReleaseHttpClient rmClient = connection.GetClient&lt;ReleaseHttpClient&gt;();

             <span style="color: #333399;font-weight: bold">var</span> releaseDefinitions = rmClient.GetReleaseDefinitionsAsync(<span style="background-color: #fff0f0">"{your project name}"</span>).Result;

            Console.Out.WriteLine(<span style="background-color: #fff0f0">"Release definitions "</span> + releaseDefinitions.Count);
        }
    }
}
</pre>
</div>
<strong>Step5</strong>: Done

&nbsp;

<span style="text-decoration: underline"><strong> Adding a variable to a given release using PAT Token</strong> </span>:-

<em>Follow <strong>Step1</strong> to <strong>Step3</strong> above</em>

<strong>Step4</strong>:-
<!-- HTML generated using hilite.me -->
<!-- HTML generated using hilite.me -->
<div style="background: #ffffff;overflow: auto;width: auto;border: solid gray;border-width: .1em .1em .1em .8em;padding: .2em .6em">
<pre style="margin: 0;line-height: 125%"><span style="color: #008800;font-weight: bold">using</span> <span style="color: #0e84b5;font-weight: bold">System</span>;
<span style="color: #008800;font-weight: bold">using</span> <span style="color: #0e84b5;font-weight: bold">Microsoft.VisualStudio.Services.Client</span>;
<span style="color: #008800;font-weight: bold">using</span> <span style="color: #0e84b5;font-weight: bold">Microsoft.VisualStudio.Services.Common</span>;
<span style="color: #008800;font-weight: bold">using</span> <span style="color: #0e84b5;font-weight: bold">Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.Clients</span>;

<span style="color: #008800;font-weight: bold">namespace</span> <span style="color: #0e84b5;font-weight: bold">ReleaseHttpClientSample</span>
{
    <span style="color: #008800;font-weight: bold">class</span> <span style="color: #bb0066;font-weight: bold">Program</span>
    {
        <span style="color: #008800;font-weight: bold">static</span> <span style="color: #008800;font-weight: bold">void</span> <span style="color: #0066bb;font-weight: bold">Main</span>(<span style="color: #333399;font-weight: bold">string</span>[] args)
        {
            <span style="color: #333399;font-weight: bold">string</span> collectionUri = args[<span style="color: #6600ee;font-weight: bold">0</span>];
            <span style="color: #333399;font-weight: bold">string</span> projectName = args[<span style="color: #6600ee;font-weight: bold">1</span>];
            <span style="color: #333399;font-weight: bold">string</span> patToken = args[<span style="color: #6600ee;font-weight: bold">2</span>];
            <span style="color: #333399;font-weight: bold">int</span> releaseId = <span style="color: #333399;font-weight: bold">int</span>.Parse(args[<span style="color: #6600ee;font-weight: bold">3</span>]);

            VssConnection connection = <span style="color: #008800;font-weight: bold">new</span> VssConnection(<span style="color: #008800;font-weight: bold">new</span> Uri(collectionUri), <span style="color: #008800;font-weight: bold">new</span> VssBasicCredential(<span style="background-color: #fff0f0">"username"</span>, patToken));
            ReleaseHttpClient client = connection.GetClient&lt;ReleaseHttpClient&gt;();
            <span style="color: #333399;font-weight: bold">var</span> release = client.GetReleaseAsync(projectName, releaseId).Result;

            <span style="color: #333399;font-weight: bold">var</span> variableValue = <span style="color: #008800;font-weight: bold">new</span> ConfigurationVariableValue();
            variableValue.Value = <span style="background-color: #fff0f0">"bar"</span>;
            release.Variables.Add(<span style="background-color: #fff0f0">"foo"</span>, variableValue);

            <span style="color: #333399;font-weight: bold">var</span> updatedRelease = client.UpdateReleaseAsync(release, projectName, releaseId).Result;

     } 
   } 
}
</pre>
</div>
<strong>Step5</strong>: Done]]></content:encoded>
    </item>
    <item>
      <title>Using PAT token in ReleaseManagement REST API's</title>
      <link>https://docs.microsoft.com/archive/blogs/chandananjani/using-pat-token-in-releasemanagement-rest-apis</link>
      <pubDate>Tue, 26 Apr 2016 23:42:00 GMT</pubDate>
      <dc:creator><![CDATA[Chandan Anjani]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/chandananjani/2016/04/26/using-pat-token-in-releasemanagement-rest-apis/</guid>
      <description><![CDATA[Generating PAT Token:-

Step1: Generate PAT token by visiting your profile and selecting the right...]]></description>
      <content:encoded><![CDATA[<strong>Generating PAT Token</strong>:-

Step1: Generate PAT token by visiting your profile and selecting the right ReleaseManagement scope as per API need ( see 'Available scopes' section https://www.visualstudio.com/en-us/integrate/extensions/develop/manifest )

<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/69/30/5756.PAT-image1.png"><img alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/69/30/5756.PAT-image1.png" border="0" /></a>

Step2: Copy the token generated after clicking 'Create Token' as shown in image above

&nbsp;

<strong>Code which uses the generated PAT token above :- </strong><strong>
</strong>

<!-- code formatted by https://manoli.net/csharpformat/ --> <!-- HTML generated using hilite.me -->
<div style="background: #ffffff;overflow: auto;width: auto;border: solid gray;border-width: .1em .1em .1em .8em;padding: .2em .6em">
<pre style="margin: 0;line-height: 125%"><span style="color: #008800;font-weight: bold">public</span> <span style="color: #008800;font-weight: bold">static</span> <span style="color: #008800;font-weight: bold">async</span> Task&lt;<span style="color: #333399;font-weight: bold">string</span>&gt; GetReleaseDefinitionsUsingPATToken()
        {
            <span style="color: #333399;font-weight: bold">var</span> username = <span style="background-color: #fff0f0">"nobody"</span>;
            <span style="color: #333399;font-weight: bold">var</span> token = <span style="background-color: #fff0f0">"&lt;Give your PAT Token here&gt;"</span>;

            <span style="color: #333399;font-weight: bold">var</span> url = <span style="background-color: #fff0f0">"https://{accountname}.visualstudio.com/{projectname}/_apis/release/definitions?api-version=3.0-preview.1"</span>;

            <span style="color: #008800;font-weight: bold">using</span> (HttpClient client = <span style="color: #008800;font-weight: bold">new</span> HttpClient())
            {
                <span style="color: #333399;font-weight: bold">var</span> mediaTypeHeader = <span style="color: #008800;font-weight: bold">new</span> MediaTypeWithQualityHeaderValue(<span style="background-color: #fff0f0">"application/json"</span>);
                client.DefaultRequestHeaders.Accept.Add(mediaTypeHeader);

                <span style="color: #333399;font-weight: bold">var</span> credentialBytes = Encoding.ASCII.GetBytes(<span style="color: #ff0000;background-color: #ffaaaa">$</span><span style="background-color: #fff0f0">"{username}:{token}"</span>);
                <span style="color: #333399;font-weight: bold">var</span> encodedCredentialBytes = Convert.ToBase64String(credentialBytes);
                client.DefaultRequestHeaders.Authorization = <span style="color: #008800;font-weight: bold">new</span> AuthenticationHeaderValue(<span style="background-color: #fff0f0">"Basic"</span>, encodedCredentialBytes);

                <span style="color: #333399;font-weight: bold">var</span> response = <span style="color: #008800;font-weight: bold">await</span> client.GetAsync(url);
                <span style="color: #333399;font-weight: bold">var</span> body = <span style="color: #008800;font-weight: bold">await</span> response.Content.ReadAsStringAsync();
                <span style="color: #008800;font-weight: bold">return</span> body;
            }
        }
</pre>
</div>
&nbsp;

&nbsp;

&nbsp;]]></content:encoded>
    </item>
  </channel>
</rss>