简体   繁体   English

如何使用SQLite数据库为AC#应用程序发布/创建安装程序?

[英]How To Publish/Create Installer For A C# Application With An SQLite Database?

I have a simple WinForms Application written in C# using Visual Studio which includes a SQLite Database.. The Database's Build Action Property is set to “Content” and the Copy To Output Directory is set to “Copy if Newer”. 我有一个使用Visual Studio C#编写的简单WinForms应用程序,其中包括SQLite数据库。.数据库的Build Action属性设置为“ Content”,“ Copy to Output Directory”设置为“ Copy if Newer”。 The application is ready for publishing. 该应用程序已准备好发布。 I'd like to make an installer. 我想做一个安装程序。 What is the best way to go about this? 最好的方法是什么? I anticipate a few problems.. Where should I save the database file? 我预计会有一些问题。我应该在哪里保存数据库文件? If it gets saved into the Program Files Folder, the Database would become Read-Only.. Where should I save it and how should I go about doing so? 如果将其保存到Program Files文件夹中,则数据库将变为只读。.我应该在哪里保存它,应该怎么做?

I will take your question as: "Where to store writable files during installation and use of application?" 我会问您的问题是: “在安装和使用应用程序期间将可写文件存储在哪里?”

There is 2 special places for this: 有两个特殊的地方:

  1. ApplicationData special folder. ApplicationData特殊文件夹。 This folder is accessable by current user and is actually placed in C:\\Users\\\\AppData\\Roaming (Win7). 当前用户可以访问此文件夹,并且该文件夹实际上位于C:\\ Users \\\\ AppData \\ Roaming (Win7)中。 This path is stored in %APPDATA% environment variable and can be used like this: 此路径存储在%APPDATA%环境变量中,可以这样使用:

     Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)); 

    You may safely store your files in following folder structure there: %APPDATA%\\YourCompanyName\\YourAppName\\ . 您可以将文件安全地存储在以下文件夹结构中: %APPDATA%\\YourCompanyName\\YourAppName\\

  2. CommonApplicationData special folder. CommonApplicationData特殊文件夹。 Almost the same as above, except it is accessable by all users and is actually placed in __ (Win7). 除了几乎所有用户可以访问并且实际上放置在__(Win7)中之外,其余与上面几乎相同。 This path is stored in %ALLUSERSPROFILE% environment variable and can be used like this: 此路径存储在%ALLUSERSPROFILE%环境变量中,可以这样使用:

     Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)); 

    As before, you may safely store your files in following folder structure there: %ALLUSERSPROFILE%\\YourCompanyName\\YourAppName\\ . 和以前一样,您可以安全地将文件存储在以下文件夹结构中: %ALLUSERSPROFILE%\\YourCompanyName\\YourAppName\\

As for your case, here how you can get a db filepath: 对于您的情况,在这里如何获取db文件路径:

var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
var dbPath = Path.Combine(appDataPath, "YourCompanyName\YourAppName", "your_db_name.sqlite3");

Real difference is: does this database are common for all windows users, or each user should have his own database. 真正的区别是:此数据库是否对所有 Windows用户都通用,还是每个用户都应该有自己的数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM