在Team Build 2010下运行针对Excel的unit testing的exception

我有一个使用Office PIA的Excel包装类。 我也有一个以前编写在NUnit上运行的有限的testing套件。 我们正在工作中迁移到TFS2010,所以我也将NUnittesting迁移到MSTest。

testing套件在我的开发机器上运行良好,如果在运行构build代理的机器上用MSTest命令行实用程序手动执行。 但是,当通过Team Build执行时,所有与磁盘I / O(打开,保存等)有关的testing都将失败。 我的构build代理正在域帐户上运行,并且该域帐户也是同一台计算机上的本地pipe理员。 几个不做任何磁盘I / O的testing运行良好,所以我知道Excel正在被解雇和可用。 只是看起来像一个权限问题或团队build设过程的限制。

所以这里是一个示例函数。 这是什么让我觉得这是一个Excel I / O问题。 File.Exists检查传递正常。 我在testing运行中没有收到FileNotFoundException,而是直接从interop层收到COMException。

public void OpenXLS(string workbookFilePath) { // Make sure given file path exists if (!File.Exists(workbookFilePath)) { throw new FileNotFoundException(String.Format(CultureInfo.CurrentCulture, "File '{0}' cannot be found.", workbookFilePath)); } // Open the Workbook _xlsWorkbook = _xlsWorkbooks.Open(workbookFilePath, 0, false, Missing.Value, "", Missing.Value, true, Missing.Value, Missing.Value, true, false, Missing.Value, Missing.Value, Missing.Value, Missing.Value); } 

例外:

 System.Runtime.InteropServices.COMException: Microsoft Excel cannot access the file 'C:\BuildPath\TestResults\TestRun\Out\TestBook.xls'. There are several possible reasons: • The file name or path does not exist. • The file is being used by another program. • The workbook you are trying to save has the same name as a currently open 

我有类似的问题,这个解决scheme为我工作: http : //blogs.msdn.com/b/sqlserverfaq/archive/2010/04/30/unable-to-open-excel-files-using-a-cscript-in -SQL-服务器jobs.aspx

在“systemprofile”文件夹中似乎需要“Desktop”文件夹。

  • 在位置C:\ Windows \ SysWOW64 \ config \ systemprofile下为Windows 2008 Server(x64)创build“桌面”文件夹

  • 而对于32位的Windows 2008 Server,在位置C:\ Windows \ System32 \ config \ systemprofile下创build“Desktop”文件夹

哈拉姆357,你做了我的一天!

但是,即使是在64位的机器上,也需要在C:\ Windows \ System32 \ config \ systemprofile中创build“桌面”文件夹。 我已经在两个目录中创build它,以确保。 不要忘记完全控制服务帐户,也许这是必要的。