microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
23.11k stars 6.37k forks source link

dll removed before debugging #16432

Closed trojanfoe closed 3 years ago

trojanfoe commented 3 years ago

Describe the bug The dependent library (pugixml in this case) is successfully linked and the dll copied into $(TargetDir) (I see it in File Explorer), however when I run the .exe the .dll file gets removed. After this happens the dll will never be copied into $(TargetDir) again during subsequent builds.

Environment

To Reproduce Steps to reproduce the behavior:

  1. ./vcpkg install pugixml:x64-windows
  2. Build project auto-linking with pugixml in VS.
  3. Look at $(TargetDir) in file explorer and note pugixml_d.dll exists.
  4. Run/Debug and get error message about missing dll.

Expected behavior The dll remains in the $(TargetDir).

Failure logs Error dialog produced: The code execution cannot proceed because pugixml_d.dll was not found. Reinstalling... blah blah.

Additional context

trojanfoe commented 3 years ago

When rebuilding, I see this in the build output:

Using "Delete" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>  Task "Delete"
1>    Deleting file "C:\Users\Andy\Documents\Source\ProjectName\x64\Debug\pugixml_d.dll".
1>  Done executing task "Delete".
trojanfoe commented 3 years ago

I am wondering if this is because vcpkg/msbuild doesn't realise there is a dependency on pugixml because it's the only header file that isn't installed into it's own sub-directory; instead it's installed into the top-level vcpkg\installed\x64-windows\include directory?

trojanfoe commented 3 years ago

Added a vcpkg manifest file to my project and set "use manifest" to "yes" in the VS project in order to explicitly state my dependencies:

{
    "name": "projectname",
    "version-string": "0.0.1",
    "dependencies": [ "directxtk", "pugixml", "effolkronium-random", "utfcpp", "yaml-cpp" ]
}

Didn't make a difference, so it's not a dependency issue.

Cheney-W commented 3 years ago

Thanks for reporting this issue to us! In order to investigate this issue, could you please provide us with your ProjectName.vcxproj file? Through this file, we may find out why the delelate task is triggered.

trojanfoe commented 3 years ago

Hi there, I have tried to checkout the previous commit showing the error but I have been unable to get it working. I therefore created a test project to try and reproduce the issue but of course this works perfectly and the dll is being copied into $(TargetDir) as expected. Sorry to waste your time on this :|

trojanfoe commented 3 years ago

@Cheney-W I have managed to reproduce the issue. MyProject.vcxproj.txt

trojanfoe commented 3 years ago

After initial build I see the following references to pugixml in the output window:

Task "Message"
1>    C:\Users\...\x64\Debug\pugixml_d.dll
1>  Done executing task "Message".
...
 Did not copy from file "C:\Users\...\x64\Debug\pugixml_d.dll" to file "C:\Users\...\x64\Debug\pugixml_d.dll" because the "SkipUnchangedFiles" parameter was set to "true" in the project and the files' sizes and timestamps match.

and running the .exe from File Explorer works fine.

Then hit F5 and I see:

Task "Delete"
1>    Deleting file "C:\Users\...\x64\Debug\pugixml_d.dll".
1>  Done executing task "Delete".

and an error dialog.

Cheney-W commented 3 years ago

@trojanfoe Thanks for your reply! I have some questions need confirm with you:

  1. Does this issue occur in a new console application project?
  2. Does this issue only occur in your current MyProject project?
  3. I saw there are 2 custombuildsteps in your vcxproj file, are this you expected?
  4. Could you please provide me with the ProcessContent.py file?
trojanfoe commented 3 years ago

@Cheney-W

  1. No, it works perfectly.
  2. Yes, when I change to the triplet x64-windows. I am currently using x64-windows-static-md and everything works fine.
  3. There is actually only one, which might have been misconfigured at the time of posting the project file (The Output field was missing so it wasn't running).
  4. It's attached, but it's nothing special.

ProcessContent.py.txt

PhoebeHui commented 3 years ago

I can't repro this issue, could you attach full log from build output?

JackBoosY commented 3 years ago

We hope your question was answered to your satisfaction; if it wasn't, you can reopen with more info.

saulthu commented 3 years ago

This one is very hard to reproduce. I occasionally have something very similar using VS2019. A very new C++ console project started, building OK, using vcpkg manifest mode, all working awesome, auto-copies all required DLLs from vcpkg, then setting up precompiled headers and I started to have the problem where DLLs were not copied. They are always removed by doing a build, and if I'm running by Ctrl+F5 to run without debug then it starts up very fast when using PCH. Perhaps there's a race condition and the fast build/run wins the race, but loses execution due to the need for DLLs?

sakiodre commented 1 year ago

I also have this issue for some reason, I'm running on my own vcpkg fork with a port updated if that matters. I fixed it by cd to vcpkg directory and re-run these commands:

bootstrap-vcpkg.bat
vcpkg integrate install