MsiInstallProduct 在 window 2016 上抛出 NullReferenceException
MsiInstallProduct throw NullReferenceException on window 2016
我遇到了奇怪的错误:
ERROR:System.NullReferenceException: Object reference not set to an instance of an object.
at WindowsInstaller.MsiInterop.MsiInstallProduct(String product, String commandLine)
at msicontroller.Program.Main(String[] arg
声明:
[DllImport(MSI_LIB, CharSet = CharSet.Auto, SetLastError=true)]
extern static public MsiError MsiInstallProduct(string product, string commandLine);
我只在 1 台电脑上遇到这个错误,电脑是 win server 2016
UPDATE (for community): If you insist on doing the platform invokes directly, you can still benefit from DTF mentioned below since the DTF source code
is available on github.com. You can see how the platform invokes / COM interops
are done there.
- You could also install via COM instead of Win32 as described in section 1 here. And in section 7 here.
- The MSI COM API is documented here.
- I like to pillage github.com for working examples.
DTF:您现在使用 DTF (Deployment Tools Foundation) for this. This is a component / set of assemblies that is part of the WiX toolkit 会更容易,它会处理所有平台调用对您而言,您可以将 MSI API 用作常规托管 API(大约)。也就是说DTF is essentially a .NET wrapper for the Win32 Windows Installer API
.
DTF 样本 (from this answer, section 6):
using Microsoft.Deployment.WindowsInstaller;
public static void Uninstall( string productCode)
{
Installer.ConfigureProduct(productCode, 0, InstallState.Absent, "REBOOT=\"R\"");
}
过程:下载 WiX 工具集,安装并在 Visual Studio 项目中添加引用到 Microsoft.Deployment.WindowsInstaller.dll
文件并将其与其他发布文件一起部署。或者,如果这是针对 Windows 安装程序自定义操作:包装在您的自定义操作项目中。安装 Visual Studio 集成后,WiX 中的模板可用于此 - 从上面的相同 link 单独下载。从本质上讲,我认为它应该在构建时自动神奇地发生。交易是托管 DLL(程序集)在构建期间转换为本机包装 DLL,其中包含 运行 自定义操作所需的文件。
一些进一步的链接:
- DTF - Deployment Tools Foundation - .NET - 组成 DTF 的不同程序集的简要说明。 推荐阅读或浏览。
- 使用 Windows 安装程序 PowerShell 模块:
我遇到了奇怪的错误:
ERROR:System.NullReferenceException: Object reference not set to an instance of an object.
at WindowsInstaller.MsiInterop.MsiInstallProduct(String product, String commandLine)
at msicontroller.Program.Main(String[] arg
声明:
[DllImport(MSI_LIB, CharSet = CharSet.Auto, SetLastError=true)]
extern static public MsiError MsiInstallProduct(string product, string commandLine);
我只在 1 台电脑上遇到这个错误,电脑是 win server 2016
UPDATE (for community): If you insist on doing the platform invokes directly, you can still benefit from DTF mentioned below since the DTF source code is available on github.com. You can see how the platform invokes / COM interops are done there.
- You could also install via COM instead of Win32 as described in section 1 here. And in section 7 here.
- The MSI COM API is documented here.
- I like to pillage github.com for working examples.
DTF:您现在使用 DTF (Deployment Tools Foundation) for this. This is a component / set of assemblies that is part of the WiX toolkit 会更容易,它会处理所有平台调用对您而言,您可以将 MSI API 用作常规托管 API(大约)。也就是说DTF is essentially a .NET wrapper for the Win32 Windows Installer API
.
DTF 样本 (from this answer, section 6):
using Microsoft.Deployment.WindowsInstaller;
public static void Uninstall( string productCode)
{
Installer.ConfigureProduct(productCode, 0, InstallState.Absent, "REBOOT=\"R\"");
}
过程:下载 WiX 工具集,安装并在 Visual Studio 项目中添加引用到 Microsoft.Deployment.WindowsInstaller.dll
文件并将其与其他发布文件一起部署。或者,如果这是针对 Windows 安装程序自定义操作:包装在您的自定义操作项目中。安装 Visual Studio 集成后,WiX 中的模板可用于此 - 从上面的相同 link 单独下载。从本质上讲,我认为它应该在构建时自动神奇地发生。交易是托管 DLL(程序集)在构建期间转换为本机包装 DLL,其中包含 运行 自定义操作所需的文件。
一些进一步的链接:
- DTF - Deployment Tools Foundation - .NET - 组成 DTF 的不同程序集的简要说明。 推荐阅读或浏览。
- 使用 Windows 安装程序 PowerShell 模块: