I would like to execute the "Post-build" event without building the project. is there an option to do so somehow?
-
Just run the same commands from the Developer Command Prompt. – Hans Passant Jan 04 '18 at 16:26
-
Looking at your commands and if you are using node.js, I think https://www.visualstudio.com/vs/node-js/ Node.js tools for VS will help you to properly setup your development environment. – KKS Jan 04 '18 at 16:41
2 Answers
Launch the Developer Command Prompt:
- Click on the start button.
- Type Developer Command Prompt and press ENTER.
Then copy the lines from your Visual Studio:
- Click on the Edit Post-Build button.
- Replace the
$(ProjectDir)
with the actual path to your project. - Copy the lines.
- Paste the lines in the command prompt and press ENTER.

- 24,690
- 13
- 50
- 55
I would recommend putting the commands into a batch file and simply running THAT in your Post Build Events field.
You can add it to your solution and then from Solution Explorer, right click, "Open With", and add a new item called:
- Name: Cmd
- Command: C:\windows\system32\cmd.exe
- Args: /c "$(ItemPath)"
- Initial Dir: $(ItemDir)
This will allow you to run Batch files from Solution Explorer in the future. More details here.
Bat File Solution 1
Either pass in the path to run from, or rely on %SolutionPath% (which is an env var that is provided when you run a bat file from Visual Studio). So this method is doing some directory sniffing. (note, solution 2 below is probably better - simpler for sure)
@echo off
if not [%1]==[] (set "ProjectDir=%1")
if not [%SolutionPath%]==[] (set "ProjectDir=%SolutionPath%\ProjectSubDirectory)
if [%ProjectDir%]==[] (
echo Error, no Solution Path env var or ProjectDir provided
exit /b
goto :eof
)
cd /d %ProjectDir%
ng build
Your post build events would then just run $(ProjectDir)\MyBatchFile.bat "$(ProjectDir)"
Bat File Solution 2
Run in directory relative to location of batch file (a simpler solution).
@echo off
pushd "%dp0"
ng build
popd
In this case your post build event would simply be: $(ProjectDir)\MyBatchFile.bat
and it would run in that same directory. I would recommend this approach for simplicity.
Pushd and popd are similar to "CD" except it's a stack that you can pop out of. So popd will return you to your original directory. %dp0
is the directory of the currently executing bat file.

- 13,994
- 6
- 46
- 79