Custom Action dll is not working . Installer is showing error: Wizard ended prematurely
Custom Action dll is not working . Installer is showing error: Wizard ended prematurely
我正在使用 dll 作为 wix 的一部分将一个目录复制到另一个目录。因此,作为测试程序,我使用以下代码 与控制台应用程序一起工作正常 。
Backup.dll
namespace WiXTutorial.Samples
{
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Deployment.WindowsInstaller;
public class SampleCheckPID
{
[CustomAction]
public static ActionResult Backup(Session session)
{
DirectoryCopy(@"D:\share", @"D:\sharecopy", true);
return ActionResult.Success;
}
private static void DirectoryCopy(
string sourceDirName, string destDirName, bool copySubDirs)
{
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
DirectoryInfo[] dirs = dir.GetDirectories();
// If the source directory does not exist, throw an exception.
if (!dir.Exists)
{
throw new DirectoryNotFoundException(
"Source directory does not exist or could not be found: "
+ sourceDirName);
}
// If the destination directory does not exist, create it.
if (!Directory.Exists(destDirName))
{
Directory.CreateDirectory(destDirName);
}
// Get the file contents of the directory to copy.
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
// Create the path to the new copy of the file.
string temppath = Path.Combine(destDirName, file.Name);
// Copy the file.
file.CopyTo(temppath, false);
}
// If copySubDirs is true, copy the subdirectories.
if (copySubDirs)
{
foreach (DirectoryInfo subdir in dirs)
{
// Create the subdirectory.
string temppath = Path.Combine(destDirName, subdir.Name);
// Copy the subdirectories.
DirectoryCopy(subdir.FullName, temppath, copySubDirs);
}
}
}
}
}
Product.wxs
<CustomAction Id='Backup' DllEntry='Backup' BinaryKey='CheckPID' Execute='immediate' Return='check' />
<InstallExecuteSequence>
<Custom Action='Backup' After='InstallFiles' />
</InstallExecuteSequence>
<Binary Id='CheckPID' SourceFile='D:\Nirvana\Installer\Backup\Backup\bin\Debug\Backup.dll' />
以上代码构建良好,如 link 所引用
- http://wixtoolset.org/documentation/manual/v3/wixdev/extensions/authoring_custom_actions.html
和
-https://www.firegiant.com/wix/tutorial/events-and-actions/how-to-manage/
但是当我安装应用程序时它显示错误:向导提前结束
这是我的日志输出
Error: could not load custom action class WiXTutorial.Samples.SampleCheckPID from assembly: CheckPID System.BadImageFormatException:
Could not load file or assembly 'CheckPID' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
File name: 'CheckPID' at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) at System.AppDomain.Load(String assemblyString)
at Microsoft.Deployment.WindowsInstaller.CustomActionProxy.GetCustomActionMethod(Session session, String assemblyName, String className, String methodName)
WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value .
CustomAction Backup returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
Action ended 17:01:54: Backup. Return value 3. MSI (s) (04:BC)
[17:01:54:356]: User policy value 'DisableRollback' is 0 MSI (s) (04:BC)
[17:01:54:356]: Machine policy value 'DisableRollback' is 0 MSI (s) (04:BC)
[17:01:54:357]: Calling SRSetRestorePoint API. dwRestorePtType: 13, dwEventType: 103, llSequenceNumber: 342, szDescription: "". MSI (s) (04:BC)
[17:01:54:357]: The call to SRSetRestorePoint API succeeded. Returned status: 0. MSI (s) (04:BC)
[17:01:54:357]: Unlocking Server Action ended 17:01:54: INSTALL. Return value 3.
在您的日志中有此错误消息:
This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
例如,一个可能的原因是您的程序集是使用 .NET 4 构建的,而加载的运行时是使用 .NET 2 的。下面的问答有更多相关信息:
"This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded"
确保您使用正确版本的编译器来构建 WiX 包(如果从命令提示符到 *.sln 文件)和自定义操作。
如果您使用 WixToolset 提供的模板为此自定义操作创建项目,则在构建项目时它将生成两个 dll:
D:\Nirvana\Installer\Backup\Backup\bin\Debug\Backup.dll
D:\Nirvana\Installer\Backup\Backup\bin\Debug\Backup.CA.dll
第二个是应该参考的:
<Binary Id='CheckPID' SourceFile='D:\Nirvana\Installer\Backup\Backup\bin\Debug\Backup.CA.dll' />
我正在使用 dll 作为 wix 的一部分将一个目录复制到另一个目录。因此,作为测试程序,我使用以下代码 与控制台应用程序一起工作正常 。
Backup.dll
namespace WiXTutorial.Samples
{
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Deployment.WindowsInstaller;
public class SampleCheckPID
{
[CustomAction]
public static ActionResult Backup(Session session)
{
DirectoryCopy(@"D:\share", @"D:\sharecopy", true);
return ActionResult.Success;
}
private static void DirectoryCopy(
string sourceDirName, string destDirName, bool copySubDirs)
{
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
DirectoryInfo[] dirs = dir.GetDirectories();
// If the source directory does not exist, throw an exception.
if (!dir.Exists)
{
throw new DirectoryNotFoundException(
"Source directory does not exist or could not be found: "
+ sourceDirName);
}
// If the destination directory does not exist, create it.
if (!Directory.Exists(destDirName))
{
Directory.CreateDirectory(destDirName);
}
// Get the file contents of the directory to copy.
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
// Create the path to the new copy of the file.
string temppath = Path.Combine(destDirName, file.Name);
// Copy the file.
file.CopyTo(temppath, false);
}
// If copySubDirs is true, copy the subdirectories.
if (copySubDirs)
{
foreach (DirectoryInfo subdir in dirs)
{
// Create the subdirectory.
string temppath = Path.Combine(destDirName, subdir.Name);
// Copy the subdirectories.
DirectoryCopy(subdir.FullName, temppath, copySubDirs);
}
}
}
}
}
Product.wxs
<CustomAction Id='Backup' DllEntry='Backup' BinaryKey='CheckPID' Execute='immediate' Return='check' />
<InstallExecuteSequence>
<Custom Action='Backup' After='InstallFiles' />
</InstallExecuteSequence>
<Binary Id='CheckPID' SourceFile='D:\Nirvana\Installer\Backup\Backup\bin\Debug\Backup.dll' />
以上代码构建良好,如 link 所引用 - http://wixtoolset.org/documentation/manual/v3/wixdev/extensions/authoring_custom_actions.html
和
-https://www.firegiant.com/wix/tutorial/events-and-actions/how-to-manage/
但是当我安装应用程序时它显示错误:向导提前结束
这是我的日志输出
Error: could not load custom action class WiXTutorial.Samples.SampleCheckPID from assembly: CheckPID System.BadImageFormatException:
Could not load file or assembly 'CheckPID' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
File name: 'CheckPID' at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) at System.AppDomain.Load(String assemblyString)
at Microsoft.Deployment.WindowsInstaller.CustomActionProxy.GetCustomActionMethod(Session session, String assemblyName, String className, String methodName)
WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value .
CustomAction Backup returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
Action ended 17:01:54: Backup. Return value 3. MSI (s) (04:BC)
[17:01:54:356]: User policy value 'DisableRollback' is 0 MSI (s) (04:BC)
[17:01:54:356]: Machine policy value 'DisableRollback' is 0 MSI (s) (04:BC)
[17:01:54:357]: Calling SRSetRestorePoint API. dwRestorePtType: 13, dwEventType: 103, llSequenceNumber: 342, szDescription: "". MSI (s) (04:BC)
[17:01:54:357]: The call to SRSetRestorePoint API succeeded. Returned status: 0. MSI (s) (04:BC)
[17:01:54:357]: Unlocking Server Action ended 17:01:54: INSTALL. Return value 3.
在您的日志中有此错误消息:
This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
例如,一个可能的原因是您的程序集是使用 .NET 4 构建的,而加载的运行时是使用 .NET 2 的。下面的问答有更多相关信息:
"This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded"
确保您使用正确版本的编译器来构建 WiX 包(如果从命令提示符到 *.sln 文件)和自定义操作。
如果您使用 WixToolset 提供的模板为此自定义操作创建项目,则在构建项目时它将生成两个 dll:
D:\Nirvana\Installer\Backup\Backup\bin\Debug\Backup.dll D:\Nirvana\Installer\Backup\Backup\bin\Debug\Backup.CA.dll
第二个是应该参考的:
<Binary Id='CheckPID' SourceFile='D:\Nirvana\Installer\Backup\Backup\bin\Debug\Backup.CA.dll' />