在向我的解决方案添加不相关的Wix安装项目后,ASP.NET MVC Web应用程序上的程序包管理器控制台中运行update-database
失败。
为什么update-database
访问这个不相关的项目?为什么wix项目的存在会触发无法找到的程序集的负载?我该如何解决这个问题?
这种情况发生在一个包含Web,桌面,安装程序项目的更大的解决方案中,但经过相当严峻的考验后,我将其单独复制:
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
。
详细说明:
代码段:
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>