How to copy native libraries to the unit test staging directory in Visual Studio 2010

时光怂恿深爱的人放手 提交于 2019-12-10 15:18:50

问题


My project has dependencies on some native libraries (DLLs) that I normally copy via the MSBuild targets into the output directory. There is no problem when I run the application, but I am writing some unit tests in Visual Studio and every time I run the unit tests, the assemblies and executables are copied from the output directory into the staging folder: C:\path\to\MyProject\TestResults\myWorkStationName 2012-03-20 13_53_56\Out

Unfortunately the native DLLs are not copied into the staging directory and the staging directory is generated on every test run. Is there an MSbuild target that allows me to copy stuff into the staging directory?

P.S. I'm not sure if "staging directory" is the correct term, so please excuse my ignorance if it's not :).


回答1:


Solution wide deployment

From the VS menu: Test> Edit Test Settings > (settings file)> Deployment > check Enable deployment and add a directory or files.

Note for one caveat in this feature: enabled deployment for existing tests won't work until Visual Studio is restarted.

Single method deployment

Use the [DeploymentItem] attribute:

[TestMethod()]
[DeploymentItem("testFile1.txt")]
public void ConstructorTest()
{
    // Create the file to deploy
    Car.CarInfo();
    string file = "testFile1.txt";
    // Check if the created file exists in the deployment directory
    Assert.IsTrue(File.Exists(file), "deployment failed: " + file +
        " did not get deployed");
}



回答2:


For various unit test settings, including the 'staging directory' and adding additional deployment files, go to

Test->Edit Test Settings->Local

For your specific question, in that settings window, go to 'Deployment', and you should be able to add additional files to be deployed to the directory where your unit test will be run.

I believe you can also use attributes to define deployment items right in your code:

http://msdn.microsoft.com/en-us/library/ms182475.aspx



来源:https://stackoverflow.com/questions/9793294/how-to-copy-native-libraries-to-the-unit-test-staging-directory-in-visual-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!