.NETのWindowsアプリケーションのセットアップファイルを作成するには?

この記事では、など、MS Accessデータベース、アンインストールオプションを使用して設定ファイルを作成する方法について、私ははっきりとスクリーンショットで、この記事で説明した各ステップを説明しました。すべての最後のステップアンインストールオプションへの最初のステップは、(Windowsアプリケーションを作成します)この記事で覆われています。

説明は、

Windowsアプリケーションを作成し

、我々は1つのWindowsアプリケーションを作成する必要がありまず。その後、我々は、そのアプリケーション用のファイルを設定作成します。
選択 ファイル- >新規- >プロジェクト Visual Studioの標準ツールバーインチ


お使いのWindowsアプリケーションの名前を付け
画像2


、デザイン側
、私は1つのテキストボックスと1つのDataGridViewで自分のフォームをデザインする必要があり、このようになり
画像3


、私はMS Accessデータベースからデータをバインドしている。このデータグリッドビューで。そして、私は名前に基づいて検索レコードのそのテキストボックスを使用します。

 

サーバー側では
、私は、クラス内の変数と接続の詳細を宣言しています


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Configuration;
using System.Diagnostics;

namespace WindowsSetup
{
public partial class Form1 : Form
{
//You can place your database "Data-directory/Databasefile" under your project bin/Debug folder
static string s=Application.StartupPath + "\\Data\\test.mdb";
static string constr="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + s + ";";

OleDbConnection con=new OleDbConnection(constr);
OleDbCommand cmd=new OleDbCommand();
OleDbDataAdapter da=new OleDbDataAdapter();
DataTable dt=new DataTable();


If you want uninstall option for your set up file then write code to get Command Line argument like below. 


public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
//Below code is used to uninstall application

//Get Command Line Arguments
string[] arguments = Environment.GetCommandLineArgs();
foreach (string argument in arguments)
{
if (argument.Split('=')[0].ToLower() == "/u")
{
string guid = argument.Split('=')[1];
string path = Environment.GetFolderPath(Environment.SpecialFolder.System);
ProcessStartInfo si = new ProcessStartInfo(path + "\\msiexec.exe", "/i " + guid);
Process.Start(si);
Close();
Application.Exit();
System.Environment.Exit(0);
}
}

//Load DataGridView first time when form load
refreshGrid();
}

void refreshGrid()
{
string query;
con.Open();
if(textBox1.Text=="")
{
query="select eno,empname,sal from emp";
}
else
{
query = "Select eno,empname,sal from emp where empname like '%" + textBox1.Text + "%'";
}
cmd=new OleDbCommand(query,con);
da = new OleDbDataAdapter(cmd);
dt.Clear();
da.Fill(dt);
dataGridView1.DataSource = dt;
con.Close();
}

private void textBox1_TextChanged(object sender, EventArgs e)
{
//Refresh grid values when each text entered in textbox by user.
refreshGrid();
}
}


That's all we done create one windows application. Compile this application and run it. Output look like below.

出力

 

How to create setup file for .Net Application?

Now we can create set up file for this application with MS Access database.
Go to File - > Add-> New project in the Existing opened Project Visual Studio screen.
image4


Then Select "Setup and Deployment" and right side select "Set up Project" (under visual studio installed templates) in the dialogue box. Give the name for your set up file.
image5


After enter name click Ok button. Screen look like below. Check it that set up file added in your solution explorer (right side)
image6


Now right click on the application folder select Add->Project Output.
image7


After select New pop up appear in that window select "Primary Ouput" Click Ok.
image8


How add MS Access database to the Set up file?

I have placed access database in my application "Data" directory so I need to create directory for same like this in application folder. Right Click of the application folder and choose Add - > New folder and name it for that folder "Data"
image9


Double click that "Data" folder in the application folder to open, now right click and choose Add->File 
image10


After select new dialogue box is appear and ask for your database location. Select your database path and click ok in that dialogue box. After added it check your database attached in Application folder look like this.
image11


How to add Desktop Shortcut in setup file?

Select Application folder in File System and right click of the Primary Output file to create short cut for that file.
image12


Rename of that shortcut and cut that shortcut file 
image13


After cut that shortcut go to File System (left side) user's desktop, double click that folder and open it and paste that shortcut
image14


If you want change the icon of short cut then select that short cut right click -> choose properties window. In that property window choose icon option to set icon for your desktop shortcut. Make sure if you want add icon in the short cut then you must add that icon in the application folder before.

How to create Shortcut in Programs menu during set up creation?

Select Application folder in File System and right click of the Primary Output file to create short cut
image12


Rename that shortcut same like above steps and Create one new folder in user's Program menu and paste that shortcut under that folder.
image15


How to create uninstall Shortcut in Programs menu?

Select Application folder in File System and right click of the Primary Output file to create short cut
image12


Rename that shortcut to "uninstall" same like above steps and Paste that shortcut under user's programs menu like this
image16


Select that uninstall short cut right click choose Properties.
image17


In that property window give Arguments value /u=[ProductCode]
.
image18


Now select set up file in solution explorer and build it
image19


名前:この例では、私はプロジェクト「\ WindowsSetup D」を作成しています。だから今、私は私のプロジェクトの場所に移動し 、「D:\ WindowsSetup」 ファイルフォルダを設定する 「Windows_Setup」は 、そのプロジェクトのフォルダと設定ファイルで提供され、このパスに提供されています :「\ WindowsSetup \ Windows_Setup \デバッグD」 フォルダ。
image20


ただ、私は自分のシステムにインストールするには、その設定ファイルをダブルクリックします。インストール後にそのアプリケーションのショートカットをデスクトップとプログラムのファイルメニューに自動的に作成されます。


デスクトップショートカット
image21


のアンインストールオプションを使用してプログラムメニューのショートカット
image22

ます。https://www.cnblogs.com/Jenny90/p/3339870.htmlで再現

おすすめ

転載: blog.csdn.net/weixin_34315189/article/details/93566832