Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell Script in PostBuild

Tags:

powershell

cmd

Continuous Integration

I have been working on a PowerShell script to keep our development process streamlined. I was planning on running it as a post-build event, but I'm having some trouble.

From the PowerShell prompt, the following works wonderfully:

PS C:\> ./example.ps1

However, when attempting to run this from cmd.exe as follows:

C:\> powershell -command "&\"C:\path to script\example.ps1\""

The script executes but I get a round of errors back from PowerShell, consisting mostly of path resolution errors from the resolve-path function:

Resolve-Path : Cannot find path 'C:\Documents and Settings\bdunbar\My Documents \Visual Studio 2008\Projects\CgmFamilyComm\FamilyComm\iirf\cms\isapirewrite4.dl l' because it does not exist. At C:\Documents and Settings\bdunbar\My Documents\Visual Studio 2008\Projects\C gmFamilyComm\scripts\cms.ps1:4 char:27 + $iirfpath = (resolve-path <<<< ../iirf/cms/isapirewrite4.dll).path,

Resolve-Path : Cannot find path 'C:\Documents and Settings\bdunbar\My Documents \Visual Studio 2008\Projects\CgmFamilyComm\FamilyComm\familycomm' because it do es not exist. At C:\Documents and Settings\bdunbar\My Documents\Visual Studio 2008\Projects\C gmFamilyComm\scripts\cms.ps1:5 char:27 + $vdirpath = (resolve-path <<<< ../familycomm).path

Is there a way to work around this? Could it be an issue with running resolve-path under cmd.exe?

[Update]

I've been able to change things to get around the errors that are occurring, but I still receive errors that work perfectly fine from the powershell command prompt. I can't figure out what the difference is.

like image 536
brad Avatar asked May 01 '09 20:05

brad


People also ask

How do I call a PowerShell script from Visual Studio?

Once it is saved as a PS1, VS Code will identify the file as a PowerShell script. From there, you can execute the PowerShell script by press F5 . You can also click the Run button on the top right of the editor. To run a select, you can press F8 or right click on the selection and click the Run Selection option.

How do I run an EXE from PowerShell?

You can run .exe files in PowerShell using three different methods: Typing “.\” followed by the name of the file. Using Invoke-Expression. Using Start-Process cmdlet.


1 Answers

I've made this work in the past (see http://sharepointpdficon.codeplex.com/SourceControl/changeset/view/13092#300544 if interested):

C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -NoLogo -NonInteractive -Command .'$(ProjectDir)Deployment\PostBuildScript.ps1' -ProjectDir:'$(ProjectDir)' -ConfigurationName:'$(ConfigurationName)' -TargetDir:'$(TargetDir)' -TargetFileName:'$(TargetFileName)' -TargetName:'$(TargetName)

Then throw these parameters in the first line of your post-build script (if you think you may be able to use them):

param($ProjectDir, $ConfigurationName, $TargetDir, $TargetFileName)

Also I should point out, I am not using this presently. I did like using it as a quick scratchpad to reload test data for running integration tests.

like image 171
Peter Seale Avatar answered Sep 19 '22 20:09

Peter Seale