visual-studiovisual-studio-2022post-build-eventpre-build-eventbuild-events

Multiple post-build events in Visual Studio 2022


There are plenty of sites where it the possibility is described to add multiple post-build events in Visual Studio (also version 2022): just add newlines.
Apparently, it's not that simple:

I am working in Windows, so the newlines should work fine, but this is the error message I get (excerpt from "Errors" window):

Severity    Code    Description Project File    Line    Suppression State
Error       The command "copy C:\<Main_Dir>\bin\Debug\<Output_DLL>.dll C:\<Output_Dir_1>\

copy C:\<Main_Dir>\bin\Debug\<Output_DLL>.dll C:\<Output_Dir_2>\" exited with code 1.

It is clearly visible that the two copy commands are treated as one (just check the presence of the double quotes).

I can confirm that the *.csproj looks as follows:

...
    <PostBuildEvent>copy $(TargetPath) C:\<Output_Dir_1>\

copy $(TargetPath) C:\<Output_Dir_2>\</PostBuildEvent>
  </PropertyGroup>
...

What can I do in order to force Visual Studio 2022 to see my two post-build events as two post-build events instead of one?


Solution

  • I found the solution(s):

    1. The output directory names contained a space. Because of that, those names needed to be quoted.
    2. The commands need to end with /Y, in order to avoid the question "Do you want to overwrite?".

    Sorry for the inconvenience.