C# 更新程序设置

C# 更新程序设置,c#,installation,C#,Installation,我没有制作安装程序的经验,但我已经准备好了,但现在我需要帮助,因为当我制作一个新版本时,我希望用户双击快捷方式,如果有,它会进行更新 应用程序位于c#中 你能帮忙吗?以下是我如何实现我之前编写的更新程序 首先,从服务器上获取一个ini文件。此文件将包含有关最新版本以及安装文件所在位置的信息。获取那个文件并不难 WebClient wc = new WebClient(); wc.DownloadFile(UrlOfIniContai

我没有制作安装程序的经验,但我已经准备好了,但现在我需要帮助,因为当我制作一个新版本时,我希望用户双击快捷方式,如果有,它会进行更新

应用程序位于
c#


你能帮忙吗?

以下是我如何实现我之前编写的更新程序

首先,从服务器上获取一个ini文件。此文件将包含有关最新版本以及安装文件所在位置的信息。获取那个文件并不难

                WebClient wc = new WebClient();
                wc.DownloadFile(UrlOfIniContainingLatestVersion, PlacetoSaveIniFile);
我还设置了从本地ini文件读取信息以确定最新版本。更好的方法是直接读取文件版本,但我手头没有这样做的代码

接下来,我们做一个非常简单的检查,看看这两个版本如何比较并下载更新

            if (LatestVersion > CurrentVersion)
            {
                //Download update.
            }
下载更新与下载原始ini一样简单。您只需更改这两个参数

wc.DownloadFile(UrlOfLatestSetupFile, PlaceToSaveSetupFile);
现在已经下载了文件,只需运行安装程序即可

System.Diagnostics.Start(PathOfDownloadedSetupFile);

如果您不确定如何读取ini文件,我在CodeProject的某处发现了以下类

using System;
using System.Runtime.InteropServices;
using System.Text;

namespace Ini
{
    /// <summary>
    /// Create a New INI file to store or load data
    /// </summary>
    public class IniFile
    {
        public string path;

        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section,
            string key, string val, string filePath);
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section,
                 string key, string def, StringBuilder retVal,
            int size, string filePath);

        /// <summary>
        /// INIFile Constructor.
        /// </summary>
        /// <PARAM name="INIPath"></PARAM>
        public IniFile(string INIPath)
        {
            path = INIPath;
        }

        /// <summary>
        /// Write Data to the INI File
        /// </summary>
        /// <PARAM name="Section"></PARAM>
        /// Section name
        /// <PARAM name="Key"></PARAM>
        /// Key Name
        /// <PARAM name="Value"></PARAM>
        /// Value Name
        public void IniWriteValue(string Section, string Key, string Value)
        {
            WritePrivateProfileString(Section, Key, Value, this.path);
        }

        /// <summary>
        /// Read Data Value From the Ini File
        /// </summary>
        /// <PARAM name="Section"></PARAM>
        /// <PARAM name="Key"></PARAM>
        /// <PARAM name="Path"></PARAM>
        /// <returns></returns>
        public string IniReadValue(string Section, string Key)
        {
            StringBuilder temp = new StringBuilder(255);
            int i = GetPrivateProfileString(Section, Key, "", temp,
                                            255, this.path);
            return temp.ToString();

        }
    }
}
使用系统;
使用System.Runtime.InteropServices;
使用系统文本;
名称空间Ini
{
/// 
///创建新的INI文件以存储或加载数据
/// 
公共类文件
{
公共字符串路径;
[DllImport(“内核32”)]
私有静态外部long WritePrivateProfileString(字符串部分,
字符串键、字符串值、字符串文件路径);
[DllImport(“内核32”)]
私有静态外部int GetPrivateProfileString(字符串部分,
字符串键、字符串定义、StringBuilder retVal、,
int大小,字符串文件路径);
/// 
///文件构造函数。
/// 
/// 
公共文件(字符串INIPath)
{
路径=路径;
}
/// 
///将数据写入INI文件
/// 
/// 
///节名
/// 
///键名
/// 
///值名称
public void IniWriteValue(字符串部分、字符串键、字符串值)
{
WritePrivateProfileString(节、键、值、this.path);
}
/// 
///从Ini文件中读取数据值
/// 
/// 
/// 
/// 
/// 
公共字符串IniReadValue(字符串部分,字符串键)
{
StringBuilder温度=新StringBuilder(255);
int i=GetPrivateProfileString(节,键“”,临时,
255,此.path);
返回温度ToString();
}
}
}

以下是我如何实现之前编写的更新程序

首先,从服务器上获取一个ini文件。此文件将包含有关最新版本以及安装文件所在位置的信息。获取那个文件并不难

                WebClient wc = new WebClient();
                wc.DownloadFile(UrlOfIniContainingLatestVersion, PlacetoSaveIniFile);
我还设置了从本地ini文件读取信息以确定最新版本。更好的方法是直接读取文件版本,但我手头没有这样做的代码

接下来,我们做一个非常简单的检查,看看这两个版本如何比较并下载更新

            if (LatestVersion > CurrentVersion)
            {
                //Download update.
            }
下载更新与下载原始ini一样简单。您只需更改这两个参数

wc.DownloadFile(UrlOfLatestSetupFile, PlaceToSaveSetupFile);
现在已经下载了文件,只需运行安装程序即可

System.Diagnostics.Start(PathOfDownloadedSetupFile);

如果您不确定如何读取ini文件,我在CodeProject的某处发现了以下类

using System;
using System.Runtime.InteropServices;
using System.Text;

namespace Ini
{
    /// <summary>
    /// Create a New INI file to store or load data
    /// </summary>
    public class IniFile
    {
        public string path;

        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section,
            string key, string val, string filePath);
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section,
                 string key, string def, StringBuilder retVal,
            int size, string filePath);

        /// <summary>
        /// INIFile Constructor.
        /// </summary>
        /// <PARAM name="INIPath"></PARAM>
        public IniFile(string INIPath)
        {
            path = INIPath;
        }

        /// <summary>
        /// Write Data to the INI File
        /// </summary>
        /// <PARAM name="Section"></PARAM>
        /// Section name
        /// <PARAM name="Key"></PARAM>
        /// Key Name
        /// <PARAM name="Value"></PARAM>
        /// Value Name
        public void IniWriteValue(string Section, string Key, string Value)
        {
            WritePrivateProfileString(Section, Key, Value, this.path);
        }

        /// <summary>
        /// Read Data Value From the Ini File
        /// </summary>
        /// <PARAM name="Section"></PARAM>
        /// <PARAM name="Key"></PARAM>
        /// <PARAM name="Path"></PARAM>
        /// <returns></returns>
        public string IniReadValue(string Section, string Key)
        {
            StringBuilder temp = new StringBuilder(255);
            int i = GetPrivateProfileString(Section, Key, "", temp,
                                            255, this.path);
            return temp.ToString();

        }
    }
}
使用系统;
使用System.Runtime.InteropServices;
使用系统文本;
名称空间Ini
{
/// 
///创建新的INI文件以存储或加载数据
/// 
公共类文件
{
公共字符串路径;
[DllImport(“内核32”)]
私有静态外部long WritePrivateProfileString(字符串部分,
字符串键、字符串值、字符串文件路径);
[DllImport(“内核32”)]
私有静态外部int GetPrivateProfileString(字符串部分,
字符串键、字符串定义、StringBuilder retVal、,
int大小,字符串文件路径);
/// 
///文件构造函数。
/// 
/// 
公共文件(字符串INIPath)
{
路径=路径;
}
/// 
///将数据写入INI文件
/// 
/// 
///节名
/// 
///键名
/// 
///值名称
public void IniWriteValue(字符串部分、字符串键、字符串值)
{
WritePrivateProfileString(节、键、值、this.path);
}
/// 
///从Ini文件中读取数据值
/// 
/// 
/// 
/// 
/// 
公共字符串IniReadValue(字符串部分,字符串键)
{
StringBuilder温度=新StringBuilder(255);
int i=GetPrivateProfileString(节,键“”,临时,
255,此.path);
返回温度ToString();
}
}
}

听起来您可能可以使用

听起来您可能可以使用

您是作为MSI安装的吗?您是作为MSI安装的吗?