.net core console application deployed with ClickOnce: how do I make it useable as a command-line app?

Viewed 475

I notice that it's possible to publish a .net core 5 console application with ClickOnce using Visual Studio.

TLDR; The whole point of a console application is to be able to invoke it on the commandline with command options/args entered by the user. The fact that ClickOnce allows me to publish a console application leads me to believe this is possible, but ClickOnce seems to work against this use-case by obscuring the actual path of the exe. How do I work around this?


Details

I can use ClickOnce to deploy a Console App and it works, but application is only findable from the Windows Start Menu. The application can't (easily?) be invoked from the commandline because its location is not in the user's path environment variable. As you may know, clickonce puts a shortcut to the executable in the Start Menu...

C:\users\<user>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\<ConsoleApp>.appref-ms

Where the <ConsoleApp>.appref-ms is an application reference that points back to the installer's UNC filepath. If I understand correctly, clickonce does install the application on the user's machine, but obscures location/filepath of the actual executable. You're basically forced to use the application reference to launch ClickOnce Applications.

This is fine for wpf applications because those are launched from the Start Menu. But what about console applications?

The console application I am writing requires options/arguments supplied by the user. If it's just in the start menu, it will get launched and run without any options/args. Moreover, it gets launched in a NEW console window. This makes the console app (when deployed in this way) useless as just another command that's available for user to execute when they're in powershell doing other stuff.

Questions

  • Is there a low friction way to deploy a console application using ClickOnce, and have its filepath added to the user's PATH env variable during install and also have it run without launching a new console window?
  • Is ClickOnce the wrong tool for commandline app deployment? If not, what is the right tool?
  • What's the point of a Console app that is only launchable from the Start-menu and can't have args/options?
1 Answers

I have done this on .Net Framework application

Please note the following important points:

  1. You need to detect whether the running application is network deployed
  2. The Click once application will not take space character as argument separator
  3. You need to define Argument separate character in my case i used comma
static void
 Main(string[] args)
{
    if (ApplicationDeployment.IsNetworkDeployed)
    {
        var inputArgs = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData;
        if (inputArgs != null && inputArgs.Length > 0)
        {
            args = inputArgs[0].Split(new char[] { ',' });
        }
    }
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new MainForm(args)); // Here you pass the argument to the application

}

on the windows command prompt you are can call the application

myapp.appref-ms argument1,argument2,argument3

Related