简体   繁体   中英

Error copying files from one project to another

I've created a *.dll file in C++ to be used in a C# program. The native DLL resides in my managed DLL wrapper. From there, I physically copied my the native DLLs (NativeDll.dll for debug and release) into my C# console application's debug and release folders. When I run the C# program, it runs as expected creating objects and displaying values.

The problem comes when I changed a default value of a variable in my native library (C++). When I run the program again, the changes to the variable (the with of a box) still holds the last value. From what I've searched for, I've found that I could copy the dll from one project into my C# project by this means in the project's Build Events/Post-build event command line:

copy "$(SolutionDir)ManagedDll\bin\$(Configuration)\NativeDll.dll"
      "$(SolutionDir)TestDLLConsole\bin\$(Configuration)"

When I run the program again, I get an error stating "exited with code 9009." The only way around this is to manually re-copy my NativeDll.dll files and overwrite the existing one whenever I make changes.

The 4 projects I have in my solution are with next build depending on the previous:

  • NativeLib (static library)
  • NativeDll
  • ManagedDll
  • TestDLLConsole (where I test to see if the dll works).

How do I get the Dlls to be copied into/overwritten every TestDLLConsole is compiled?

Maybe you are trying to overwrite the last dll that you copy with the last post build event. You can try:

copy /Y "$(SolutionDir)ManagedDll\bin\$(Configuration)\NativeDll.dll"
  "$(SolutionDir)TestDLLConsole\bin\$(Configuration)"

The /Y parameter suppresses prompting to confirm you want to overwrite an existing destination file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM