I have a WPF app built with .Net 6.0 and deployed with ClickOnce as an offline-only application. I set a file association in my manifest file:
<fileAssociation
xmlns="urn:schemas-microsoft-com:clickonce.v1"
extension=".customext"
description="Custom File"
progid="0"
defaultIcon="AppIcon.ico"/>
When i deploy and install the application, the app is working fine and firing up when double-clicking a .customext file.
I need to read the file content, so I subscribed the Startup event in App.xaml:
Startup="Application_Startup"
Then, in App.xaml.cs:
private void Application_Startup(object sender, StartupEventArgs e)
{
MainWindow mainWindow = new();
foreach (string s in e.Args)
{
// Here I need to manage the file content
}
mainWindow.Show();
}
The problem is e.Args is always empty.
What I tried:
- Using
Environment.GetCommandLineArguments()
- Overriding
OnStartup
event in App.xaml.cs
I previously got this working but it was a Net Framework application, so probably there's something different I'm not taking into account.
What am I doing wrong? I googled looking for solutions but most of the answers are Net Framework-realated and use the ActivationArguments class (solution not available in .Net Core).