vs2010 Windows安装程序自定义操作中的混合模式程序集

时间:2010-10-05 09:33:22

标签: visual-studio-2010

我有一个Windows安装程序项目,其中包含自定义操作。此自定义操作使用SMO配置数据库。安装程序项目是.Net 4.执行自定义操作时,出现以下错误:

    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文件中添加以下内容来在控制台和Winforms应用中修复此问题。

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

问题是我是如何做到这一点或与安装程序项目类似的东西?当自定义操作中的所有引用程序集都是框架工作2时,我仍然会遇到此问题,因此必须由MSI本身(根据Fusion日志查看器引起.net4)引起。

1 个答案:

答案 0 :(得分: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);
}