I'm trying to get the exit code of my wpf application called in a Powershell script.
My main in WPF :
[STAThread]
public static int Main(string[] args)
{
    if (args != null && args.Length > 0)
    {
        NB_ERRORS = AutomaticTests.Program.Main(args);
        return NB_ERRORS;
        //Application.Current.Shutdown(NB_ERRORS);
    }
    else
    {
        App app = new App();
        app.Run(new MainWindow());
        //Application.Current.Shutdown(NB_ERRORS);
        return NB_ERRORS;
    }
}
And in powershell I call it like this :
& $PathToExeTests 0 $LogTestsStagging
$nbFailed = $LASTEXITCODE
But it always contains 0.
I've tried to manually set the Environment.ExitCode, to shutdown the application with the code, to override OnExit like this :
protected override void OnExit(ExitEventArgs e)
{
    e.ApplicationExitCode = AutomaticTests.GUI.Program.NB_ERRORS;
    base.OnExit(e);
}
But I always have 0 in the LastExitCode.