post build copy file

Punnet Patel 21 Reputation points
2021-10-07T17:38:52.187+00:00

I am having a .net WPF application. After build is complete I want to copy a .dll to target directory.
For this I am writing following in the - Post Build Event Command Line

copy "$(prjname.pkgname)\mydll.dll" $(TargetDir)"

Due to "." it fails by giving error exit code 1.

If I hardcode the path like below it works

copy "c:\myprjpath\mydll.dll" $(TargetDir)"

Please suggest?

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
41,441 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 56,271 Reputation points
    2021-10-07T17:55:26.707+00:00

    That isn't a valid macro so you cannot use it in command. In the project properties where you generally add the post-build event there is an option to see the allowed macros. You are limited to them or env variables that may be defined at the point the post-build event runs.

    It is unclear to me what your pkgname variable is supposed to represent. In general I recommend that if you have binaries that your app depends on then place them into some sort of "Dependencies" folder as part of the project. Then your post-build event can copy all the files from the "Dependencies" to the target directory.

       xcopy /q /y "$(ProjectDir)dependencies\*.*" "$(TargetDir)"  
    

    If you need to use mutiple macros then join them.

       xcopy /q /y "$(ProjectDir)dependencies\$(ConfigurationName)*.*" "$(TargetDir)"  
    

    Note that directory macros already have the ending slash so you don't need to include them. Refer to the master list of available macros here.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.