可以使用下列方法之一:
在您的代碼中添加對 System.Diagnostics.Debugger.Launch
的調用。該方法會打開實時調試,並允許您將新的調試器附加到您的代碼。
在您的代碼中添加對 MessageBox.Show("Debug Me")
的調用。顯示消息框時,使用 Visual Studio 附加到 MessageBox 進程。然後將斷點(對於 Visual C# 項目)或停止點(對於 Visual Basic 項目)放入代碼中。
將調試首選項設置爲啓動 InstallUtil.exe(位於 /winnt/Microsoft.net/Framework/version )並將其作爲參數傳遞給程序集。按 F5 時,命中斷點。InstallUtil.exe 運行自定義操作的方式將和 MSI 一樣。
對於作爲安裝組件的自定義操作(ProjectInstaller 類),“CustomActionData”屬性採用 /name=value 形式。其中的每個名稱都必須是唯一的,並且僅有一個值。多個值之間必須用一個空格隔開:/name1=value1 /name2=value2 。如果值本身有一個空格,則必須在該值兩側加上引號:/name="a value" 。
使用加括號的語法:/name=[PROPERTYNAME] ,可以傳遞 Windows Installer 屬性。對於像“[TARGETDIR]”這樣返回目錄的 Windows Installer 屬性,除了加括號外,還必須加引號和尾部反斜槓:/name="[TARGETDIR]/" 。
注意 |
---|
爲了使自定義操作被視爲安裝組件,必須將“InstallerClass”屬性設置爲“true”。 // Uses System.IO and System.Configuration.Install
|
一).創建部署項目
1. 在“文件”菜單上指向“添加項目”,然後選擇“新建項目”。
2. 在“添加新項目”對話框中,選擇“項目類型”窗格中的“安裝和部署項目”,然後選擇“模板”窗格中的“安裝項目”。在“名稱”框中鍵入 setup1。
1.在打包項目中添加文件msiexec.exe(一般可在c:/windows/system32/下找到)
2.在文件系統視圖中選擇應用程序文件夾,在msiexec.exe上按右鍵,選擇創建快捷方式,重命名快捷方式為"卸載".
3.更改此快捷方式的Arguments 爲"/x {產品id}",產品id的值為打包項目的ProductCode屬性值.
1.先生成安裝包,記下ProductCode(選擇解決方案資源管理器根目錄如setup1,再查看屬性標籤,不是右鍵中的屬性),下面要用到
2.用VS.net建立一個新的控制檯程序uninst.exe文件
'power by: landlordh
'for 2000,xp,2003
Module uninstall
Sub Main()
Dim myProcess As Process = New Process
If System.Environment.OSVersion.ToString.IndexOf("NT 5") Then
myProcess.Start("msiexec", "/X{2B65D4A9-C146-4808-AB4B-321FB0779559}") '改爲自己的ProductCode
End If
myProcess.Close()
End Sub
End Module
3.將控制檯程序BIN目錄的exe文件加入到打包程序文件中,在程序組創建uninst.exe的快捷方式
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;
using System.Reflection;
using System.IO;
using System.Data;
using System.Data.SqlClient;
{
/// <summary>
/// Installer1 的摘要說明。
/// </summary>
[RunInstaller(true)]
public class Installer1 : System.Configuration.Install.Installer
{
/// <summary>
/// 必需的設計器變量。
/// </summary>
private System.ComponentModel.Container components = null;
{
// 該調用是設計器所必需的。
InitializeComponent();
}
/// 清理所有正在使用的資源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region 組件設計器生成的代碼
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
{
// //調用osql執行腳本
//
// System.Diagnostics.Process sqlProcess = new System.Diagnostics.Process();
//
// sqlProcess.StartInfo.FileName = "osql.exe";
//
// sqlProcess.StartInfo.Arguments = String.Format(" -U {0} -P {1} -d {2} -i {3}db.sql", this.Context.Parameters["user"], this.Context.Parameters["pwd"],"master", this.Context.Parameters["targetdir"]);
//
// sqlProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
//
// sqlProcess.Start();
//
// sqlProcess.WaitForExit() ;//等待執行
//
// sqlProcess.Close();
try
{
// Assembly Asm = Assembly.GetExecutingAssembly();
// System.IO.FileInfo FileInfo = new System.IO.FileInfo(Asm.Location);
// string path=FileInfo.DirectoryName+@"/"+Name ;
string path=this.Context.Parameters["targetdir"]+Name;
FileStream fs=new FileStream(path,FileMode.Open,FileAccess.Read,FileShare.Read);
StreamReader reader = new StreamReader(fs,System.Text.Encoding.Default);
//System.Text.Encoding.ASCII;
return reader.ReadToEnd();
catch (Exception ex)
{
Console.Write("In GetSql:"+ex.Message);
throw ex;
}
}
{
SqlConnection sqlConnection1=new SqlConnection();
sqlConnection1.ConnectionString =string.Format("server={0}; user id={1}; password={2}; Database=master",this.Context.Parameters["server"],this.Context.Parameters["user"],this.Context.Parameters["pwd"]);
System.Data.SqlClient.SqlCommand Command = new System.Data.SqlClient.SqlCommand(Sql,sqlConnection1);
try
{
Command.Connection.Open();
Command.Connection.ChangeDatabase(DataBaseName);
Command.ExecuteNonQuery();
}
catch(Exception ex)
{
Console.Write("In exception handler :"+ex.Message);
}
finally
{
Command.Connection.Close();
}
}
protected void AddDBTable(string strDBName)
{
try
{
ExecuteSql("master","CREATE DATABASE "+ strDBName);
ExecuteSql(strDBName,GetSql("sql.txt"));
ExecuteSql("master","exec sp_addlogin 'myoamaster','myoamaster','"+strDBName+"',Null,Null");
ExecuteSql(strDBName,"EXEC sp_grantdbaccess 'myoamaster', 'myoamaster'");
ExecuteSql(strDBName,"exec sp_addrolemember 'db_owner','myoamaster'");
}
catch(Exception ex)
{
Console.Write("In exception handler :"+ex.Message);
}
}
{
base.Install(stateSaver);
AddDBTable(this.Context.Parameters["dbname"]);
}
}
}
{
String str;
SqlConnection myConn = new SqlConnection (strSql);
str = "EXEC sp_attach_db @dbname = '"+ DataName +"', @filename1 = '"+ strMdf +"',@filename2='"+strLdf+"'";
myConn.Open();
myCommand.ExecuteNonQuery();
myConn.Close();
}