Search code examples
visual-studio-2017post-build-eventpre-build-event

After creating Pre-build event, get error "The Exec task was not given a value for the required parameter Command"


I added some prebuild script to a Visual Studio 2017 project.

Pre-build script

powershell.exe -ExecutionPolicy ByPass -NoProfile -NonInteractive -File "./myscript.ps1"

It's just a script outputting some information in console.

The script executes correctly, whether it is launched directly in my Powershell console or from the build event (I can see the correct output in the Build Output panel in VS).


After the execution, the build fails with one error :

The "Exec" task was not given a value for the required parameter "Command"


I tried to reduce the problem to a minimal "./myscript.ps1" to show you my problem, and the problem occurs with any script, even an empty one!

And again, whatever the PS script is, it gives its output correctly.


Why does my build fail, and what can I do to fix it, while still running the script before build ?


Solution

  • The issue was caused by this entry in the .csproj project file :

    <Target Name="PostBuild" AfterTargets="PostBuildEvent">
      <Exec Command="" />
    </Target> 
    

    Apparently, I (or VS ;) ) mistakenly added an empty script for PostBuild at the same time.

    Removing the quoted entry solved the problem.

    Thanks to Hans Passant's comment for pointing to the right direction.