I'm developing a Smart Device application that includes a native C++ DLL
that is used via PInvoke.
All Projects, including the C++ DLL, are contained in a single solution
like this:
Solution
MyLibrary.Native (C++ DLL)
MyLibrary (C# P/Invoke Wrapper)
MyApplication (C# App)
When I deploy the library to my PocketPC, it copies the binaries of each
project into a separate folder (eg. \Program
Files\MyLibrary.Native\MyLibrary.Native.dll and \Program
Files\MyLibrary\MyLibrary.dll). This means that my P/Invoke wrapper
cannot find the C++ DLL.
Is there a way I can tell Visual Studio to deploy the output of the
other projects into my application's target directory?
I already tried copying the binaries from the other projects into the
output folder of MyApplication using a post-build step, but while this
works flawlessly for C++ projects, C# projects will still only deploy
the files actually produced by the compiler.
-Markus-
Peter Foot - 26 Mar 2008 11:31 GMT
A C# project will copy any .dll files you reference to the output directory
if they are not part of a known distribution package (such as the .NETCF
libraries themselves). If you want to add a resource file or native dll add
it to your project and set the BuildAction property to "Content". Set the
Copy to Output Directory to "Copy if Newer". Now your project will deploy
the native dll to the same folder as your .exe
Regards.
Peter

Signature
Peter Foot
Microsoft Device Application Development MVP
www.peterfoot.net | www.inthehand.com
In The Hand Ltd - .NET Solutions for Mobility
> I'm developing a Smart Device application that includes a native C++ DLL
> that is used via PInvoke.
[quoted text clipped - 22 lines]
>
> -Markus-
Markus Ewald - 26 Mar 2008 12:14 GMT
> A C# project will copy any .dll files you reference to the output
> directory if they are not part of a known distribution package (such as
> the .NETCF libraries themselves). If you want to add a resource file or
> native dll add it to your project and set the BuildAction property to
> "Content". Set the Copy to Output Directory to "Copy if Newer". Now your
> project will deploy the native dll to the same folder as your .exe
Thanks, that's a nice solution!
The only problem with that would be that I cannot easily switch between
Release and Debug builds because I cannot add a link to
MyLibrary.Native.dll in both the bin\x86\Release and bin\x86\Debug folders.
I think I can solve that with a Pre-Build step that copies the C++
output directory from the correct build configuration to some temporary
place from where I can link it into the project.
> Regards.
>
> Peter
Thanks again,
-Markus-
Markus Ewald - 26 Mar 2008 13:36 GMT
Markus Ewald schrieb:
>> A C# project will copy any .dll files you reference to the output
>> directory if they are not part of a known distribution package (such
[quoted text clipped - 6 lines]
> Thanks, that's a nice solution!
> [...]
Well, I got the Release/Debug issue solved by manually inserting a
Condition into the ItemGroup in the .csproj file. Visual Studio seems to
handle it just fine. I'm linking the files directly from the C++ DLL's
target directory, so my build process is now also free of any
Pre-/Post-Build steps =)
The only annoyance is an inconsistency in the behavior of Visual Studio
between .NETCF 2.0 and .NET 2.0 builds:
- if I add a link to MyLibrary.Native.dll into my MyLibrary.dll project
under .NET 2.0, Visual Studio will copy it to the output folder of all
depending projects (in other words, I'll find MyLibrary.Native.dll in
the output folder of MyApplication if MyApplication references MyLibrary)
- if I do the same under .NETCF 2.0, MyLibrary.Native.dll will only be
copied into the output folder of the project containing the link (so
I'll find MyLibrary.Native.dll in the output folder of MyLibrary, but
not in that of MyApplication)
-Markus-
Mark Erikson - 26 Mar 2008 11:44 GMT
> I'm developing a Smart Device application that includes a native C++ DLL
> that is used via PInvoke.
[quoted text clipped - 22 lines]
>
> -Markus-
If you just need to have them in the same directory for debugging and
development, you need to change the "Output files folder" option to
the same location as your main project. In VS 2005, it's located at
Project > Properties > Devices.
However, Peter Foot is correct that for actual installation and
deployment, you'll want to include a build of the native DLL as a
"Content" file in your main project. I've got a project that does as
well.
Hope this helps!
Mark Erikson
http://www.isquaredsoftware.com