Suppose you work on a product and you want to release something. As an initial setup you could start with a folder were the source code existing.
At some point in time some of the basic requirements are implemented, the next step is testing your application. Let’s say you have some friends that will help on that. Meanwhile you get new requirements and you don’t what to mess up the existing code base, because you want to release the tested code.
At this point you could create a branch in TFS.
1. Create Main source folder and convert it to branch
2. Create a new branch Dev from the Main branch. Right click the Main branch and select Branch under Branching and Merging
3. Create a new branch from Dev called Release Candidate. Here you will have the code that is tested and will be shipped to the public.
It’s handy to have a visual hint regarding of how the branches are split. Go to Main and choose View Hierarchy under Branching and Merging .
This is a simple strategy that will help you build, test and release you application.
TF.exe is a Team Foundation command line tool that help you to run version control operations from a command prompt or script (bat or cmd). A detailed list of command can be found here.
I like Codeplex because I can keep my sources in sync. But because Codeplex is a free solution based of TFS it doesn’t offer all the facilities, like a build server. So, I started to automate a little bit this process and first thing was to do a get latest version from a console application.
1. First, a script file (cmd file) to get the sources from Codeplex
SET PATH=%PATH%;c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\
ECHO Trying TFS get...
REM IF NOT EXIST Create GetPath
IF NOT EXIST %Getpath% MD %Getpath%
REM if exists remove WORKSPACE and create NEW WORKSPACE
tf workspace /login:snd\your_user,password /delete WORKSPACENAME /noprompt /s:tfs.codeplex.com\TFSXX
tf workspace /login:snd\your_user,password /new /s:tfs.codeplex.com\TFSXX WORKSPACENAME /noprompt
REM unmap default WORKING FOLDER for newly created WORKSPACE
tf workfold /login:snd\your_user,password /s:tfs.codeplex.com\TFSXX /workspace:WORKSPACENAME /unmap $/
REM map WORKING FOLDER for newly created WORKSPACE
tf workfold /login:snd\your_user,password /server:tfs.codeplex.com\TFSxx /workspace:WORKSPACENAME /map $/TFSPathToProject/ %Getpath%
REM get the recent path through DOS command
REM get latest source from TFS
tf get /login:snd\your_user,password /recursive /noprompt
REM move back to actual path through DOS command
ECHO TFS get completed...pause
2. Call from C# code
It is a simple example of running a cmd file without showing the console and capturing the output and error messages in a variable.
StringBuilder runInformation = new StringBuilder();
string cmdFile = "Cmd\\getlatest.cmd";
ProcessStartInfo getStartInfo = new ProcessStartInfo(cmdFile);
getStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
getStartInfo.RedirectStandardError = true;
getStartInfo.RedirectStandardOutput = true;
getStartInfo.UseShellExecute = false;
using (Process getProcess = Process.Start(getStartInfo))
string errorMessage = getProcess.StandardError.ReadToEnd();
string outMessage = getProcess.StandardOutput.ReadToEnd();