TFS build automation issue when unit test case opening an Excel file RRS feed

  • Question

  • We are facing problems in executing unit test cases through TFS build automation which tries to open an Excel file. Here are the details:


    ·         We are writing unit test cases for our Excel Add-In project (visual studio 2010).

    ·         As part of the unit test cases, we need to open an excel test data file which will be used by the unit test cases. This excel file is part of the solution and configured to be deployed for unit testing in “Local.testsettings” and “TraceAndTestImpact.testsettings” files.

    ·         We are using the below code to open the excel file. This code is written inside a unit test case, not in test/class initialize methods.


    InteropExcel.Application application = new InteropExcel.Application();

    InteropExcel.Workbook workBook = null;

    if (application != null)


           application.Visible = visibility;

    // Open the unit test data excel file.

           string filePath = Path.Combine(Environment.CurrentDirectory, fileName);

           workBook = application.Workbooks.Open(filePath);



    ·         Above code in the unit test case works fine in the local machine/TFS server through visual studio 2010 IDE. Same code works fine in command prompt using MSTest.exe (same command used by TFS build automation).

    ·         But, when the same unit testing is executed using TFS build automation, it fails with the following exception.

    Microsoft Excel cannot access the file 'C:\Builds\176\XXXX\XXXXXXXXX\TestResults\XXXXX_Any CPU_Debug\Out\TestData.xlsx'. 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 workbook.

    ·         When we checked the above “Out” folder, TestData.xlsx file exists and we are able to open the file in Excel 2010 manually from the same location.

    ·         We also checked that no other MSTest.exe is running which holds the file. Also, tried with only one test case as part of build automation which opens the excel file.


    Please let me know if any more details are needed.
    Sasikumar G
    Monday, February 28, 2011 6:25 PM

All replies

  • Hi Sasikumar,

    Just random thought. When you open excel for the first time, it asks to set the username and initials. May be this could be the reason. Can you login to the build machine with the build service account and try to see what you get on opening the excel file. If you get this pop up, try setting the values and queuing a build again.



    Monday, February 28, 2011 11:33 PM
  • Hi Anuj,

    Thanks for your response. We tried what you said but could not get the build run successfully. We are still facing the same issue. In fact, we didn't see the username/initials pop-up window when logged in with build service account.


    Sasikumar G
    Tuesday, March 1, 2011 6:31 AM
  • Given below is the link which has the solution to this problem. Using the solution provided there, we are able to get the unit testing working. http://social.msdn.microsoft.com/Forums/en/vbgeneral/thread/4d6c383a-94eb-4898-9d22-aa4bb69be25b


    Sasikumar G

    Tuesday, March 1, 2011 3:17 PM