Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MsTest: how to set the deployment item relative to either $(ProjectDir) or $(OutDir)

I want to add an deployment item to my test. As far as I understood up until now, the path is relative to the solution. I want the path to be relative to the project. Otherwise, the project can't be used in multiple solutions. How can I configure the deployment Item to be relative to a project dependent variable?

I was hoping for something like: [DeploymentItem(@"$(ProjectDir)..\..\bin\$(Configuration)")] but I don't find any documentation and it does not seem to work.


I just did a small test. Just plain wizard code and one deployment item:

[TestMethod]
[DeploymentItem("stdafx.cpp")]
void TestMethod1()
{
    Assert::Fail();
};

and the trx file shows the following line:

Warning: Test Run deployment issue: Failed to get the file for deployment item 'stdafx.cpp' specified by the test 'TestProject1.UnitTest1.TestMethod1': System.IO.FileNotFoundException: Could not find file 'd:\Development\Projects\deploymentItemTest\stdafx.cpp'. System.IO.FileNotFoundException: Could not find file 'd:\Development\Projects\deploymentItemTest\stdafx.cpp'. File name: 'd:\Development\Projects\deploymentItemTest\stdafx.cpp'

which means that "stdafx.cpp" is searched relative to the solution directory (which is in ...\depoymentItemTest) and not the project directory (which is in ...\depolymentItemTest\TestProject1)

like image 618
Tobias Langner Avatar asked Oct 11 '22 03:10

Tobias Langner


2 Answers

I know this is an old question, but my answer may help others. I was able to solve this problem with two simple steps:

  1. Create the following build event on the test project:

    xcopy /I /S /Y  "$(TargetDir)*.*" "$(SolutionDir)\bin"
    

    This will copy all the contents (including sub-directories) of the project folder to a folder "bin" relative to the solution.

  2. Add the following DeploymentItem to the test class:

    [DeploymentItem ("bin")]
    

    This will copy all the bin contentes to the test folder

This mechanism may be refined (if required) with additional filters both in the build event and the DeploymentItem

like image 81
Miguelb Avatar answered Oct 14 '22 01:10

Miguelb


Let the test setup copy the file to Environment.CurrentDirectory.

like image 29
Thomas Eyde Avatar answered Oct 14 '22 02:10

Thomas Eyde