What is the right syntax for launching an executable in Appveyor? - appveyor

I'm trying to start the Azure Storage Emulator in an AppVeyor instance but I can't find the right syntax. I've tried this:
- ps: "C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start
and this:
- ps: & "C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start
and this:
- "C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start
All fail with various unhelpful YAML parsing errors.

- cmd: '"C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start'
or simple:
- '"C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start'
or with PowerShell:
- ps: '& "C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start'
Easiest way to avoid YAML parsing errors is to do initial configuration in UI and then press Export YAML. GitHub search for appveyor.yml <something> often brings useful results too.

Related

How to convert powershell exe calls to YAML for git CI/CD

I am having difficulty understanding the syntax of yaml. I want to convert the below power shell commands for restoring nuget packages and building visual studio solution to yaml. I am not able to get it correct, pls help.
PowerShell Commnds:
$ProjectPath = "e:\GitExperiment\SGen"
Set-Location $ProjectPath
$MSBuildPath = "C:\Program Files (x86)\Microsoft VisualStudio\2019\BuildTools\MSBuild\Current\Bin"
$NugetExePath = "C:\Program Files (x86)\NuGet\nuget.exe"
& $NugetExePath restore $ProjectPath\SGen.sln
& $MSBuildPath\MSBuild.exe $ProjectPath\SGen.sln /t:Build /p:Configuration=Release /p:TargetFramework=v4.7.2 /p:SkipPostSharp=True /p:RunCodeAnalysis=False
YAML
stages:
- BUILD
- UNITTEST
- DEPLOY
BUILD_RestoreNugetPackages:
script:
- '$ProjectPath = e:\GitExperiment\SGen"'
- 'Set-Location $ProjectPath'
- '$MSBuildPath = "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild.exe"'
- '$NugetExePath = "C:\Program Files (x86)\NuGet\nuget.exe"'
- '"$NugetExePath restore $ProjectPath\SGen.sln"'
stage: BUILD
tags:
- ci
BUILD_SolutionBuild:
script:
- "& $MSBuildPath $ProjectPath\\SGen.sln /t:Build /p:Configuration=Release /p:TargetFramework=v4.7.2 /p:SkipPostSharp=True /p:RunCodeAnalysis=False"
stage: BUILD
tags:
- ci
I tried using quotes and double quotes and escaping characters in yaml. But couldn't get the commands right.
Please help.
While a gitlab-ci runner does support Powershell, I would rather:
put those commands in a script (versioned with the rest of the sources)
call that script from your YAML directives
powershell -noprofile -noninteractive -executionpolicy Bypass -file my-script.ps1
That way, you don't have to deal with trying to escape any special characters.

Running cmd /c from PowerShell with spaces in filepath

I am trying to run the following command in PowerShell
PS C:\Users\Administrator> cmd /c "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\vsdevcmd.bat && nuget restore && msbuild mywebapp.sln /p:DeployOnBuild=true /p:PublishedProfile=ServerFolderProfile"
This produces the error
'C:\Program' is not recognized as an internal or external command.
My paths have spaces and I'm running several commands seperated by && which is messing everything up. I have tried putting quotes all over the place but I can't get it to work.
If i run just the first part of the command
cmd /c "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\vsdevcmd.bat"
it works fine. But I can't get the other commands to work too.
According to the docs for cmd.exe:
If /C or /K is specified, then the remainder of the command line is processed as an immediate command in the new shell. Multiple commands separated by the command separator & or && are accepted if surrounded by quotes
So I just had to change my command to:
PS C:\Users\Administrator> cmd /c "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\vsdevcmd.bat" "&&" nuget restore "&&" msbuild mywebapp.sln /p:DeployOnBuild=true /p:PublishedProfile=ServerFolderProfile

The term 'xsd' is not recognized as the name of a cmdlet, function, script file, or operable program

When executing the following script (this is a part of the actual script), I'm getting the following error message in powershell:
The term 'xsd' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:10 char:3
$xsds = ls *.xsd | %{ $_.Name }
if ($xsds.Count -eq 0) { exit }
# Add '.\' to last file name, see http://stackoverflow.com/questions/906093/xsd-exe-output-filename
$last = $xsds | select -last 1
$last = '.\' + $last
$xsds[$xsds.Count - 1] = $last
& xsd $xsds /c /n:OutputFolder
Are there some requirements for Powershell that I need to install to be able to run the 'xsd' cmdlet first?
The output of $env:Path:
PS C:\Users\Administrator\Desktop\New> $env:Path
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Mi
crosoft\Web Platform Installer\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files
(x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Micro
soft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program F
iles (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\
PS C:\Users\Administrator\Desktop\New>
An xsd.exe is available in the folders:
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\x64
The paths you have listed are not part of your PATH environment variable. So that leaves you with two options. Add the directories to path or just reference the exe by its full path.
& "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\xsd.exe" $xsds /c /n:OutputFolder
If you want to change your paths you could update them like this
$env:Path += ";C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools"
If you need x64 paths just update the strings.

CSPack and CSRun for running site in azure emulator from powershell

I have spend some time trying to get the cspack and csrun command working to run a website locally in the azure emulator.
So far this is what I get, but its not working
I use psake
Task StartAzureEmulator {
& 'C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\v2.2\bin\cspack' sitename.azure\ServiceDefinition.csdef /out:Sitename.csx /role:sitename;sitename /sites:Vola;Web;Web /copyOnly
& 'C:\Program Files\Microsoft SDKs\Windows Azure\Emulator\csrun' sitename.csx sitename.Azure\ServiceConfiguration.Local.cscfg /useiisexpress /launchbrowser
}
Basically I am not very impressed with how the azure commandline tools works with powershell.
Has anyone got example of this working?
In PowerShell the ; character is a statement separator. You can escape it by preceding it with a backtick or if you are V3 or higher you can user --% to switch PowerShell into a simpler (dumber) parser mode. Try this:
Task StartAzureEmulator {
& 'C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\v2.2\bin\cspack' --% sitename.azure\ServiceDefinition.csdef /out:Sitename.csx /role:sitename;sitename /sites:Vola;Web;Web /copyOnly
& 'C:\Program Files\Microsoft SDKs\Windows Azure\Emulator\csrun' --% sitename.csx sitename.Azure\ServiceConfiguration.Local.cscfg /useiisexpress /launchbrowser
}

Echo %path% on separate lines

Using the Windows command prompt, can I echo %path% and get the resulting paths on separate rows?
Something like this, but for Windows:
echo $PATH | tr ':' '\n'
Can I do this with vanilla cmd or do I need PowerShell or JavaScript scripting?
Example echo %path% output:
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Microsoft SQL Server\90\DTS\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\;
Desired output:
C:\WINDOWS\system32;
C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;
C:\Program Files\Microsoft SQL Server\90\DTS\Binn\;
C:\Program Files\Microsoft SQL Server\90\Tools\binn\;
C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\;
C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\;
Try:
($env:Path).Replace(';',"`n")
or
$env:path.split(";")
Fewer keystrokes using either the split operator or method
$env:Path -split ';'
$env:Path.split(';')
This works for me (in a cmd window):
powershell -Command ($env:Path).split(';')