Powershell script in Visual Studio 2010 Post-Build Step

I have a powershell script that works fine from the powershell shell and from the cmd window, and now I'm trying to start it from the post-build phase in Visual Studio.

After several different options for trying to achieve this for lunch and a successful launch, I currently have the following configuration for the Command Line property in the Post-Build Event in VS2010.

This is all on one line in the Post-Build setup, but I wrapped the text here just for readability:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -File "$(SolutionDir)testScript.ps1" -ConfigurationFile "$(SolutionDir)configuration.txt" -SolutionDir "$(SolutionDir)" -Platform "$(Platform)" -Configuration "$(Configuration)" 

The power part of the script expects 4 required parameters: ConfigurationFile, SolutionDir, Platform and Configuration. As you can see, I provide each of these parameters above, and enclose them in double quotation marks to protect against spaces in the values.

In VS2010, the SolutionDir macro expands to a path with spaces, the platform expands to Release, and the Configuration expands to Win32.

When the step after the build is executed, this is the error I get:

 testScript.ps1 : Cannot process command because of one or more missing mandatory parameters: Platform Configuration. + CategoryInfo : InvalidArgument: (:) [testScript.ps1], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingMandatoryParameter,testScript.ps1 

... any ideas that I could lose? Apparently, it can find the script in $ (SolutionDir), but I can’t determine if it will accept any command line arguments. Could the trailing "\" character in $ (SolutionDir) suspend this?

+4
source share
1 answer

The $(SolutionDir) variable since this directory ends with a backslash '\'. So, when the variable expands, the argument for -SolutionDir "$(SolutionDir)" as follows:

 -SolutionDir "c:\Your Solution Dir\" 

when this is parsed, the final slash actually eludes the final quote, and the shell parser does not see the end of the argument, so the -SolutionDir parameter β€œdraws” the remaining arguments into the SolutionDir argument. You can fix this by breaking the final backslash with another by adding a trailing slash:

-SolutionDir "$ (SolutionDir) \"

+13
source

Source: https://habr.com/ru/post/1437708/


All Articles