mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-04 05:34:51 +00:00
Passing Command Line arguments to .exe generated after build #407
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @VH97 on GitHub (Nov 5, 2019).
Originally assigned to: @GregorBiswanger on GitHub.
I have a desktop App.exe built using Electron.Net, if I pass parameters along with "electronize start", these arguments get ignored. In command prompt, when I run App.exe with command line arguments it does not accept the parameters being passed to it.
Example: App.exe hello 123
electronize start hello 123
I tried to make little changes in code to try to achieve the same. I have attached my findings below in Changes file.
It would be great if this feature could be supported in the coming days. Thank you.
Changes.docx
@MrCircuit commented on GitHub (Nov 22, 2019):
The implementation sketch given by @VH97 works except for one case:
For the "electronize start [args]" sequence one has to pay attention to the first parameter. If it denotes a valid path, this parameter will be used by the ExecuteAsync method of StartElectronCommand for the "aspCoreProjectPath". A safer solution would be to extend this part like this:
Otherwise, the parameters of "electronize start" must be escaped e.g. using commands like "--path [coreProjectPath]" and "--args [argument list as string]".
@MrCircuit commented on GitHub (Nov 22, 2019):
I've implemented the latter because it seemed more reliable to me. I kept the case of exactly one parameter that is interpreted as the aspCoreProjectPath for the sake of backward compatibility.
Shall I create a PR?
@GregorBiswanger commented on GitHub (Nov 30, 2019):
Implemented! Available in Electron.NET version 7.30.2.
You can start the app with:
electronize start /args --dog=woof --test=trueor
myapp.exe /args --dog=woof --test=trueWith the Electron.NET API you can get the value:
@VH97 commented on GitHub (Nov 30, 2019):
Thank you!
@MrCircuit commented on GitHub (May 18, 2021):
Just one remark on the feature: The command line arguments are passed in lowercase to the Electron.NET API.
Took me quite some time to find out :-P
@locoruiz commented on GitHub (Feb 11, 2022):
Hello, this works very well, however, I need to access a Filepath when a file is dropped on the app.exe to open it.
Or to open it with the protocol from the browser (like Zoom), is this possible?
@danatcofo commented on GitHub (Feb 11, 2022):
@locoruiz
for url support you need to register a scheme with the os and associate it with the app. This is different for each os in how you do this.
in the code to handle the scheme
In Mac
info.plist
electron.manifest.json
csharp code
In Windows/Linux
Likewise handling files is similar, you must first register the app as a handler for the file type and that is os dependent.
In Windows with NSIS
Nsis install script adddition
csharp code
In Mac
csharp
Now I'm sure I've definitely missed something here in this long winded explanation as there are too many intricacies that I figured out, got set up and working and promptly forgot about but this should get you started.
@locoruiz commented on GitHub (Feb 11, 2022):
Thank you very much!
@Atmosferrum commented on GitHub (Nov 1, 2022):
The " myapp.exe /args --dog=woof --test=true" desn't work for me. I'm getting:
A positional parameter cannot be found that accepts argument '--dog=woof'.
It doesn't matter even if I use my own arguments.