-
Notifications
You must be signed in to change notification settings - Fork 66
Expose ActivationData to launched .NET app #245
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
Expose ActivationData to launched .NET app #245
Conversation
src/clickonce/launcher/Program.cs
Outdated
|
|
||
| // ClickOnce ActivationData | ||
| string[] activationData = AppDomain.CurrentDomain?.SetupInformation?.ActivationArguments?.ActivationData; | ||
| if (activationData != null && activationData.Count() > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't Length be better here since Count is a computed result?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They should have equivalent value, in this case, so we could use either. I used count to match the env. var. name I'm using - ClickOnce_ActivationData_Count. It does require Linq and is slightly slower - but this array usually has zero or only 1 element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed the change - removing Linq dependency and using Length.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So these environment variables will get inherited all the way through to the application process where the app can choose to read these variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is correct. It is the model we've been using for passing data from Launcher (which is a ClickOnce-activated app and has access to additional data like ApplicationDeployment.CurrentDeployment) to the .NET (Core) app being launched.
|
@NikolaMilosavljevic How do I actually start a .NET app with custom arguments using the Targeting .NET 8, I can still start the app like this from the command-line: But when passing a custom parameter it just silently fails: |
@mgnsm I ran into this today. What I found is you can pass a URL as the parameter but you cannot pass individual arguments. Example: Why it fails when passing normal arguments? You can setup a string registry key under But if you pass a URL as the argument then the error doesn't occur. |
Fixes: #236 and #113
Description
This work enables .NET app, deployed using ClickOnce, to use the activation arguments.
This solves two scenarios:
Launcher reads the
AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationDataarray and sets some environment variables if array is non-empty.New environment variables
ClickOnce_ActivationData_CountIf this variable exists, the value is the count of elements in ActivationData string array.
ClickOnce_ActivationData_<n>For each element in array, new environment variable gets added, with a zero-based index, i.e.:
ClickOnce_ActivationData_0ClickOnce_ActivationData_1...
Note that the scenarios being fixed always use the
0-index element, so the variable will always beClickOnce_ActivationData_0, but the code is flexible and is able to pass all activation data to .NET app.Usage scenario
Developer can read these environment variables to discover ActivationData content, using something like the following:
string value = Environment.GetEnvironmentVariable("ClickOnce_ActivationData_0");Previously, for .NET FX apps, this would have been achieved using the following code:
string value = AppDomain.CurrentDomain?.SetupInformation?.ActivationArguments?.ActivationData?[0];