Wix Setup Project breaks unrelated Migrations update-database call

1

Running update-database from the Package Manager Console on an ASP.NET MVC Web Application fails after I add an unrelated Wix setup project to my solution.

Why is update-database accessing this unrelated project? Why does the presence of the wix project trigger a load of an assembly that cannot be found? How do I fix this?

This happens in a larger solution with web, desktop, installer projects, but after considerable head-scratching I reproduced this in isolation:

  • Setup a new stock-standard VS solution with an ASP.NET MVC Web Application, Entity Framework, enable migrations, add WebMatrix components, setup Role provider.
  • Add Configuration.Seed() method to call out to WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection(..) and System.Web.Security.Roles.

Run update-database. It will work fine. Now add a Wix setup project (no need to configure) and it will fail at/before executing Seed() with

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.

So, it seems having a Wix project in my solution triggers the load of an additional (not found) assembly when trying to call WebSecurity / WebMatrix methods through update-database from the Package Manager Console.

Workaround: Unload the Wix setup project and restart Visual Studio. There is no need to remove the project entirely.

Adding the missing dll to the GAC or a reference to the machine.config does not help. The dll is found but loading it errors out with

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

Using FUSLOGVW.exe to log assembly load events didn't help. It basically shows that update-database can't find the v15.1 dll because it's not in the GAC and there is no app/host/system config file pointing at it.

Running the seed method from the running web application (enable automatic migration) works fine.

And yes, I am setting PMC "default project" to the web application, ie, point update-database at the web application.

Details:

  • Visual Studio Professional 2017 on Win 10 Pro fully patched.
  • Recently upgraded VS from 2015. No such problem under 2015.
  • Wix Toolset 3.11.0.1528
  • Package Manager Console 4.1.0.2427
  • System.Web.Mvc 5.2.3.0
  • Entity Framework 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 lives in C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\ and Visual studio has a redirect to it in its app.config.

Snippets:

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>
entity-framework
wix
entity-framework-migrations
asked on Stack Overflow May 11, 2017 by typpo

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0