Я хочу использовать IDE-код Visual Studio ("VSC") для разработки на MQL (а не в собственной среде MetaEditor), как описано здесь: Как кодировать и компилировать MQL5 в Visual Studio .
Мой вопрос относится к процессу компиляции, который состоит из VSC-задачи, которая вызывает скрипт PowerShell, который, в свою очередь, вызывает MetaEditor.exe и динамически передает ему текущий .mq5-файл.быть скомпилированным (именно поэтому используется задача).
Все работает нормально, когда я запускаю скрипт PowerShell напрямую (выбирая его код и нажимая F8 ), но когда я пытаюсь запуститьчерез назначенную VSC-задачу я получаю сообщение об ошибке ...
Терминальный процесс завершается с кодом выхода: 1
... даже если я выбрал PowerShell в качествеоболочка по умолчанию, которая будет использоваться VSC (вместо cmd, это мой соответствующий параметр: "Terminal.integrated.shell.windows": "C: \ Windows \ System32 \ WindowsPowerShell \ v1.0 \ powershell.exe").
Это VSC-задача в .json-формат, версия 2.0.0 , о котором я говорю:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Compile-MQL",
"type": "shell",
"command": "C:\\Users\\Username\\AppData\\Roaming\\MetaQuotes\\Terminal\\D0E8209F77C8CF37AD8BF550E51FF075\\MQL5\\Compile-MQL.ps1 ${file}",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": false
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Может кто-нибудь адаптировать мою вышеуказанную задачу VSC , чтобы она работала изкоробка ?
@ postanote: пожалуйста, НЕ копируйте и не вставляйте здесь ответ на подобные вопросы снова, поскольку я, к сожалению, не могу перевести версию 0.1.0 на 2.0.0 (или любые другие отклонения), я 'Я уверен, что есть кто-то, кто может быстро адаптировать мои несколько строк кода, чтобы они сразу работали ...
Большое спасибо заранее!
PS: это вышесценарий PowerShell (который работает с F8 ):
#gets the File To Compile as an external parameter... Defaults to a Test file...
Param($FileToCompile = "C:\Users\Username\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Experts\Advisors\ExpertMACD.mq5")
#cleans the terminal screen and sets the log file name...
Clear-Host
$LogFile = $FileToCompile + ".log"
& "C:\Users\Username\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\compile.bat" "C:\Program Files\MetaTrader 5\metaeditor64.exe" "$FileToCompile" "$LogFile" "C:\Users\Username\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5"
#before continue check if the Compile File has any spaces in it...
if ($FileToCompile.Contains(" ")) {
"";"";
Write-Host "ERROR! Impossible to Compile! Your Filename or Path contains SPACES!" -ForegroundColor Red;
"";
Write-Host $FileToCompile -ForegroundColor Red;
"";"";
return;
}
#first of all, kill MT Terminal (if running)... otherwise it will not see the new compiled version of the code...
Get-Process -Name terminal64 -ErrorAction SilentlyContinue |
Where-Object {$_.Id -gt 0} |
Stop-Process
#fires up the Metaeditor compiler...
& "C:\Program Files\MetaTrader 5\metaeditor64.exe" /compile:"$FileToCompile" /log:"$LogFile" /inc:"C:\Users\Username\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5" | Out-Null
#get some clean real state and tells the user what is being compiled (just the file name, no path)...
"";"";"";"";""
$JustTheFileName = Split-Path $FileToCompile -Leaf
Write-Host "Compiling........: $JustTheFileName"
""
#reads the log file. Eliminates the blank lines. Skip the first line because it is useless.
$Log = Get-Content -Path $LogFile |
Where-Object {$_ -ne ""} |
Select-Object -Skip 1
#Green color for successful Compilation. Otherwise (error/warning), Red!
$WhichColor = "Red"
$Log | ForEach-Object {
if ($_.Contains("0 error(s), 0 warning(s)")) {
$WhichColor="Green"
}
}
#runs through all the log lines...
$Log | ForEach-Object {
#ignores the ": information: error generating code" line when ME was successful
if (-not $_.Contains("information:")) {
#common log line... just print it...
Write-Host $_ -ForegroundColor $WhichColor
}
}
#get the MT Terminal back if all went well...
if ($WhichColor -eq "Green") {
& "c:\program files\metatrader 5\terminal64.exe"
}
PS2: IDE MetaEditor можно бесплатно установить вместе с MetaTrader 5 здесь .