-
-
Notifications
You must be signed in to change notification settings - Fork 735
Passing Command Line arguments to .exe generated after build #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
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]". |
Ensures backward compatibility
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? |
Implemented! Available in Electron.NET version 7.30.2. You can start the app with:
or
With the Electron.NET API you can get the value:
|
Thank you! |
* manifest, aspCoreProjectPath parameter support added to Init, Start, Build commands ElectronNET/Electron.NET#340 Commandline support ElectronNET/Electron.NET#337 * Microsoft.NET.Test.Sdk update
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 |
Hello, this works very well, however, I need to access a Filepath when a file is dropped on the app.exe to open it. |
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 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>None</string>
<key>CFBundleUrlIconFile</key>
<string>Contents/Resouces/MyApp.icns</string>
<key>CFBundleUrlName</key>
<string>com.myapp.app</string>
<key>CFBundleUrlSchemes</key>
<array>
<string>myappscheme</string>
</array>
</dict>
</array>
<key>NSPrincipalClass</key>
<string>AtomApplication</string>
</dict>
</plist> electron.manifest.json {
"build": {
"protocols": [
{
"name": "myapp",
"role": "Viewer",
"schemes": [ "myappscheme"]
}
]
},
"mac": {
"appBundleId": "com.myapp.app",
"appCategoryType": "app-category-type=public.app-category.developer-tools",
"extendedInfo": "info.plist"
}
}
csharp code app.On("open-url", o => {
// myappscheme://the/rest/of/the/url
var url = o.ToString();
// Do logic here to parse the url for intended results
}); In Windows/Linux app.On("second-instance", o => {
var args = ((JToken)o).ToObject(typeof(List<string>)) as List<string>;
var url = args.FirstOrDefault(i => i.StartsWith("myappscheme://");
if (string.IsNullOrWhitespace(url) == false) {
// Do logic here to parse the url for intended results
}
}); 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 ; Register the extension with your app, look up RegisterExtension in NSIS documentation
${RegisterExtension} "$INSTDIR\MyApplication.exe" ".ext" "NAME_FOR_EXTENSION"
csharp code app.On("second-instance", o => {
var args = ((JToken)o).ToObject(typeof(List<string>)) as List<string>;
var path = args
.SkipWhile(a => !a.Equals("--allow-file-access-from-files"))
.Skip(1).FirstOrDefault();
if (string.IsNullOrWhiteSpace(path) == false) {
// do something with the path
}
});
In Mac csharp app.On("open-file", async o =>
{
var path = o.ToString();
// Do something with the path
});
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. |
Thank you very much! |
The " myapp.exe /args --dog=woof --test=true" desn't work for me. I'm getting: |
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
The text was updated successfully, but these errors were encountered: