1

I want to get the path and version number of a ClickOnce application, provided the name of the ClickOnce application.

When I manually searched for it, I found it at the path as follows:

'C:\Users\krishnaim\AppData\Local\Apps\2.0\1HCG3KL0.K41\VO5BM4JR.RPO\head..tion_7446cb71d1187222_0005.0037_37dfcf0728461a82\HeadCount.exe'

But this keeps on changing, and it will become a hard-coded path. Is there another way to get a ClickOnce application (for example, HeadCount.exe which is already installed) path and version number using C#/.NET code?

2 Answers 2

4

It seems a little bizarre, but getting the current directory of the executing assembly is a bit tricky so my code below may be doing more than you think it should, but I assure you it is mitigating some issues where others may attempt to use Assembly.GetExecutingAssembly.Location property.

static public string AssemblyDirectory
{
    get
    {
        //Don't use Assembly.GetExecutingAssembly().Location, instead use the CodeBase property
        string codeBase = Assembly.GetExecutingAssembly().CodeBase;
        UriBuilder uri = new UriBuilder(codeBase);
        string path = Uri.UnescapeDataString(uri.Path);
        return System.IO.Path.GetDirectoryName(path);
    }
}

static public string AssemblyVersion
{
    get
    {
        var asm = Assembly.GetExecutingAssembly();
        //If you want the full four-part version number:
        return asm.GetName().Version.ToString(4);

        //You can reference asm.GetName().Version to get Major, Minor, MajorRevision, MinorRevision
        //components individually and do with them as you please.
    }
}
Sign up to request clarification or add additional context in comments.

6 Comments

Not sure if you got my question correct.Let me give you more info. The scenario here is : We can install the ClickOnce application HeadCount from URL HeadCount by clicking on Install button from HeadCount home page.And we want to automate the scenario where if the client installed in our machine is older(e.g. 5.5) and then clicking on Install button should upgrade the existing Client (to e.g. 5.6) or if tthere is not client installed at all then clicking on install button should do a fresh installation.At the end we have to verify whether the latest client version
The below code works but not without the first line where i am loading the clickonceapp with hardcoded path. 'var assemblyFullName = Assembly.LoadFrom("C:\\Users\\krishnaim\\AppData\\Local\\Apps\\2.0\\1HCG3KL0.K41\\VO5BM4JR.RPO\\head..tion_7446cb71d1187222_0005.0037_37dfcf0728461a82\\HeadCount.exe"); Assembly[] myAssemblies = Thread.GetDomain().GetAssemblies(); Assembly myAssembly = null; for (int i = 0; i < myAssemblies.Length; i++) { MessageBox.Show(myAssemblies[i].FullName.ToString()); }'
See my additional answer below. If you are wanting to update a click-once app, you can do so without having to do it manually. The Click-once deployment framework provides a mechanism to do so.
@gopi - backing up what EdFred said. ClickOnce will automatically download changes and stay on the latest version. That's why people like it. You just need to increment the version number when you publish and make sure the minimum required version is set to the latest version. Then when the user starts the app it will check the server for a newer version and update itself if one exists.
I could able to get the assembly version of the ClickOnce application programmatically using the C#.Net for any other application.Basically i am searching in Apps folder for that.Without opening clickonce application i want to see if the update is availble for it.I explored the ClickOnce API but i didnt find any method which accepts application assembly path reutnrs the update availability.
|
0

In order to do a ClickOnce application update you do not have to do so manually as long as you are using the standard deployment manifests (which I don't know how to ClickOnce unless you do use them).

The MSDN article Choosing a ClickOnce Update Strategy describes the different options for application updates.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.