Question

I´m trying to create a small console app in c#. I want to run the program and save all pending changes in TFS to a .txt file. But I cant get the arguments to work. Can someone help me?

Here is my code i haved done so far:

string argument = "@tf.exe status /collection:http://tiffany:8080/tfs/ /user:* /format:detailed >c:\\Status\\Detailed.txt";

try
{
    Process process = new Process();
    process.StartInfo.Arguments = "@call" + " " + "C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\Common7\\Tools\\VsDevCmd.bat";
    process.StartInfo.FileName = "cmd.exe";
    process.StartInfo.Verb = "runas";
    process.StartInfo.Arguments = argument;
    process.StartInfo.CreateNoWindow = false;
    process.Start();
}
catch (Exception ex)
{
    Console.WriteLine(ex.ToString());
    Console.ReadKey();
}
Was it helpful?

Solution

aI'm not really sure that I understand what you're trying to call, exactly. Let's assume you want to run the following command line from a C# application, as if you would call it from a command line:

tf.exe status /collection:http://tiffany:8080/tfs/ /user:* /format:detailed >c:\\Status\\Detailed.txt"

I would use this code:

string arguments = @"/C tf.exe status /collection:http://tiffany:8080/tfs/ /user:* /format:detailed >c:\\Status\\Detailed.txt";
this.process = new Process();
this.process.StartInfo.FileName = @"cmd.exe";
this.process.StartInfo.Arguments = arguments;

this.process.Start();

Edit: If that's all your console app does, why not consider creating a batch (.BAT / .CMD) file instead of a C# application?

OTHER TIPS

Instead of running a command line tool you could leverage the TFS API.

There are many articles out there, e.g. Code project article on topic

and

Sample code directly from the MSDN

I suppose you have to read standard error and output from process started:

Process process = new Process();
process.StartInfo.Arguments = @"status PATH /recursive";
process.StartInfo.FileName = "tf.exe";
process.StartInfo.CreateNoWindow = false;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
process.Start();

var st = process.StandardOutput.ReadToEnd();
var err = process.StandardError.ReadToEnd();

But parsing tf output is not easy and I'd like to suggest to use TFS API as @Mare said

You do not need to create an application in C # to save in a text file. Just use the parameters (...) > [file name].txt at the end of the command.

The ">" symbol send the result of any command to a file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top