Visual studio 2008 如何使用Visual Studio 2008部署.dll文件?
我正在用VS2008创建一个安装程序,其中包含一个桌面应用程序和一个BHO插件 它是作为类库项目创建的。Visual studio 2008 如何使用Visual Studio 2008部署.dll文件?,visual-studio-2008,deployment,dll,bho,regasm,Visual Studio 2008,Deployment,Dll,Bho,Regasm,我正在用VS2008创建一个安装程序,其中包含一个桌面应用程序和一个BHO插件 它是作为类库项目创建的。 我可以使用以下命令手动注册myPlugin.dll[regasm/codebase“myPlugin.dll”register],但我不知道如何在安装项目中实现这一点。有什么想法吗?最简单、最安全的方法是创建自己的安装程序类,该类接受要注册的DLL的名称,并用于安装或卸载DLL 创建时,它可以通过自定义操作的CustomActionData属性接受自定义操作中的参数。每个参数都存储在Inst
我可以使用以下命令手动注册myPlugin.dll[regasm/codebase“myPlugin.dll”register],但我不知道如何在安装项目中实现这一点。有什么想法吗?最简单、最安全的方法是创建自己的安装程序类,该类接受要注册的DLL的名称,并用于安装或卸载DLL 创建时,它可以通过自定义操作的CustomActionData属性接受自定义操作中的参数。每个参数都存储在Installer.Context.parameters集合中。这意味着通过使用一些安装程序属性,您可以将完整的安装路径传递给DLL,然后RegistrationServices可以使用该路径执行与Regasm相同的操作 实施这是一个多步骤的过程: 步骤1是创建安装程序类。因为这是可重用的代码,我建议创建一个单独的DLL项目来保存这个类
using System;
using System.Text;
using System.ComponentModel;
using System.Configuration.Install;
using System.Collections;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
[RunInstaller(true)]
public partial class AssemblyRegistrationInstaller : Installer
{
public AssemblyRegistrationInstaller()
{
}
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
RegisterAssembly(true);
}
public override void Rollback(IDictionary savedState)
{
base.Rollback(savedState);
RegisterAssembly(false);
}
public override void Uninstall(IDictionary savedState)
{
base.Rollback(savedState);
RegisterAssembly(false);
}
private void RegisterAssembly(bool fDoRegistration)
{
string sAssemblyFileName = base.Context.Parameters["AssemblyFileName"];
if (string.IsNullOrEmpty(sAssemblyFileName))
{
throw new InstallException("AssemblyFileName must be specified");
}
if (!File.Exists(sAssemblyFileName))
{
if (fDoRegistration)
{
throw new InstallException(string.Format("AssemblyFileName {0} is missing", sAssemblyFileName));
}
else
{
// Just bail if we are uninstalling and the file doesn't exist
return;
}
}
var oServices = new RegistrationServices();
var oAssembly = Assembly.LoadFrom(sAssemblyFileName);
if (fDoRegistration)
{
oServices.RegisterAssembly(oAssembly, AssemblyRegistrationFlags.SetCodeBase);
}
else
{
try
{
oServices.UnregisterAssembly(oAssembly);
}
catch
{
// Just eat the exception so that uninstall succeeds even if there is an error
}
}
}
}
第2步是将新DLL添加到安装项目中。因为我们需要为DLL配置设置,所以不要添加项目本身;直接从项目的发布目录添加DLL
步骤3是将新DLL作为自定义操作添加。为此,右键单击安装项目并选择查看
,然后选择自定义操作
右键单击自定义操作
菜单,并在弹出对话框中选择新的安装程序DLL。这将自动将DLL添加到所有4个部分。右键单击添加到Commit
部分的内容并将其删除
对于其他3个部分,执行以下操作:
右键单击DLL条目并选择属性窗口
确保属性网格中的InstallerClass
条目设置为true(应该设置为true)
将以下条目添加到CustomActionData
属性,以将要注册到自定义安装程序类的dll的名称传递给该类:
/AssemblyFileName="[TARGETDIR]\myplugin.dll"