我有一个使用Office PIA的Excel包装类。我还有一个有限的测试套件,它以前是为在NUnit上运行而编写的。我们正在工作中迁移到TFS2010,所以我也将NUnit测试迁移到MSTest。
该测试套件在我的开发机器上运行良好,如果在运行构建代理的机器上使用MSTest命令行实用程序手动执行,则运行得很好。然而,当通过Team Build执行时,所有与磁盘I/O (打开、保存等)相关的测试都会失败。我的生成代理在域帐户上运行,并且该域帐户也是同一台计算机上的本地管理员。少数不执行任何磁盘I/O的测试运行良好,因此我知道Excel正在启动并可用。只是看起来像是权限问题或团队构建过程的限制。
下面是一个示例函数。这就是我认为这是Excel I/O问题的原因。File.Exists检查通过正常。我在测试中没有收到FileNotFoundException,而是直接从互操作层收到了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 发布于 2011-05-23 21:21:33
我也遇到过类似的问题,这个解决方案对我很有效:http://blogs.msdn.com/b/sqlserverfaq/archive/2010/04/30/unable-to-open-excel-files-using-a-cscript-in-sql-server-jobs.aspx
在“systemprofile”文件夹中,“Desktop”文件夹似乎是必需的。
对于32位Windows 2008服务器,请在位置C:\Windows\SysWOW64\config\systemprofile
下,请创建“桌面”文件夹
发布于 2012-08-14 01:38:51
Harlam357,你真让我高兴!
但是,似乎即使在64位计算机上,您也需要在C:\Windows\System32\config\systemprofile.中创建“桌面”文件夹我已经在这两个目录中创建了它,以确保。别忘了完全控制Service帐户,可能需要它。
https://stackoverflow.com/questions/5642351
复制相似问题