Can't create migration because test projects won't build, even though main project can?

Viewed 63

Before fixing tests I would like to fix the main codebase with some migrations.

Entity Framework won't let me use Add-Migration if some projects don't build in the solution (i.e., the test projects). The rest of the solution, however, is able to build and launch.

Is there a way I can ignore the test projects (but without resorting to e.g. commenting out the tests or removing the projects)?

1 Answers

Add-Migration should work only with built assembly. For this reason, tests are not (or shouldn't be) the part of the final executable assembly -> that's the reason why new Project for test is always created.

Maybe it will help you to set for Add-Migration the parametes where you specify, which project should be use to find the DbContext - [-ProjectName <String>] / [-StartUpProjectName <String>]. From this project (and from any related) there shouldn't be reference to Test projects. If it is, something is probably wrong about the concept.

PM> get-help add-migration

NAME
    Add-Migration
    
SYNOPSIS
    Scaffolds a migration script for any pending model changes.
    
    
SYNTAX
    Add-Migration [-Name] <String> [-Force] [-ProjectName <String>] [-StartUpProjectName <String>] 
        [-ConfigurationTypeName <String>]     [-ConnectionStringName <String>] [-IgnoreChanges] 
        [-AppDomainBaseDirectory <String>] [<CommonParameters>]
    
    Add-Migration [-Name] <String> [-Force] [-ProjectName <String>] [-StartUpProjectName <String>] 
        [-ConfigurationTypeName <String>] -ConnectionString <String> -ConnectionProviderName <String>
        [-IgnoreChanges] [-AppDomainBaseDirectory <String>] [<CommonParameters>]

Related