Avilan
Avilan

Reputation: 628

Copy C++ library to a C# project automatically on build? (Visual Studio 2010)

I have a library written in C++, and a wrapper for this library written in C#.

Both projects are under development, and the way it is now I have to manually copy the .dll from the C++ project to the C# project after each build.

So I was wondering if there was any way to make Visual Studio copy the .dll from the C++ project automatically when re-building?

Upvotes: 2

Views: 2209

Answers (4)

aledeniz
aledeniz

Reputation: 463

There are several approach to achieve what you request.

Here I suppose you are using Microsoft Visual C++, but on other platforms there will be analogous functionalities.

  • Right click on the icon representing the vc++ project on the Solution explorer
  • Click Properties
  • Select the Configuration Properties/Build Events/Post Build Event node
  • Write the Command Line required to copy the dll around

Remember you must do it for every Configuration and for every Platform supported from your project.

Alternatively you may ask the Linker to output directly on the location referenced by your C# project:

  • Right click on the icon representing the vc++ project on the Solution explorer
  • Click Properties
  • Select the Configuration Properties/Linker/General Event node
  • Set the Output File property to the location referenced by your C# project

That said, you may also get the dll from the c# project.

Upvotes: 0

JohnnBlade
JohnnBlade

Reputation: 4327

if yr using that c++ dll as reference, then u might be able to add the c++ project as a project reference, and everything will be copied automaticly, and it also helps while debugging.

Click on references in yr c# project, then a dialog window opens and choose Projects and select yr c++ project

Upvotes: 0

GETah
GETah

Reputation: 21409

Use post build event for that. Just something like xcopy <yourDllFilePath> <destinationPath> and it will copy your dll file to wherever your want

Upvotes: 0

Habib
Habib

Reputation: 223237

You can use Build events in visual studio and place a dos command to copy the dll to the current project

Right click on the project in Solution explorer in Visual studio, select properties. There in Build events you can type:

copy c:\Cplusproject\yourproject.dll $(TargetDir)

You can use Post Build or Pre Build events based on your requirements

See this article: http://geekswithblogs.net/dchestnutt/archive/2006/05/30/80113.aspx

Upvotes: 4

Related Questions