Wix安装项目打破了无关的迁移更新 - 数据库调用

时间:2017-05-11 01:05:45

标签: entity-framework wix ef-migrations

在向我的解决方案添加不相关的Wix安装项目后,ASP.NET MVC Web应用程序上的程序包管理器控制台中运行update-database失败。

为什么update-database访问这个不相关的项目?为什么wix项目的存在会触发无法找到的程序集的负载?我该如何解决这个问题?

这种情况发生在一个包含Web,桌面,安装程序项目的更大的解决方案中,但经过相当严峻的考验后,我将其单独复制:

  • 使用ASP.NET MVC Web应用程序,实体框架,启用迁移,添加WebMatrix组件,设置角色提供程序,设置新的库存标准VS解决方案。
  • 添加Configuration.Seed()方法以呼叫WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection(..)System.Web.Security.Roles

运行update-database。它会工作正常。现在添加一个Wix安装项目(无需配置),它将在执行Seed()之前/之前失败

Could not load file or assembly 'Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

因此,当我尝试通过包管理器控制台中的update-database调用WebSecurity / WebMatrix方法时,我的解决方案中的Wix项目似乎会触发其他(未找到)程序集的加载。

解决方法:卸载Wix安装项目并重新启动Visual Studio。无需完全删除项目。

将缺少的dll添加到GAC或对machine.config的引用没有帮助。找到了dll,但用

加载错误
System.IO.FileLoadException: Loading this assembly would produce a different grant set from other instances. (Exception from HRESULT: 0x80131401)

使用FUSLOGVW.exe记录程序集加载事件并没有帮助。它基本上表明update-database无法找到v15.1 dll,因为它不在GAC中,并且没有指向它的app / host / system配置文件。

从正在运行的Web应用程序运行种子方法(启用自动迁移)可以正常工作。

是的,我正在设置PMC"默认项目"到Web应用程序,即在Web应用程序中指向update-database

详细说明:

  • Win 10 Pro上的Visual Studio Professional 2017完全打补丁。
  • 最近从2015年升级VS. 2015年没有这样的问题。
  • Wix Toolset 3.11.0.1528
  • 程序包管理器控制台4.1.0.2427
  • System.Web.Mvc 5.2.3.0
  • 实体框架6.1.3
  • WebMatrix.Data.dll 3.0.0.0
  • WebMatrix.WebData.dll 3.0.0.0
  • Microsoft.Build.Framework.dll v15.1.0.0位于C:\ Program Files(x86)\ Microsoft Visual Studio \ 2017 \ Professional \ MSBuild \ 15.0 \ Bin \中,Visual Studio在其中重定向到它的app.config。

代码段:

Configuration.cs:

class Configuration : DbMigrationsConfiguration<MyDbContextHere>
{
    public Configuration() { AutomaticMigrationsEnabled = false; }

    protected override void Seed(Stash context)
    {
        WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfiles", "UserId", "UserName", autoCreateTables: true);    
        if(!Roles.RoleExists("G1")) Roles.CreateRole("G1");
    }
}
`

的web.config:

`
<configuration>  
  <system.web>
    <roleManager enabled="true" defaultProvider="SimpleRoleProvider">
      <providers>
        <clear />
        <add name="SimpleRoleProvider" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData" />
      </providers>
    </roleManager>

0 个答案:

没有答案