Contains notes and lessons in working technology, especially .NET, Azure, DevOps, Agile, and Team Foundation Server.
Wednesday, July 12, 2017
TFS Hosted Build Controller and .NET 4.7
Friday, November 20, 2015
Getting all changesets associated to work items
using (TextWriter tmp = Console.Out)
{
using (var fs = new FileStream("Test.txt", FileMode.Create))
{
using (var sw = new StreamWriter(fs))
{
Console.SetOut(sw);
var workItemIds = new int[] { 1,2,3 };
var collectionUri = new Uri("http://yourtfs/server/");
try
{
using (var tpc = new TfsTeamProjectCollection(collectionUri))
{
var workItemStore = tpc.GetService<WorkItemStore>();
var teamProject = workItemStore.Projects["project-name"];
var versionControlServer = tpc.GetService<VersionControlServer>();
var artifactProvider = versionControlServer.ArtifactProvider;
var workItems = workItemStore.Query(workItemIds, "Select [System.Id], [System.Title] from WorkItems");
var allChangesets = new List<Changeset>();
foreach (WorkItem workItem in workItems)
{
allChangesets.AddRange(
workItem.Links.OfType<ExternalLink>().Select(link => artifactProvider.GetChangeset(new Uri(link.LinkedArtifactUri)))
);
}
var orderedChangesets = allChangesets.OrderByDescending(c => c.CreationDate).ToArray();
foreach (var changeset in orderedChangesets)
{
Console.WriteLine("{0} on {1:MM-dd-yyyy HH:mm} by {2} ({3} change(s))", changeset.ChangesetId, changeset.CreationDate, changeset.Owner, changeset.Changes.Length);
foreach (var change in changeset.Changes)
{
Console.WriteLine(" [{0}] {1}", change.ChangeType, change.Item.ServerItem);
}
Console.WriteLine("-----");
Console.WriteLine();
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
sw.Close();
}
}
Console.SetOut(tmp);
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
Wednesday, November 11, 2015
Branching
I had a conversation with a co-worker yesterday about when to create branches in TFS and the conversation reflected a confusion surrounding the use of branches. The coworker suggested that a new branch should be created each time code was being pushed to any environment because it’s the only way you can be completely sure the branch isn’t polluted.
To get the obvious out of the way, if a source control system “pollutes” a branch with no human intervention, get a new source control system. The system has failed at its most basic task. It is very likely this is not the case. It is probably how you are executing your branching and merging strategy.
Let’s take a typical branching structure: Dev > QA > Prod; Dev is the parent of QA, which is the parent of Prod. Changes are merged from Dev into QA, then from QA into Prod. You should never get merge conflicts when going from Dev to QA, or QA to Prod. Because of this, merging is clean and no “pollution” can happen.
How is this possible?
The only way a merge conflict happens is when a change has occurred in the target branch you are merging into which has not been integrated in the source branch. But - and this is the critical point - if you are following good merging practices, if a change must be made in QA or Prod, it is immediately merged into the parent branch(es). No exceptions! If I make a change in the QA branch, my next immediate check-in is a merge to the Dev branch from QA. I will resolve any merge conflicts with this merge, ensuring that my change is properly integrated in Dev. The next time Dev is merged into QA, it will already have this change, and so no merge conflicts will occur.
Tuesday, April 10, 2012
Crossing Domains without Password Pain
If the client has a TFS instance, you can save your username and password used to access it by going to the team web access site in Internet Explorer and saving your credentials when prompted. When you launch Visual Studio and connect to that TFS instance, it will then use your saved credentials.
Sunday, April 1, 2012
Team Foundation Server 2010 Security Practices
TFS Security
| Team Project Roles | Sharepoint Roles | Reporting Services Roles |
| Project Administrators Contributors Readers Builders | Full Control Design Contribute Read | Content Manager Browser |
- ProjectName\Project Administrators Members of this group can administer all aspects of the team project, although they cannot create projects.
- ProjectName\Contributors Members of this group can contribute to the project in multiple ways, such as adding, modifying, and deleting code and creating and modifying work items.
- ProjectName\Readers Members of this group can view the project but not modify it.
- ProjectName\Builders Members of this group have build permissions for the project. Members can manage test environments, create test runs, and manage builds.
TFS Security Tools
Configuring Security
- Use Active Directory groups to manage TFS access
- A/D groups for TFS access should reflect team and project structure.
Scenario 1: Multiple Departments, Multiple Products, Not-Shared within an IT organization
- Architects and possibly team leads should have Project Admin rights, and are the ones responsible for builds.
- Developers should be Contributors.
- QA, BA, and managers should have read-only rights to the source control, but be able to manage work items, iterations, areas, etc.
- The PMO office (executives) want to run reports and read access to source is fine.
| A/D Group Name | TFS Team Project Permission | Members |
| TFS.All | – | All TFS.* groups |
| TFS.ProjectName | – | All TFS.ProjectName.* groups |
| TFS.ProjectName.Admins | Project Administrator | Architects, maybe leads |
| TFS.ProjectName.Developers | Contributor | Developers |
| TFS.ProjectName.Editors | Work Item Editor | QA, BAs, Managers |
| TFS.ProjectName.PMO | Reader | PMO office |
Scenario 2: Multiple Departments, Multiple Products, Shared within an IT organization
| A/D Group Name | TFS Team Project Permission | Members |
| TFS.All | – | All TFS.* groups |
| TFS.ProjectName | – | All TFS.ProjectName.* groups |
| TFS.ProjectName.Admins | Project Administrator | Project leads |
| TFS.ProjectName.Editors | Work Item Editor | Managers and BAs |
| TFS.QA | Work Item Editor for all dev projects | QA |
| TFS.Developers | Contributor for all dev projects | Dev, Architects |
Scenario 3: Single Department, Multiple Products
| A/D Group Name | TFS Team Project Permission | Members |
| TFS.All | – | All TFS.* groups |
| TFS.Admins | Project Administrator | Project leads |
| TFS.Managers | Work Item Editor | Managers |
| TFS.Editors | Work Item Editor for all dev projects | QA and BAs |
| TFS.Developers | Contributor for all dev projects | Dev, Architects |
Scenario 4: Multiple Teams, Multiple Products, Some Common, Some Team-Specific
| A/D Group Name | TFS Team Project Permission | Members |
| TFS.All | – | All TFS.* groups |
| TFS.TeamName | – | All TFS.TeamName.* groups |
| TFS.TeamName.Admins | Project Administrator for team-specific and common projects | Project leads |
| TFS.TeamName.Developers | Contributor for team-specific and common projects | Developers |
| TFS.TeamName.Editors | Work Item Editor for team-specific and common projects | Managers, QA, BAs |
Tuesday, March 13, 2012
Essential TFS Process Template Modifications
<FIELD name="Assigned To" refname="System.AssignedTo" > <ALLOWEDVALUES expanditems="true" filteritems="excludegroups"> <LISTITEM value="[Project]\Project Administrators"/> <LISTITEM value="[Project]\Contributors"/> <LISTITEM value="[Project]\Not Assigned"/> </ALLOWEDVALUES> <PROHIBITEDVALUES expanditems="true"> <LISTITEM value="Project Administrators"/> <LISTITEM value="Contributors"/> <LISTITEM value="Not Assigned"/> </PROHIBITEDVALUES> <DEFAULT from="value" value="Not Assigned"/> <ALLOWEXISTINGVALUE/> <HELPTEXT>..snip..</HELPTEXT> </FIELD>
The other two modifications are to create initial states in both the Task and Bug work item types. This can be done by adding the states in the work item type editor, editing the workflow to add the states, and then republishing the work items back to the server. The flow on a bug would be modified to Created > Active > Resolved > Closed and the Task flow would be modified to a flow of Created > Active > Closed.
Monday, February 20, 2012
TFS 2010, Build Definitions, and Powershell
clear-host
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.WorkItemTracking.Client")
$tfsCollectionUrl = "http://{server}:8080/tfs/{collection}"
$server = new-object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection(New-Object Uri($tfsCollectionUrl))
$buildServer = $server.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
$workStore = $server.GetService([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore])
$workStore.Projects | ForEach-Object {
Write-Host ("Project: "+$_.Name)
$buildServer.QueryBuildDefinitions($_.Name) | select-object {$_.Name, $_.ContinuousIntegrationType} | format-table
}
Saturday, July 2, 2011
BRD Lite Rangers HOL–Web deployment task failed
Going through the HOL Lab for the BRD Lite Team Build process template, I received the error “Web deployment task failed” after changing the connection string to remove the ‘sqlExpress’ instance. Yet it still failed, even when I changed it to run under the Admin account. After turning on the Diagnostic detail, it turned out to be a different project issue:
This was because I had to change the connection string in the web project properties under the Package/Publish SQL tab. Once I removed the ‘sqlexpress’ value from the Data Source, my build succeeded.
Monday, May 23, 2011
TFS 2010 SP1 Installation Issue–TFS_SCHEMA_VERSION
I just completed applying TFS SP1 our production TFS server. The installation experience was smooth, but I ran into one problem that caused some minor panic and about an hour of research. The install succeeded, the server restarted, but the TFS Job would not start up, and when trying to connect to TFS via Visual Studio, it threw an error about a mismatch of TFS versions in the database. In the error log, the following was being logged:
TF53010: The following error has occurred in a Team Foundation component or extension:
Date (UTC): 23/05/2011 23:59:18
Machine: --removed--
Application Domain: TfsJobAgent.exe
Assembly: Microsoft.TeamFoundation.Framework.Server, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a; v2.0.50727
Service Host: 16ff6530-41b7-4803-8474-7ff80ca3c33f (--removed--)
Process Details:
Process Name: TFSJobAgent
Process Id: 2056
Thread Id: 1584
Account name: --removed--Detailed Message: There was an error during job agent execution. The operation will be retried. Similar errors in the next five minutes may not be logged.
Exception Message: The requested schema property TFS_SCHEMA_VERSION did not match the expected value. The server requires the Microsoft Team Foundation Server 2010 (SP1) schema but the database currently implements Microsoft Team Foundation Server 2010 (RTM). (type DatabaseSchemaException)Exception Stack Trace: at Microsoft.TeamFoundation.Framework.Server.TeamFoundationDatabaseSettings.ValidateDatabase(TeamFoundationRequestContext requestContext, String connectionString, String expectedSchema)
at Microsoft.TeamFoundation.Framework.Server.FrameworkSqlResourceComponent..ctor(TeamFoundationRequestContext requestContext, String databaseCategory)
at Microsoft.TeamFoundation.Framework.Server.TeamFoundationJobService.AcquireJob(TeamFoundationRequestContext requestContext, Guid agentId, TeamFoundationJobQueueEntry jobToStart)
at Microsoft.TeamFoundation.Framework.Server.JobRunner.AcquireJob(TeamFoundationRequestContext requestContext, TeamFoundationJobQueueEntry queuedJob)
at Microsoft.TeamFoundation.Framework.Server.JobApplication.CheckJobQueue()
at Microsoft.TeamFoundation.Framework.Server.JobApplication.ProcessJobQueueInternal()
at Microsoft.TeamFoundation.Framework.Server.JobServiceUtil.RetryOperationsUntilSuccessful(RetryOperations operations)
Upon opening SQL Management Studio and right clicking the Properties of the appropriate TFS collection database, sure enough, the version was still contained the value “RTM”. I changed the value to “SP1” (highlighted below), started the TFS Job service, and the collection servicing started immediately. Within 5 minutes, the server was up and fully operational.
I don’t know why this had to be done, but there it is. Hope this helps others who might run into this problem. Thanks to Stackoverflow for the answer to this.
Thursday, March 17, 2011
Installing TFS 2010 on a SQL Instance
When installing Team Foundation Server 2010 on a SQL Instance today, I ran into a couple of issues that are related to the SQL Browser service. If the SQL browser service is running, you only need to specify the server and instance name, as “sqlservername\instancename”. If the browser service is not running, you should specify the server name and port number, as “sqlservername, portnumber”. The value in the screenshot below did NOT work until I removed the “\tfs” value.
Tuesday, November 9, 2010
TFS Build Servers
By default TFS 2010 installs the build server with the fully qualified domain name as part of the path. In our environment, this caused the build servers to be unreachable. You can change this by going to TFS Admin Console on the build server, stop the build service, open the properties window, and remove the domain name from the path:
Tuesday, November 2, 2010
Configure Team Build 2010 to use a Proxy Server
If you want to set up the TFS 2010 Build server to use the TFS Proxy server, you’ll need to log in with the build account on the server and modify the registry with the following entries:
[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\TeamFoundation\SourceControl\Proxy]
"Enabled"="True"
"Url"="http://proxyservername:8081"
These entries are set when you use the Visual Studio UI to configure proxy usage, so if you have Visual Studio installed on the build server, you can configure it through the VS settings dialog.
Monday, October 11, 2010
TFS and Reporting Services Access Issue
After installing and configuring Team Foundation Server 2010 with Reporting Services, I was unable to access the Reporting Services instance from any other box besides the server itself, regardless of the account used (even the setup account was denied). I would hit the host/reports site and would be prompted for a username and password and even when putting valid credentials in, the site would still deny me. The solution ended up being to remove the Windows Negotiate authentication option from the RSReportServer.config file. This file is located at %Program Files%\Microsoft SQL Server\INSTANCENAME\Reporting Services\ReportServer. Remove the RSWindowsNegotiate node under Authentication/AuthenticationTypes.
Thursday, June 17, 2010
Migrating TFS 2008 from SQL 2005 to SQL 2008 (R2)
I have been tasked with upgrading our TFS 2008 instance to TFS 2010. However, our current environment is a TFS 2008 dual-server deployment running on a SQL 2005 database server, and TFS 2010 requires SQL Server 2008. In order to upgrade to TFS 2010, our current TFS 2008 instance must be migrated over to run against a SQL 2008 database server.
After quite a bit of searching and reading a variety documentation, I came to the conclusion that there doesn’t seem to be an official Microsoft document that describes this process. The closest thing to this was the endorsement of this article by several of the TFS folks. I highly recommend reading this article, as it is about 99% of what you’ll need to do in order to have a successful migration.
There is one gotcha that is very important or the process will fail when you try to move the TFS databases. You must install a TFS 2008 with SP1 integrated on a separate (or same) server configured to point to the new SQL 2008 database server to “prep” the database server and make sure all the necessary TFS components, jobs, and security roles are set up correctly.
Thus, before starting the process as described in the article, first create a new TFS 2008 instance with the database on the SQL 2008 instance you will be migrating too. Then you can begin following the instructions in the referenced article.
In addition, I unprovisioned WSS from the application tier server and re-provisioned it (by running the Sharepoint Products and Technologies Configuration Wizard), and then created a new web application on port 80, and then restored the content database and configured it to use the restored content database. I wanted to move all WSS databases (Admin, Config, and Content) and simply moving the Content was not sufficient. Note if you do this, you’ll probably need to reinstall the WSS extensions for TFS as the last step.
One final comment – we used SQL Server 2008 R2 and the migration worked fine. Just make sure your TFS install has SP1 integrated.
Other links I found helpful:
Wednesday, April 21, 2010
Creating TFS 2008 Build Server
The base install used for setting up a TFS 2008 Build server was Windows 2008 R2 Standard.
- Install Visual Studio 2008 Developer Edition, custom install, with only the Visual Web Developer and Team System Developer tools
- Install TFS 2008 Team Explorer
- Install Visual Studio 2008 Tester Edition, custom install, with only the Team System Tester Tools.
- Install VS 2008 SP1.
- Install the Web Deployment Setup.
- Install VS 2008 DB Pro GDR Update.
- Install Team Build.
- Install TFS SP1.
For .NET 4.0 Builds, I also installed:
- .NET 4.0 Framework
- Visual Studio 2010 Ultimate with the Web Development tools.
