我的解决方案有 3 个项目,其中一个用于 CustomInstaller 项目、一个用于我的 WPF 应用程序和我的安装程序安装程序的项目。
构建我的安装程序并运行它后,在过程中我确实收到错误消息:
错误 1001。无法获取 C:\Miopro\MS4\Miopro.Setup.Preventions.dll 程序集中的安装程序类型。 --> 无法加载一种或多种请求的类型。检索 LoaderExceptions 属性以获取更多信息。
这是我的 Visual Studio 2022 解决方案:
环境:
文件系统
自定义安装程序类
using System;
using System.ComponentModel;
using System.Configuration.Install;
using System.Diagnostics;
using System.IO;
namespace Miopro.Setup.Prerequisites
{
[RunInstaller(true)]
public class CustomInstaller : Installer
{
public CustomInstaller() : base()
{
this.Committed += new InstallEventHandler(CustomInstaller_Committed);
this.Committing += new InstallEventHandler(CustomInstaller_Committing);
}
public static void Main()
{
WriteToEventLog("Install");
}
/// <summary>
/// Event handler for 'Committing' event.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CustomInstaller_Committing(object sender, InstallEventArgs e)
{
WriteToEventLog("Committing Event occurred.");
}
/// <summary>
/// Event handler for 'Committed' event.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CustomInstaller_Committed(object sender, InstallEventArgs e)
{
WriteToEventLog("Committed Event occurred.");
}
public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
}
/// <summary>
///
/// </summary>
/// <param name="savedState"></param>
public override void Commit(System.Collections.IDictionary savedState)
{
base.Commit(savedState);
}
/// <summary>
///
/// </summary>
/// <param name="savedState"></param>
public override void Rollback(System.Collections.IDictionary savedState)
{
base.Rollback(savedState);
}
/// <summary>
///
/// </summary>
/// <param name="savedState"></param>
public override void Uninstall(System.Collections.IDictionary savedState)
{
base.Uninstall(savedState);
}
private static void WriteToEventLog(string message)
{
string source = "Miopro.Setup.Prerequisites.CustomInstaller";
string log = "Application";
if (!EventLog.SourceExists(source))
{
EventLog.CreateEventSource(source, log);
}
EventLog.WriteEntry(source, message, EventLogEntryType.Information);
}
}
}
因此,当我安装时,我可以在我的应用程序文件夹默认位置上看到我的 Miopro.Setup.Precessions.dll,因此它可用。
我已经在这里准备了一些帖子,但他们都没有谈论自定义操作上的 CustomInstaller。收到此错误消息的可能原因是什么?
System.Configuration.Install.dll DLL 用于.NET Framework 项目。
因此创建.NET框架
Miopro.Setup.Prerequisites