Skip to content

Instantly share code, notes, and snippets.

@ritalin
Created November 26, 2012 06:25
Show Gist options
  • Save ritalin/4146829 to your computer and use it in GitHub Desktop.
Save ritalin/4146829 to your computer and use it in GitHub Desktop.
Run Powershell script from VisualStudio Post-Build-Event.
powershell -NoProfile -ExecutionPolicy RemoteSigned -file $(ProjectDir)\post-command.ps1
@nult2003
Copy link

it don't work with me

@dotdiego
Copy link

dotdiego commented Dec 10, 2021

@nult2003

You should put it in your .csproj like this

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
        <Exec Command="powershell -NoProfile -ExecutionPolicy RemoteSigned -file $(ProjectDir)\post-command.ps1" />
</Target>

@ritalin
Copy link
Author

ritalin commented Dec 12, 2021

@dotdiego Thank you for your following up.

@jacques-hoventer
Copy link

Still trying to figure this one out, but it looks like you need to somehow enclose your -file argument in quotes. If I execute the command in CMD it throws an exception probably because the path has spaces in it.

@jacques-hoventer
Copy link

Figured it out:

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
        <Exec Command="powershell -NoProfile -ExecutionPolicy RemoteSigned -file &quot;$(ProjectDir)post-command.ps1&quot;" />
</Target>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment