views:

1780

answers:

5

Hi,

I have a Visual Studio 2008 solution with two projects in it. A C++ DLL and a Csharp application.

The Csharp application uses [DllImport] to access the functions in the DLL, and has a dependency set on the DLL.

For some reason, setting the dependency isn't sufficient to cause VS to copy the DLL to the build path of the app. So the app project has a post-build event which causes the DLL to get copied. (If anyone knows of a cleaner way of doing this, please let me know!)

The problem I have is that when I make a change to the DLL code, then attempt to run the Csharp application in the debugger, VS2008 fails to realise that the DLL must be rebuilt (and re-copied).

I have to force a re-build of the Csharp application (ie by explicitly choosing build, or by "touching" a .CS file).

Does anyone know how to tell Visual Studio to do the right thing? Thanks, Rob

Edits: I am using project dependencies. They aren't working correctly.

I am using a post-build event to copy the DLL across.

The issue is that, if you simply choose to debug the application, Visual Studio fails to recompile the changed C++ project, despite the fact that there is a dependency in place.

I know the dependency is working, because if I choose "Build" (as opposed to "Debug") the C++ DLL is built.

A: 

Hmm... so I haven't done this exact thing before but I just threw together a C++ lib project and a C# winform project in the same solution. I right-clicked the solution, chose Properties and then under Common Properties->Project Dependencies, I made the C# one depend on the C++ one.

When I make a mod to the C++ one, it will ask me if I want to rebuild the C++ one. There's a "Don't ask me" checkbox too.

Maybe my test is different than your situation, but it seemed to work when I did that.

Hope that is some help.

itsmatt
The problem is apparent if you attempt to debug the Csharp app. It fails to realise it needs to rebuild the DLL.
Rob
Strange - I didn't see that behavior. When I clicked run and ran in debug mode, it noticed the DLL was needing to be rebuilt.
itsmatt
If you make a code change in the dll, and maybe set a break point, when you click to run in the debugger you'll find that the DLL hasn't been rebuilt - ie. the break point won't be hit. (Or at least, that's what I see.)
Rob
A: 

Assuming the DLL project isn't used in another solution, why not put the post-build event on the DLL app project, so it is always copied?

Rob Walker
As mentioned in the original question, I am already using a post-build event on the DLL project. It does not get copied, because visual studio is not correctly deciding that the project needs to be bbuilt.
Rob
Sorry -- fingers and brain are disconnected ... put the post-build event on the app project so that it is copied every time it is built.
Rob Walker
Yes sorry, that's what I meant too. The problem is that the app is not being rebuilt despite the fact that the DLL *has* been changed and rebuilt. ie. the dependecies are enough to trigger a build of the DLL, but not the app!
Rob
Sorry again, it's on a pre-build event. Of course, post build events can be set to always get executed. I will try this...
Rob
No, that still doesn't work :( Starting the app in the debugger (F5) triggers a rebuild of the DLL, but *not* the app, so the post-build event isn't fired, even when it's set to build always.
Rob
A: 

I've not tried, but can't you do this with the build order?

Benjol
+1  A: 

"Build" and "Debug" do different things. In Tools - Options - Projects and Solutions - Build and Run, there is a checkbox "Only build startup projects and dependencies on Run". This is checked by default. So, if VS isn't recognising the DLL as a dependency, it won't build it when you choose "Debug".

I don't have VS to hand (only Express), but you could try adding the C++ DLL as a reference rather than a dependency.

Sunlight
A: 

I have experienced this same issue with applications that have DLL project dependencies. It seems to me that the problem is that Visual Studio only launches the post-build event if it has to recompile something in the Application's project. So, if you modify the DLL source without modifying any of the headers that the Application includes, then the Application is not recompiled because from it's perspective the DLL is the same. Since the application is not recompiled, the post-build event is not triggered. So, the Application is left with out of date DLLs. I have yet to come up with a good solution to this problem.