2010-10-05 75 views
0

我有一个包含自定义操作的Windows安装程序项目。此自定义操作使用SMO来配置数据库。安装程序的项目是.NET 4当执行自定义操作,我得到以下错误:vs2010 Windows安装程序自定义操作中的混合模式程序集

Mixed mode assembly is built against version 'v2.0.50727' of the runtime 
and cannot be loaded in the 4.0 runtime without additional configuration information. 

我可以在一个单独的可执行文件运行数据库更新代码或重写自定义操作,以便不使用SMO,但我如果可能,宁愿保留代码。

我知道如何通过将以下内容添加到app.config文件来解决这个问题。

<?xml version="1.0"?> 
<configuration> 
    <startup useLegacyV2RuntimeActivationPolicy="true"> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> 
    </startup> 
</configuration> 

问题是我该怎么做这个或类似的安装程序项目?当自定义操作中的所有引用程序集都是框架工作2时,我仍然会遇到此问题,因此必须根据Fusion Log Viewer根据MSI本身(它是.net4)引起。

回答

0

最后,我决定从安装程序的自定义操作中启动一个concole应用程序,以便对数据库进行必要的更新。它的工作原理以及

代码来调用安装程序的控制台应用程序是:

public enum ReturnCode 
{ 
    Error = -1, 
    Updated = 0, 
    UpdateNotRequired = 1, 
    ServerNotAvailable = 2, 
    DatabaseNotAvailable = 3 
} 

private int UpdateSchema(string installationPath) 
{ 
    const string exeName = @"SchemaUpdater"; 

    string executablePath = Path.Combine(installationPath, exeName); 

    LogModule.Log_NewLogEntry("Starting Schema Updater"); 

    var myProcessStartInfo = new ProcessStartInfo(executablePath); 
    myProcessStartInfo.UseShellExecute = false; 
    myProcessStartInfo.CreateNoWindow = true; 

    Process process = Process.Start(myProcessStartInfo); 
    process.WaitForExit(); 

    int exitCode = process.ExitCode; 

    LogModule.Log_NewLogEntry(string.Format("SchemaUpdate returned {0}", exitCode)); 

    return exitCode; 
} 

public override void Install(IDictionary stateSaver) 
{ 
    string installationPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); 

    int dbUpdaterReturnVal = UpdateSchema(installationPath); 

    if (dbUpdaterReturnVal < 0) 
    { 
     throw new Exception("Schema Update returned with an error"); 
    } 

    if (dbUpdaterReturnVal == (int)ReturnCode.ServerNotAvailable) 
    { 
     throw new Exception("SqlServer Not available. Aborting Install"); 
    } 

    base.Install(stateSaver); 
}