I have lost a few hairs when trying to deal with DeploymentItem recently.
We have a few common directories for native dll's, and many tests depends on these.
For C++ projects, we use propertypages, where these paths are defined. These can even be imported in a C# project aswell, with some manual editing (as they are MSBuild files). Still I can't figure out how to utilize them in tests.
Unfortunately, the DeploymentItemAttribute can't use the properties in the sheet, but it can utilize environment variables. I was hoping to avoid forcing everybody to define global environment variables...
I have seen various suggestions around the net, but haven't really found a simple solution.
Anybody have good approach to this ?
Anders' answer is a good solution, but in my case:
I somehow ended up with this solution:
First, I included the global VC++ property page into the test project. This must be done manually by adding this directive under the <Project>
tag on top of the .csproj:
<Import Project="$(UserProfile)\AppData\Local\Microsoft\MSBuild\v4.0\Microsoft.Cpp.Win32.user.props" />
I now got access to the properties/macros that defines the dll paths in my C++ environment.
I then
"NativeDlls"
<Content Include="$(MyLibLocation)\GDAL18BIN\gdal18.dll">
<Link>NativeDlls\mylib.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
The dlls is then ready to deploy:
[TestMethod]
[DeploymentItem(@"NativeDlls")]
public void TestSomeStuff()
{
}
And, as Anders mentions: The remaining work is to set debug/release and 32/64 conditions.