I have seen Set environment variable for ClickOnce Application? but my question is slightly different.
I work on a C# ClickOnce application, that uses public string myvar_env = Environment.GetEnvironmentVariable("MYVAR"); if (myvar_env == "skip_stage_01") .... When the application is "published", I get a setup.exe which I can run as an installer - and ultimately, it ends by placing MyApp.appref-ms shortcut on the desktop.
If browsed in Windows 10 via right-click/Properties, this shortcut does not contain the actual path to the .exe; otherwise ClickOnce .appref-ms more than a link to .application file? notes:
If you open the appref-ms file in a text editor you'll see it contains the Url for the application, culture, processor architecture and key used to sign the application, so yes, it's just a link.
The difference between those "Application Reference" files and shortcuts (.lnk) is that the application reference points to the original application Url and not the location of the exe on disk, when you run the appref-ms file the system knows how to find the copy of the program on the local disk and run it from there without accessing the Url (this is not accurate and depends on settings in the ClickOnce manifest, but its a close approximation).
Right, so I can search and eventually find the actual MyApp.exe; if I open cmd.exe at the folder location of MyApp.exe, then I can do this in there:
set MYVAR="skip_stage_01"
.\MyApp.exe
... and MyApp.exe starts fine, and takes the environment variable into account.
My question is: is this (addition of environment variable) somehow possible to do, but from the shortcut, that is the .appref-ms file? In other words, can I open the .appref-ms file as a text file, and add some sort of an invocation there equivalent to cmd.exe/batch "set MYVAR="skip_stage_01"", so then when I double-click the shortcut, the application starts and sees this environment variable as being set to the given value?