Share via

add-migration throws error File web.dll not found. The startup project is where DbContext is. Web is the asp.net core project

Pablo The Tiger 186 Reputation points
2026-02-25T05:02:08.6833333+00:00

Greetings, Ladies and Guys!

So finally I found a tutorial of Razor Pages C#, with jQuery AJAX.

The solution has 3 projects: Web (asp.net core razor pages app, here goes the config, such as connection string and some services), Core (Model and Interfaces), and Infrastructure (here goes the DbContext and Repositories).

So I tried to run: add-migration Initial

and the output was:

Build started

Builder succeeded

File 'C:\Users\PABLO\source\repos\RazorCRUD.jQueryAJAX\Infrastructure\bin\Debug\net9.0\Web.dll' not found.

In the Package Manager Console (where I write the before) in the dropdown it is selected the project Infrastructure (where is DbContext)

If I run: update-database it occurs the same messages.

I searched a lot and saw something like:

Add-Migration InitialCreate -Project Web -StartupProject Infrastructure

but it doesn't work

Your help is much appreciated

Pablo

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments
{count} votes

Answer accepted by question author
  1. Jack Dang (WICLOUD CORPORATION) 14,955 Reputation points Microsoft External Staff Moderator
    2026-02-25T07:47:34.64+00:00

    Hi @Pablo The Tiger ,

    Thanks for reaching out.

    The issue you’re seeing happens because EF Core needs both the project where your DbContext lives and the project that contains your app configuration. In your solution:

    • Infrastructure -> contains DbContext
    • Web -> contains connection string and services

    If EF Core tries to use Infrastructure as the Startup Project, it can’t find Web.dll, which causes the error.

    Try running this instead:

    Add-Migration InitialCreate -Project Infrastructure -StartupProject Web
    

    This tells EF Core:

    • DbContext is in Infrastructure
    • Startup Project is Web (so it can read the connection string)

    Then run:

    Update-Database -Project Infrastructure -StartupProject Web
    

    Hope this helps! If my answer was helpful - kindly follow the instructions here so others with the same problem can benefit as well.


1 additional answer

Sort by: Most helpful
  1. Q&A Assist
    2026-02-25T05:02:52.72+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    It seems like you are encountering an issue with the add-migration command in your ASP.NET Core project setup. The error message indicates that the Web.dll file cannot be found, which typically means that the command is not able to locate the startup project correctly.

    Here are some steps you can take to resolve this issue:

    1. Check Project Configuration: Ensure that the Web project is set as the startup project in Visual Studio. You can do this by right-clicking on the Web project in Solution Explorer and selecting "Set as Startup Project."
    2. Use Correct Command: When running the migration command, make sure you specify the correct parameters. Since your DbContext is in the Infrastructure project and your startup project is Web, you should run:
         Add-Migration InitialCreate -Project Infrastructure -StartupProject Web
      
      This tells the command to look for the DbContext in the Infrastructure project while using the Web project as the startup.
    3. Build the Solution: Before running the migration command, ensure that the solution builds successfully. You can do this by selecting "Build Solution" from the Build menu in Visual Studio.
    4. Check Output Path: Verify that the output path for the Web project is correctly set. You can check this in the project properties under the "Build" tab. Ensure that the output path matches where the Web.dll should be generated.
    5. Clean and Rebuild: Sometimes, cleaning the solution and then rebuilding it can resolve issues with missing files. You can do this by selecting "Clean Solution" followed by "Rebuild Solution" from the Build menu.

    If you follow these steps and still encounter issues, consider checking the project dependencies and ensuring that all necessary packages are installed and up to date.


    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.