我使用批处理脚本自动获取和编译多个解决方案。以下是批处理文件中的示例代码段:
"C:\...\IDE\TF.exe" get $/NG3rdParty/Main /recursive
当我从命令提示符调用它时,这工作正常。但是,我正在编写一个C#程序来更改DLL的版本号,它执行以下操作:
var businessFile= @"C:\Build\Common.AssemblyInfo.cs";
var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(@"http://tfs:8080"));
var workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(businessFile);
var workspace = workspaceInfo.GetWorkspace(tfs);
workspace.PendEdit(businessFile);
var batchFilePath = @"\CleanBuild.bat";
var batchFile = path + batchFilePath;
var p = new Process
{
StartInfo =
{
FileName = batchFile,
UseShellExecute = true
}
};
p.Start();
p.WaitForExit();
从程序调用批处理文件时,同一行会抛出此异常:
Unable to determine the workspace. You may be able to correct this by running 'tf workspaces /collection:TeamProjectCollectionUrl'.
答案 0 :(得分:1)
BATCH脚本无法了解您在C#代码中声明的工作空间。如果在本地工作空间目录中启动Process,它应该可以工作:
var p = new Process
{
StartInfo =
{
FileName = batchFile,
WorkingDirectory = "<local workspace dir>",
UseShellExecute = true
}
};
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.workingdirectory.aspx