From a Visual STudio external tool, I would like to call a powershell script like this :
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command "{ Add-PSSnapin Microsoft.SharePOint.POwerShell -EA 0; & ""C:\a very long path to my script with spaces\my-script.ps1"" -ProjectFile ""c:\another very long path\to my visual studio project file\of a \customerprojet.csproj"" -WebPartDefinition ""c:\another very long path\to my visual studio project file\of a\file-in-my-customerproject.xml"" }"
Actually, I defined my external tools to use some tokens :
-command { Add-PSSnapin Microsoft.SharePOint.POwerShell -EA 0; & ""C:\a very long path to my script with spaces\my-script.ps1"" -ProjectFile ""$(ProjectFileName)"" -WebPartDefinition ""$(ItemPath)"" }
However, this command line exceed the 260 chars limits allowed by Windows, and it does not works. It seems the command line is truncated (missing }
at the end of my command.
How can I solve this?
[Edit] Actually, there was an issue with the project file. The token $(ProjectFileName)
does not include the project directory, so I have to put instead:
-command { Add-PSSnapin Microsoft.SharePOint.POwerShell -EA 0; & """C:\a very long path to my script with spaces\my-script.ps1""" -ProjectFile ""$(ProjectFileName)\$(ProjectFileName)"" -WebPartDefinition ""$(ItemPath)"" }
I also have to "triple" the quotes around the ps1 path (not understanding why though)
But this does not works. The argument is too long and visual studio forbid me to put this value.
[Edit2] To be sure of the syntax, here is how I call the script successfully from the command line :
powershell -command "& { Add-PSSnapin Microsoft.SharePOint.POwerShell -EA 0; & """C:\path-to\myscript.ps1""" -ProjectFile """C:\Projects\someproject\someproject.csproj""" -WebPartDefinition """C:\Projects\someproject\somefolder\somefile.xml""" -Verbose }"
Which can be tokenized as :
powershell -command "& { Add-PSSnapin Microsoft.SharePOint.POwerShell -EA 0; & """C:\path-to\myscript.ps1""" -ProjectFile """$(ProjectFileName)\$(ProjectFileName)""" -WebPartDefinition """$(ItemPath)""" -Verbose }"
But the command line is still too long with the real paths :(