How To Use Another Project Reference In Existing Project Using ASP.NET Core

In this article, we will learn how to use another project reference in existing project in ASP.NET Core

Let’s get started with creating ASP.NET Core Project.

First create Demo Project like below

1. Open Visual Studio and click on Create New Project.

using-project-reference-for-another-project-1

2. From the Create a New Project window, select ASP.Net Core Web Application option.

using-project-reference-for-another-project-2

3. Now you need to set a Name for your project and also you can set its Location where you want to create the Project.

using-project-reference-for-another-project-3

Add the below code in Home view page

@{
    ViewData["Title"] = "Home Page";
}

<section class="h-100 gradient-form" style="background-color: #eee;">
    <div class="container py-5 h-100">
        <div class="row d-flex justify-content-center align-items-center h-100">
            <div class="col-xl-10">
                <div class="card rounded-3 text-black">
                    <div class="row g-0">
                        <div class="col-lg-6">
                            <div class="card-body p-md-5 mx-md-4">

                                <div class="text-center">
                                    <img src="https://mdbcdn.b-cdn.net/img/Photos/new-templates/bootstrap-login-form/lotus.webp"
                                         style="width: 185px;" alt="logo">
                                    <h4 class="mt-1 mb-5 pb-1">We are The Lotus Team</h4>
                                </div>

                                <form>
                                    <p>Please login to your account</p>

                                    <div class="form-outline mb-4">
                                        <input type="email" id="form2Example11" class="form-control"
                                               placeholder="Phone number or email address" />
                                        <label class="form-label" for="form2Example11">Username</label>
                                    </div>

                                    <div class="form-outline mb-4">
                                        <input type="password" id="form2Example22" class="form-control" />
                                        <label class="form-label" for="form2Example22">Password</label>
                                    </div>

                                    <div class="text-center pt-1 mb-5 pb-1">
                                        <button class="btn btn-primary btn-block fa-lg gradient-custom-2 mb-3" type="button">
                                            Log
                                            in
                                        </button>
                                        <a class="text-muted" href="#!">Forgot password?</a>
                                    </div>

                                    <div class="d-flex align-items-center justify-content-center pb-4">
                                        <p class="mb-0 me-2">Don't have an account?</p>
                                        <button type="button" class="btn btn-outline-danger">Create new</button>
                                    </div>

                                </form>

                            </div>
                        </div>
                        <div class="col-lg-6 d-flex align-items-center gradient-custom-2">
                            <div class="text-white px-3 py-4 p-md-5 mx-md-4">
                                <h4 class="mb-4">We are more than just a company</h4>
                                <p class="small mb-0">
                                    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
                                    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
                                    exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

Now run the project and it’s showing output like below

using-project-reference-for-another-project-4

Now add demo reference project as shown further steps

using-project-reference-for-another-project-5

Now right click on demo reference project and unload project and again right click on project and select edit project file and add demo project path as below

using-project-reference-for-another-project-6

Now reload the project and run the project.

Right click on demo reference project and select option Open folder in file explorer 

Open command prompt as below

using-project-reference-for-another-project-7

Execute the command:- dotnet restore and dotnet build

using-project-reference-for-another-project-8

Now run the demo reference project

using-project-reference-for-another-project-9

it’s throwing The request matched multiple endpoints error

The solution is first you remove home controller and it’s view because in demo project also home controller and view that’s why the demo reference project throwing the error

Now add new controller and Add method like below

using-project-reference-for-another-project-10

using-project-reference-for-another-project-11

Now set route as below

using-project-reference-for-another-project-12

Now run the project.

using-project-reference-for-another-project-13

Hope you understand the article , If you still have any questions or queries then please let me know in the comment section, I’ll respond to you as soon as possible.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories