0

I would like to perform postBuild action in MS Visual Studio 2022 / C# project.

The action is to copy the executable into a different folder. However the folder is not yet created so the copy instruction fails. How to use the copy instruction in a way it creates the required directory or something other like mkdir? Is anywhere a list of available commands?

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
  <Exec Command="MKDIR $(SolutionDir)Outputs&#xD;&#xA;copy /Y $(TargetDir)$(TargetName).exe $(SolutionDir)Outputs\$(TargetName).exe" />
</Target>
no one special
  • 1,608
  • 13
  • 32
  • A directory `Outputs` is created when I use your code, and it does contain an executable. => not reproducible ? – Luuk Apr 09 '22 at 18:13
  • Not exactly. It does create the output in first build but fails to copy. Then on second build it is copying properly. Maybe the commands are executed in parallel and not sequentially? – no one special Apr 09 '22 at 20:27
  • I just removed the directory `Outputs`, and here it is re-created with a build, and does contain the exe file ( `fc Outputs\myProject.exe myProject\bin\Debug\net6.0\myProject.exe Comparing files OUTPUTS\myProject.exe and myProject\BIN\DEBUG\NET6.0\myProject.EXE FC: no differences encountered` ) – Luuk Apr 09 '22 at 20:51
  • And what I get is: 2>...Proj.csproj(17,5): error MSB3073: The command "MKDIR E:\...\Outputs 2>...Proj.csproj(17,5): error MSB3073: copy /Y E:\...\MyLib.dll E:\...\" exited with code 1. – no one special Apr 10 '22 at 04:38
  • When you have different projects in your solution: [How do I fix MSB3073 error in my post-build event?](https://stackoverflow.com/questions/17075279/how-do-i-fix-msb3073-error-in-my-post-build-event) – Luuk Apr 10 '22 at 08:41
  • About the list of available command, it is somewhere down here: https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-concepts?view=vs-2022 (which is on my long list to read sometimes... ) – Luuk Apr 10 '22 at 08:41

0 Answers0