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.