简体   繁体   中英

Automatically compile a .au3 script via my C# code

I'm trying to compile an.Au3 script code automatically, then then run it. I update the script (au3 file) automatically, but for it to work when I update the script, it must be compiled first (to use the new script). There is no issue running the.exe file, my issue is I can't find code to compile it before I run it. This is how I run my executable:

 Process.Start(@"C:\Users\XX\Documents\visual studio 2017\Projects\TESTING TEXT\TESTING TEXT\bin\Debug\XX.exe");

But before I run my executable, I need to compile the script. Any help?

Take a look at this documentation: https://www.autoitscript.com/autoit3/docs/intro/compiler.htm

You should be able to call the command line utility, Aut2exe.exe , to compile from another application.


The syntax here would be

Aut2exe.exe /in c:\path\to\your\script.au3 /out c:\path\to\save\app.exe /icon c:\path\to\icon.ico /x64

So to execute this from C#, it would be something like

Process.Start('c:\path\to\Aut2exe.exe', '/in c:\path\to\your\script.au3 /out c:\path\to\save\app.exe /icon c:\path\to\icon.ico /x64')

I can propose you another approach. I do the same thing with a Window batch program. It allows to compile AutoIt, prepare a package and generate an installer.

The main step in this Windows batch program are:

  • Assign a version number to the application and configure the scripts wich create package and generate Windows installer.
  • Compile the application via the main entry point myApplication.au3 with theaut2exe compiler;
  • Copy the assets (images, files …) necessary for the proper functioning of the application in the output directory;
  • Create a zip archive to recover the application;
  • And finally build the installer by compiling the associated InnoSetup script.

All steps, to package the application and generate the installer, can be driven from the Windows batch. You can see documentation here: https://autoit-gui-skeleton.github.io//documentation/creating-setup-package-autoit-application

AGS 创建设置工作流程

The AutoIt program is compiled from the command line with the aut2exe binary. Warning, it is necessary that this last one is to inform in the variable of environment PATH of the operating system.

# Set variables
(...)
set AUT2EXE_ARGS=/in "%FOLDER_SRC%\%AUT2EXE_AU3%" /out "%FOLDER_OUT%\%NAME_EXE%" /icon
aut2exe %AUT2EXE_ARGS%
echo Compilation AutoIt is finished.

AGS Windows batch bandmaster

::------------------------------------------------------------------------------
::
::    Copyright © 2018-05
::
::    @name           : AGS-deployment-setup
::    @version        : 1.0.1
::    @AGS package    : AGS v1.0.0
::    @AutoIt version : v3.3.14.5
::    @authors        : 20100 <vb20100bv@gmail.com>
::
::------------------------------------------------------------------------------


cls
@echo off

:: Change value for this variables
set VERSION=0.9.0
set NAME_PROJECT=ApplicationWithCheckForUpdates

:: Deployment variables
set FOLDER_CURRENT=%cd%
set NAME_EXE=%NAME_PROJECT%_v%VERSION%.exe
set FOLDER_SRC=%FOLDER_CURRENT%\..\
cd %FOLDER_SRC%
set FOLDER_SRC=%cd%
set FOLDER_OUT=%FOLDER_CURRENT%\v%VERSION%\%NAME_PROJECT%_v%VERSION%

:: AutoIt compiler
Set AUT2EXE_AU3=ApplicationWithCheckForUpdates.au3
set AUT2EXE_ICON=%FOLDER_SRC%\assets\images\myApplication.ico
set AUT2EXE_ARGS=/in "%FOLDER_SRC%\%AUT2EXE_AU3%" /out "%FOLDER_OUT%\%NAME_EXE%" /icon "%AUT2EXE_ICON%"

:: Path binaries
set ZIP_CLI="C:\Program Files\7-Zip\7z.exe"
set ISCC_CLI="C:\Program Files (x86)\Inno Setup 5\ISCC.exe"
set ISCC_SCRIPT=AGS-deployment-setup.iss


echo.
echo.
echo      [  AGS-deployment-setup  ]
echo.     
echo.


echo ----[ Variables for generation ]----
echo * VERSION        = %VERSION%
echo * NAME_PROJECT   = %NAME_PROJECT%
echo * FOLDER_CURRENT = %FOLDER_CURRENT%
echo * NAME_EXE       = %NAME_EXE%
echo * FOLDER_SRC     = %FOLDER_SRC%
echo * FOLDER_OUT     = %FOLDER_OUT%
echo * AUT2EXE_ICON   = %AUT2EXE_ICON%
echo * AUT2EXE_AU3    = %AUT2EXE_AU3%
echo * AUT2EXE_ARGS   = %AUT2EXE_ARGS%
echo * ZIP_CLI        = %ZIP_CLI%
echo * ISCC_CLI       = %ISCC_CLI%
echo * ISCC_SCRIPT    = %ISCC_SCRIPT%
echo -------------------------------------

echo.
echo.

echo ----[ Step 1/7 - Creating directories ]----
cd %FOLDER_CURRENT%
echo * Attempt to create : "%cd%\v%VERSION%\"
mkdir v%VERSION%
cd v%VERSION%
echo.
echo * Attempt to create : %cd%\%NAME_PROJECT%_v%VERSION%\
mkdir %NAME_PROJECT%_v%VERSION%
cd %FOLDER_CURRENT%
echo -------------------------------------

echo.
echo.


echo ----[ Step 2/7 - Launch AutoIt compilation ]----
echo * Run compilation with aut2exe and AUT2EXE_ARGS.
aut2exe %AUT2EXE_ARGS%
echo * Compilation AutoIt is finished.
echo -------------------------------------

echo.
echo.


echo ----[ Step 3/7 - Copy assets files ]----
echo * Create the file xcopy_EXCLUDE.txt in order to ignore some file and directory.
echo .au3 > xcopy_Exclude.txt
echo /releases/ >> xcopy_Exclude.txt
echo /src/ >> xcopy_Exclude.txt
echo /vendor/ >> xcopy_Exclude.txt
echo *   - ignore all .au3 files
echo *   - ignore all .pspimage files
echo * The file xcopy_EXCLUDE.txt is created.
echo.
echo * Copy additional files store in assets, config, docs directories
xcopy "%FOLDER_SRC%\assets" "%FOLDER_OUT%\assets\" /E /H /Y /EXCLUDE:xcopy_Exclude.txt
xcopy "%FOLDER_SRC%\config" "%FOLDER_OUT%\config\" /E /H /Y /EXCLUDE:xcopy_Exclude.txt
xcopy "%FOLDER_SRC%\docs" "%FOLDER_OUT%\docs\" /E /H /Y /EXCLUDE:xcopy_Exclude.txt
@copy "%FOLDER_SRC%\package.json" "%FOLDER_OUT%\package.json" /Y > log
echo "%FOLDER_SRC%\package.json" is copied.
@copy "%FOLDER_SRC%\README.md" "%FOLDER_OUT%\README.md" /Y > log
echo "%FOLDER_SRC%\README.md" is copied.
echo * Ok all files and directory are copied.
echo.
echo * Delete xcopy_Exclude.txt.
del xcopy_Exclude.txt
del log
echo -------------------------------------

echo.
echo.


echo ----[ Step 4/7 - Create additional files ]----
echo * Create file ".v%VERSION%" in FOLDER_OUT.
cd %FOLDER_OUT%
echo Last compilation of application %NAME_PROJECT% version %VERSION% the %date% at %time% > .v%VERSION%
echo * This file has been created.
echo -------------------------------------

echo.
echo.


echo ----[ Step 5/7 - Create zip archive ]----
echo * Move in the folder %FOLDER_CURRENT%\v%VERSION%
cd %FOLDER_CURRENT%\v%VERSION%
echo * Zip the folder %NAME_PROJECT%_v%VERSION%
%ZIP_CLI% a -tzip %NAME_PROJECT%_v%VERSION%.zip "%NAME_PROJECT%_v%VERSION%
echo * The zip has been created.
echo -------------------------------------

echo.
echo.

echo ----[ Step 6/7 - Make setup with InnoSetup command line compilation ]----
cd %FOLDER_CURRENT%
echo * Launch compilation with iscc
%ISCC_CLI% %ISCC_SCRIPT% /dApplicationVersion=%VERSION% /dApplicationName=%NAME_PROJECT%
echo.
echo * Compilation has been finished.
echo -------------------------------------

echo.
echo.

echo ----[ Step 7/7 - Delete temp folder use for ISS compilation ]----
cd %FOLDER_CURRENT%
echo * Delete the folder %FOLDER_CURRENT%\v%VERSION%\%NAME_PROJECT%_v%VERSION%\
rmdir %FOLDER_CURRENT%\v%VERSION%\%NAME_PROJECT%_v%VERSION% /S /Q
echo -------------------------------------

echo.
echo.

cd %FOLDER_CURRENT%
echo ----[ End process ]----
echo.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM