Showing posts with label Team Foundation Server. Show all posts
Showing posts with label Team Foundation Server. Show all posts

Thursday, April 24, 2014

Hide Done Column On TFS Web Portal Task Boards

Working with TFS's kanbon board layout can be difficult as the number of tasks grow and the number of tasks in your done column ever increase. If the done column is hidden, it becomes easier to scroll to find things that are still in play. Below is a script that I use to accomplish that.

This script handles custom setups where the Done column is not in it's default location.
// ==UserScript==
// @name        TFS Boards Hide Done Column
// @namespace   net.intellectualponderings.TFSBoardsHideDoneColumn
// @include     http://*:8080/tfs/*/_boards*
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js
// @version     1
// @grant       GM_addStyle
// @grant       unsafeWindow
// ==/UserScript==

// Default easy method, doesn't work on customized layouts.
//GM_addStyle('#taskboard-table_s3, td[axis="taskboard-table_s3"] { display: none ! important; }');

var ob = (function () {
    var MutationObserver = window.MutationObserver || window.WebKitMutationObserver,
    eventListenerSupported = window.addEventListener;
    return function (obj, callback) {
        if (MutationObserver) {
            var obs = new MutationObserver(function (mutations, observer) {
                if (mutations[0].addedNodes.length || mutations[0].removedNodes.length)
                callback();
            });
            obs.observe(obj, {
                childList: true,
                subtree: true
            });
        } else if (eventListenerSupported) {
            obj.addEventListener('DOMNodeInserted', callback, false);
            obj.addEventListener('DOMNodeRemoved', callback, false);
        }
    }
}) ();
ob(document.getElementById('taskboard'), function () {
    var dth = $('.taskboard-row th:contains("Done")');
    if (dth) {
        var col = dth[0].id;
        // Hide the column
        GM_addStyle('#' + col + ', td[axis="' + col + '"] { display: none ! important; }');
        var numColumns = $('th.taskboard-cell:not(.taskboard-parent):visible').length
        if (numColumns > 0) {
            var newColumnWidth = 100 / numColumns;
            GM_addStyle('th.taskboard-cell:not(.taskboard-parent) { width: ' + newColumnWidth + '% !important; }');
        }
    }
});

Friday, January 31, 2014

Duplicate TFS Query in Visual Studio's Team Explorer

Just a quick post on how to duplicate TFS Queries. In my environment, I don't have permission to add columns to the Shared Queries, but I can edit my own queries. Instead of creating my own version of the Product Back Log from scratch, I wanted to duplicate the query as my own. It turns out that it is as easy as copying the query and pasting the query to the "My Queries" folder.


If you paste to the same directory or there is a name collision, you will be prompted to enter a new name.


Incredibly easy, but not obvious. I am surprised how many things I can do from the Team Explorer panel. It makes life much easier.

Thursday, October 3, 2013

XCode development with Team Foundation Server

Occasionally, I do work on multiple platforms and historically mixed development has been an issue when your environment requires TFS. However, with TFS supporting Git, it should make that development much easier. I just ran across a couple posts that with instructions on how to use TFS w/ XCode and thought I would share.

Microsoft has a page dedicated to making this happen: (UPDATE: 2016-05-05, Microsoft moved the page) https://www.visualstudio.com/get-started/code/share-your-code-in-tfvc-xcode http://tfs.visualstudio.com/en-us/learn/use-git-and-xcode-with-tfs.aspx . I don't have a Team Foundation Server at my disposal, but it looks like you should be able to do this with onsite Team Foundation servers.

In projects with .Net code and iOS (and/or potentially Android), it might be a good idea to keep the code in separate repositories. It appears that Team Foundation Server 2012 supports multiple Git repositories with a single TFS team project.

http://stackoverflow.com/questions/17591461/can-you-add-multiple-git-repositories-to-a-team-project-in-tfs-tfs-service
You can create multiple git repositories under a single Team Project. Navigate to the Code Explorer, and locate the repository chooser in the web interface and select Manage Repositories...

<repository chooser image>

From the repository manager, you can add a new repository:

<team Project Version Control tab image>

This, of course, is provided that the Team Project uses Git as the version control provider - you can't mix and match Git repositories and Team Foundation Version Control in a single Team Project.

If you have an existing project w/ TF source control, you are out of luck. You can't do multiple TF SC repositories or have a TF and Git repository, so the only option is Git for this.

It is nice to see Microsoft embracing an incredibly powerful tool like Git. Just need to be weary about them reverting back to the days of the 3 E's.

Tuesday, September 10, 2013

Branching Current Changes Into New TFS Branch

Every once in a while I find myself in the middle of a change and think that the changes I am making need to be pushed into a new branch. Being in an evironment using TFS as the source control system, that kind of flexibility is not something I generally think of in the scope of TFS.

From a Stack Overflow question, I was able to get a start. The most important line was the TFPT line. It appeared the task at hand was achievable.

1. You need to include the new branch in your workspace in order to see any changes (otherwise you'll only see the checked-in versions). From Source Control Explorer, select Workspace->Workspaces... from the toolbar.
2. Select Edit for your workspace and add a mapping to your new branch, e.g. Active|$/Root/MyProject-Branch|<my Local TFS Storage>\MyProject-Branch
3 .Run the command tfpt unshelve <shelveset> /migrate /source:$/Root/MyProject /target:$/Root/MyProject-Branch. It should create a new shelveset with mappings changed to your new branch.
4 .Try unshelving the new, migrated shelveset onto your new branch.

This wasn't very clear, so I continued my search. I found Brian Franklin's post was far more detailed and gave a better picture of what needed to happen.

1. Shelve the pending changes.
2. Create a new Dev branch with the latest changes and perform a Get on the branch.
3. Start Visual Studio Command Prompt.
4. Set the path to the folder the new branch is mapped to.
5. Execute tfpt unshelve command supplying the following arguments:
1. Shelveset name
2. Source server path
3. Target server path
4. Migrate
5. No Backup

In the process of going through his steps, which was easy enough, I ran into a peculiar error.

TFPT.EXE unshelve bundles /migrate /source:"$/<TFS project path>/branches/Feature1Rewrite" /target:"$/<TFS project path>/branches/Feature1RewriteExploritory"
An item with the same key has already been added.

Googling yielded no fruitful paths forward. And after some thought, it occurred to me that I might need to check in my branch before migrating my shelf to the new target. After checking in my branch and retrying, the did not occur.

It may be pertinent to note that when I create branches in this environment, I receive an error saying that I don't have permission to create a branch. However, the branch is created and everything seems to work.

TL;DR:

Make sure you check in your branch before running the command.

Wednesday, July 25, 2012

Git-Tfs Setup And Development Workflow

I finally got around to testing the git-tfs tool. I originally looked at this several months ago and didn't have time to dive into it and WOW was I missing out.

Those That Came Before Me

There are some excellent blogs out there which have plenty of information on this tool, except they all seem to miss the a major issue that none of them address. I will cover them below and the highlights of the installation process.

The Setup

To set it up, just clone the git-tfs GitHub repository. If you use GitHub for Windows, just click the "Clone in Windows" button.

To build the solution, make sure to use the Visual Studio 2010 Command Line, or at least make sure the Visual Studio environment variables are set.
msbuild GitTfs.sln /p:Configuration=Vs2010_Debug
It appears that there is a hidden step that should immediately follow this, copying the output to the Git\bin directory. From the git-tfs directory where the solution file exists, run the following (update accordingly).
copy /Y GitTfs.Vs2010\bin\Debug\*.dll "C:\Program Files (x86)\Git\bin"
copy /Y GitTfs.Vs2010\bin\Debug\*.exe "C:\Program Files (x86)\Git\bin"
Verify that the Git\bin directory is in your path. Open a git bash shell and run:
git tfs help
If the command is found, it is ready to go. At this point a celebration may be appropriate. There is still plenty of awesomeness to come.

The Simple Development Workflow

The workflow for this is actually pretty simple. Git-tfs is only needed in 3 use cases:
  • Clone the project
  • Pulling updates from TFS
  • Pushing files to TFS
Once the project has been cloned, standard git best practices apply. All check-ins to the git repository are stored with the reposiotry.

Getting The Project Files

There are a couple ways to get files out of TFS. You can clone the entire TFS project or just part of it. Performing a quick-clone will generate a git repository with only the latest code (no history). Using clone will generate a git repository with full history. NOTE: in all examples below, omitting <Local Location> will generate the repository in the current directory.

The following is an example of the commands required:
git tfs clone http://vstfs:8080 $/Team.Project <Local Location>

git tfs quick-clone http://vstfs:8080 $/Team.Project <Local Location>
The following are examples of generating a partial repository.
git tfs clone http://vstfs:8080 $/Team.Project/ <Local Location>

git tfs quick-clone http://vstfs:8080 $/Team.Project/ <Local Location>
This can be very useful for instances where a TFS project has multiple root folders like branches, tags, and trunk. It doesn't make a lot of sense to clone the tags unless you have to have it especially if the trunk is needed.

From this point forward, all local changes can be maintained with Git Bash or GitHub for Windows until the repository needs to be updated or changes checked in.

Updating The Repository From TFS

Updating is straight forward. All merging is accomplished with Git's merging functionality and tools.
git tfs pull

Pushing to TFS

Once the changes are complete, use the following to check in the changes. Checking-in to TFS does a rebase, in that it only checks in the latest version and the other check-ins in the git repository are left as is but not persisted in TFS.
git tfs checkin -m "Add a great comment"

That

Friday, July 6, 2012

Powershell Unlock File In TFS Using Visual Studio Command Line Vars

I recently found a situation where someone checked out a file and locked it. That severely impedes my ability to make changes to that file. So I set out to remove the lock using Powershell, while I didn't get the native Powershell functionality I normally like, it still achieves the solution in a usable script.

The solution required that I use tf.exe, not an issue, but it is not in windows path by default. It is available if you use the Visual Studio Command Line, which is just a regular command line which runs a batch file. I thought it might be useful to have the ability to turn Powershell into a Visual Studio Command Line. I found a blog post, Replace Visual Studio Command Prompt with Powershell, that works, but I updated it to work with Visual Studio 2010 and more fully use the power of Powershell.

Set Visual Studio Command Prompt environment variables
#Set Visual Studio Command Prompt environment variables
pushd "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC";
cmd /c "vcvarsall.bat&set" | ? { $_ -match "^(?<Name>[^=]+)=(?<Value>.+)$" } | % {
    Set-Item -Force -Path "env:\$($matches['Name'])" -Value $matches["Value"];
}
popd;
Write-Host "Visual Studio 2010 Command Prompt variables set." -ForegroundColor Yellow;
Here is my script to unlock a file in TFS even if the workspace doesn't belong to the user or on the users computer. If the command line arguments are not entered, the script will prompt for the arguments. It is a nice pattern that I may make a standard of in my scripts.
param(
  [string] $SourceControlFilePath = $(Read-Host "Source Control File Path"),
  [string] $Workspace = $(Read-Host "Workspace"),
  [string] $Username = $(Read-Host "Username")
)

& .\set-vsvars.ps1;

tf lock /lock:none $SourceControlFilePath /workspace:$Workspace`;$Username

Wednesday, August 26, 2009

Visual Studio 2008 Post-Build Event and Minify Using YUI Compressor

A time tested way to shrink and optimize JavaScript and CSS is to minify and obfuscate your files. Yahoo (High Performance Web Sites Rule 10) and Google (Minimize Payload Size) have best practices recommending minifying JavaScript.

The YUI Compressor is an excellent open source tool for this; the best I have found. My real world use reduced the size of the regular CSS and JavaScript files by 45%. Gzipping the files reduced CSS files by an additional 25% and JavaScript files by an additional 36%. Resulting in 75%+ smaller files.

Here is a batch file snippet which should speed up implementing this into your build process:

SET YUICOMPRESSOR=%Minify%\yuicompressor-2.4.2.jar
IF "%JAVA_HOME%" == "" (
 ECHO Searching for Java...
 for /f %%j in ("java.exe") do (set JAVA_HOME=%%~dp$PATH:j)
)
ECHO Java: %JAVA_HOME%
ECHO YUICOMPRESSOR: %YUICOMPRESSOR%
IF EXIST "%YUICOMPRESSOR%" (
 IF NOT "%JAVA_HOME%" == "" (
  ECHO Deleting Minified files, TFS can make these readonly and the compressor will not overwrite read only files...
  del /F "%CD%\<Path To Script Directory>\core.min.js"
  del /F "%CD%\<Path To Styles Directory>\core.min.css"
  ECHO Done.

  "%JAVA_HOME%java" -jar "%YUICOMPRESSOR%" -v --type JS -o "%CD%\<Path To Script Directory>\core.min.js" "%CD%\<Path To Script Directory>\core.js"
  "%JAVA_HOME%java" -jar "%YUICOMPRESSOR%" -v --type CSS -o "%CD%\<Path To Styles Directory>\core.min.css" "%CD%\<Path To Styles Directory>\core.css"
 ) ELSE (
  ECHO ERROR: Java is not installed, no Minification
 )
) ELSE (
 ECHO ERROR: YUI Compressor not found.
)

Also note that if a build event echos a line starting with "ERROR", not sure if it is case sensitive, the Visual Studio and Team Foundation Server will set that step as a failure and alert as expected. Remove the "ERROR:" text from the echo lines to allow the build to proceed if it cannot find the compressor or java.