Get current ClickOnce app publisher name?

Is it possible to read the publisher name of the currently running ClickOnce application (the one you installed in Project Properties -> Publish -> Options -> Publisher name in Visual Studio)?

The reason I need this is to start another instance of the current application described in this article and pass parameters to it.

Of course, I know the name of my application publisher, but if I hardcode it, and later I decided to change the name of my publisher, I will most likely forget to update this piece of code.

+7
source share
3 answers

You would think that it would be trivial, but I do not see anything in this structure that gives you this information.

If you want to hack, you can get the publisher from the registry.

Disclaimer - The code is ugly and untested ...

  ... var publisher = GetPublisher("My App Name"); ... public static string GetPublisher(string application) { using (var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall")) { var appKey = key.GetSubKeyNames().FirstOrDefault(x => GetValue(key, x, "DisplayName") == application); if (appKey == null) { return null; } return GetValue(key, appKey, "Publisher"); } } private static string GetValue(RegistryKey key, string app, string value) { using (var subKey = key.OpenSubKey(app)) { if (!subKey.GetValueNames().Contains(value)) { return null; } return subKey.GetValue(value).ToString(); } } 

If you find the best solution, consult with him.

+1
source

Here is another option. Please note that it will only get the publisher name for the current application, which is all I need.

I'm not sure if this is the safest way to parse XML.

 public static string GetPublisher() { XDocument xDocument; using (MemoryStream memoryStream = new MemoryStream(AppDomain.CurrentDomain.ActivationContext.DeploymentManifestBytes)) using (XmlTextReader xmlTextReader = new XmlTextReader(memoryStream)) { xDocument = XDocument.Load(xmlTextReader); } var description = xDocument.Root.Elements().Where(e => e.Name.LocalName == "description").First(); var publisher = description.Attributes().Where(a => a.Name.LocalName == "publisher").First(); return publisher.Value; } 
+4
source

I do not know about ClickOnce, but as a rule, you can read assembly information using the System.Reflection framework:

 public string AssemblyCompany { get { object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false); if (attributes.Length == 0) { return ""; } return ((AssemblyCompanyAttribute)attributes[0]).Company; } } 

Unfortunately, theres no โ€œpublisherโ€ attribute, just throwing it away as a possible workflow

0
source

All Articles