使用vs2010为C#应用程序创建安装 [英] create an install using vs2010 for c# applications

查看:144
本文介绍了使用vs2010为C#应用程序创建安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于使用SQL EXpress mdfs的某些c#应用程序,我需要帮助使用vs2010创建安装(最好是创建MSI).我已经尝试了一次单击,但是这不能满足我的需要.我需要安装的SQL Express mdfs必须放置在"C:\ Program Files \''Company""目录或另一个静态目录中,因此应用可以读取和写入这些mdf.这些应用程序也可以位于该目录中,也可以位于子目录中.我有多个共享相同mdfs的小型应用程序,因此应将它们安装在同一目录或子目录中.

如果可用,此安装应在XP,Vista,Win7和Win8中安装相同的文件夹.

我需要使用VS2010 Ultimate中提供的工具来执行此操作.我可以使用任何免费的工具,并且可以获得帮助.

该安装适用于小型办公室中的独立PC.

请帮忙.

I need help to create an install (preferably creating a MSI) using vs2010 for some c# applications that use SQL EXpress mdfs. I have tried the click once, but that does not meet my needs.The SQL Express mdfs that I need installed must be placed in the "C:\Program Files\''Company''" directory, or another static directory, so the apps can read and write to these mdfs. The applications can be there as well, or in a sub-directory. I have multiple small apps that share the same mdfs, so they should be installed either in the same directory or in a sub-directory.

This install should install the same folders in XP, Vista, Win7 and Win8 when it is available.

I need to do this using the provided tools in VS2010 Ultimate. I can use any tool if it is free and I can get help.

The install is for stand alone PCs in small offices.

Please help.

推荐答案

我编写了一个具有类似问题的ClickOnce应用程序.我克服了这些问题,甚至想出了一旦为软件付款后如何通过电子邮件发送激活密钥.

通过让您的应用使用Windows注册表,您可以测试一下这是否是首次运行.

I wrote a ClickOnce Application with similar problems. I overcame those problems and even figured out how to email an activation key once the software was paid for.

By having your App use the windows registry you can test to see if this is the first time the App is being run.

void OnFirstRun()
{
   // get directory of datafiles downloaded with the App, this is 
   // an unusual and very long ClickOnce path.
   String StartupPath = System.Windows.Forms.Application.StartupPath;
   String OrigMktDataPath = Path.Combine(StartupPath, "MktData");

   // get destination path
   String localAppData = Environment.GetFolderPath   
                         (Environment.SpecialFolder.LocalApplicationData);

   String DestPath = Path.Combine(localAppData, @"YourCompanyName\YourAppName\");
   DirectoryInfo diSource = new DirectoryInfo(OrigMktDataPath);
   DirectoryInfo diDest = new DirectoryInfo(DestPath);
   try
   {
    if (diSource.Exists)
    {

     if (!diDest.Exists)
     {
      Directory.CreateDirectory(destPath);
     }
     bool OverWrite = false;
     CopyDir(OrigMktDataPath, DestPath, OverWrite);
    }
   }
   catch (Exception ex)
   {
    regWrap.WriteLogException(ex);
    regWrap.FlushFileStream();
   }
}

private void CopyDir(String PathSrc, String PathDest, bool OverWrite)
{
 DirectoryInfo diSource = new DirectoryInfo(PathSrc);
 FileInfo[] files = diSource.GetFiles();
 String DestFFN;

 foreach (FileInfo fi in files)
 {
  DestFFN = PathDest + fi.Name;

  if (!File.Exists(DestFFN) || OverWrite)
  {
   fi.CopyTo(DestFFN, true);
   File.SetAttributes(DestFFN, FileAttributes.Normal);
  }
 }
}


如果ClickOnce不适用于您,并且您想使用Visual Studio 2010,则需要研究安装项目.

此处 [此处 [
If ClickOnce will not work for you and you want to use Visual Studio 2010, then you need to research a setup project.

Here[^] is an MSDN article about creating one.

Here[^] is a google search that may help you find more information.

Use these to start working on your project, then when you get stuck with a more specific question come back here and post your question.

Hope this helps.


这篇关于使用vs2010为C#应用程序创建安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆