Post-build event with folders which contains spaces

How to fix MSB3073 errors in Visual Studio post-build events by quoting macros such as $(TargetPath) when file or folder paths contain spaces.

If you want to use a Post-build event with folders which contains a space often you get an error like:

The system cannot find the file specified.

c:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets(3397,13):
error MSB3073: The command
"COPY C:\Projekte\_Learning By Doing\EsriDE.QA.StyleCop\bin\Debug\EsriDE.QA.StyleCop.dll
"C:\Program Files\Microsoft StyleCop 4.3""
exited with code 1.

In my case I used the macro $(TargetPath) in following line which contains indirectly the spaces in _Learning By Doing:

COPY $(TargetPath) "C:\Program Files\Microsoft StyleCop 4.3"

To avoid this error also the macro must putted in quotes.

So the correct line is:

COPY "$(TargetPath)" "C:\Program Files\Microsoft StyleCop 4.3"