Windows Develop Bookmark and Share   
 index > ClickOnce and Setup & Deployment Projects > Clickonce and installation files
 

Clickonce and installation files

Hey guys, first time post, so please be gentle
I have done a bit of digging around but have not found the answer to what I'm looking for.

Basically, here is my problem and question.

I have successfully, implemented a test clickonce application using the tutorials i've found online.
I want to implement this into my existing project for deployment on clients site, however, there is one thing that I am unable to work out which is preventing me from doing this.
I have a .config file that is saved on the clients computer during a conventional installation with a normal windows installer, if for some reason, some value were to change in the config file for a new release, I would have to manually go onto each desktop, uninstall the old version and reinstall the new version and then update the config file with some new values or some other data.
Now, my question is, how would i, or can i automate this process with the clickonce auto installer?
For example, what I am thinking is, I will create a new version, put it into a shared folder or a folder on the clients site, when the client PC's open the application and a check is done for a later version, when it has found it, it will then install the newer version (all automated by clickonce) but then it will also update the config file and any other files necessary.

Is this possible? or am i missing something?
Also, the same would go for a database change, obviously, this is a rarity and should never happen, but on the off chance that it does, how would i go about automating it? or would the best way be for me to just manually log onto the database and update it?

Any help or suggestions would be greatly appreciated.

Also, if anyone has any useful links or reading material on clickonce, i'd appreciate it if you put up the links to the resources in the thread.

Thanks for reading.

Pooner  Tuesday, July 14, 2009 8:57 AM

Hi Pooner,

These are my replies to your questions:

1. How to automatically install a windows installer package and update a .config file after that?

Analysis: Actually ClickOnce cannot automatically run an installation when the customer updates a software, it can only update the published files. But we can change our application to do this.

Solution: We need to add the files to our project to make them as the application files. Then change the code of our project to implement the logic of how to install the package and update the configuration file. We also need to add an extra file to our project to indicate whether we need to install the new package. These are the steps:

1) Add the windows installer package and the configuration file to our project.

2) Add an extra file to indicate whether we need to install the package and update the configuration file. We can name this file upd.txt and modify the content to be like this: "Update=fasle".

3) Open the properties of each added file and change the Copy to Output Directory to Copy always.

4) Modify the code in Main function to implement the installation and update logic.
This is a code snippet shows a simple example:

[STAThread]

static void Main()

{

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

//Write code here to handle the installation fo the package and the updating of the configuration file.

//For example.

string updCheckFilePath = "upd.txt";

string txt = File.ReadAllText(updCheckFilePath);

bool isUpdate = Boolean.Parse(txt.Split('=')[1]);

bool showInstallUi = false;//If show the UI of the installation.

if (isUpdate)

{

//Install the package.

string installPackage = "test.msi";

if (showInstallUi)

{

Process.Start(installPackage);

}

else

{

string cmd = "msiexec";

string args = "/i \"{0}\" /qn";

Process.Start(cmd, args);

}

//Update the config file.

string path = "upd.config";

string content = File.ReadAllText(path);

//Update the content of the file here.

txt = "addsfsdfsfsfsd";

File.WriteAllText(path, content);

}

Application.Run(new Form1());

}

5) If the installer package need to update, modify the upd.txt file to enable the update: "Update=true". Then modify the version of the project and republish it.

2. How to update the software when the database changes?

Analysis: If the database changes, we often only need to update the connection string. We can configure the connection by add connection string to the configuration file of the project. When the database changes, we can modify the connection strings and publish the application again.

Solution: These are the steps:
1) Modify the connection strings in the app.config file.

2) Modify other files related to database if needed.

3) Modify the version of our project and republish.

Since ClickOnce would manage the updating process, we only need to update the applications files and republish our application. When a new version can be accessed, the application in customer’s machine would update automatically. These are some links about ClickOnce:
A Sample: http://msdn.microsoft.com/en-us/library/01f4d4fc(VS.80).aspx

The details: http://msdn.microsoft.com/en-us/library/t71a733d.aspx

Let me know if this helps.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Thursday, July 16, 2009 7:03 AM
anyone?
Pooner  Wednesday, July 15, 2009 11:02 AM

Hi Pooner,

These are my replies to your questions:

1. How to automatically install a windows installer package and update a .config file after that?

Analysis: Actually ClickOnce cannot automatically run an installation when the customer updates a software, it can only update the published files. But we can change our application to do this.

Solution: We need to add the files to our project to make them as the application files. Then change the code of our project to implement the logic of how to install the package and update the configuration file. We also need to add an extra file to our project to indicate whether we need to install the new package. These are the steps:

1) Add the windows installer package and the configuration file to our project.

2) Add an extra file to indicate whether we need to install the package and update the configuration file. We can name this file upd.txt and modify the content to be like this: "Update=fasle".

3) Open the properties of each added file and change the Copy to Output Directory to Copy always.

4) Modify the code in Main function to implement the installation and update logic.
This is a code snippet shows a simple example:

[STAThread]

static void Main()

{

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

//Write code here to handle the installation fo the package and the updating of the configuration file.

//For example.

string updCheckFilePath = "upd.txt";

string txt = File.ReadAllText(updCheckFilePath);

bool isUpdate = Boolean.Parse(txt.Split('=')[1]);

bool showInstallUi = false;//If show the UI of the installation.

if (isUpdate)

{

//Install the package.

string installPackage = "test.msi";

if (showInstallUi)

{

Process.Start(installPackage);

}

else

{

string cmd = "msiexec";

string args = "/i \"{0}\" /qn";

Process.Start(cmd, args);

}

//Update the config file.

string path = "upd.config";

string content = File.ReadAllText(path);

//Update the content of the file here.

txt = "addsfsdfsfsfsd";

File.WriteAllText(path, content);

}

Application.Run(new Form1());

}

5) If the installer package need to update, modify the upd.txt file to enable the update: "Update=true". Then modify the version of the project and republish it.

2. How to update the software when the database changes?

Analysis: If the database changes, we often only need to update the connection string. We can configure the connection by add connection string to the configuration file of the project. When the database changes, we can modify the connection strings and publish the application again.

Solution: These are the steps:
1) Modify the connection strings in the app.config file.

2) Modify other files related to database if needed.

3) Modify the version of our project and republish.

Since ClickOnce would manage the updating process, we only need to update the applications files and republish our application. When a new version can be accessed, the application in customer’s machine would update automatically. These are some links about ClickOnce:
A Sample: http://msdn.microsoft.com/en-us/library/01f4d4fc(VS.80).aspx

The details: http://msdn.microsoft.com/en-us/library/t71a733d.aspx

Let me know if this helps.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Thursday, July 16, 2009 7:03 AM

You can use google to search for other answers

Custom Search

More Threads

• Updating version number
• A problem integrating a huge database into ClickOnce
• Using [TARGETDIR] to pass data via CustomActionData into .NET custom action throws error!
• Erratic detection of new versions of ClickOnce App
• have problem with my App.config EXE file ??????
• ClickOnce stop downloading files
• Update an application
• Delete later versions in setup project (msi)
• Installer package
• Attaching an Icon to an application