C++ project dependency for .NET Core project

2019-05-04 16:37发布

问题:

I have solution with .NET Core project and C++ project. .NET Core project uses compiled C++ library via interop and DllImport. How can I configure my build process properly? I would like to have:

  1. Native library is built
  2. Native library is copied to output directory to my main application

Is it possible to do that with project.json and "dotnet build/publish" command?

回答1:

Open the property window of your native C++ project. Find Build Events/Post-Build Event/Command Line. Then input the following commands to copy the built dll and pdb files to the output directory of your main application.

xcopy /Y /S "$(OutDir)*.dll" "E:\output_directory_to_my_main_application"
xcopy /Y /S "$(OutDir)*.pdb" "E:\output_directory_to_my_main_application"