0

我使用批处理脚本来自动获取和编译几个解决方案。这是批处理文件中的示例片段:

"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'.

4

1 回答 1

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

于 2013-08-29T18:37:19.340 回答