1.5: Adding Other Projects and References

Add other ASP.NET Core Projects

Now we're going to add our class libraries that will support our API.

Inside your main EFConnect folder (not inside your API project):

dotnet new classlib -o EFConnect.Models --framework netcoreapp2
dotnet new classlib -o EFConnect.Services --framework netcoreapp2
dotnet new classlib -o EFConnect.Data --framework netcoreapp2
dotnet new classlib -o EFConnect.Contracts --framework netcoreapp2

We added the --framework option to tell it to make these class libraries target the .NET Core ^2.0+ framework. Its default is .NET Standard 2.0 - which won't work with some packages we need.

Delete the default Class1.cs files generated in the class libraries.

Add Project References

Navigate into your EFConnect.API project in your command line

dotnet add reference ../EFConnect.Data/EFConnect.Data.csproj

This adds a reference in our .API project to the .Data project.

In our EFConnect.API.csproj file: we now have a new ItemGroup with a reference to our .Data project:

<ItemGroup>
    <ProjectReference Include="..\EFConnect.Data\EFConnect.Data.csproj" />
</ItemGroup>

Alternatively to adding the project reference via the command line - you could also just type that into the .csproj file.

Copy the project reference down two more times and edit them to add references to the Models, Data, Contracts, and Services class libraries.

<ItemGroup>
    <ProjectReference Include="..\EFConnect.Data\EFConnect.Data.csproj" />
    <ProjectReference Include="..\EFConnect.Models\EFConnect.Models.csproj" />
    <ProjectReference Include="..\EFConnect.Contracts\EFConnect.Contracts.csproj" />
    <ProjectReference Include="..\EFConnect.Services\EFConnect.Services.csproj" />
</ItemGroup>

Next, open the EFConnect.Services.csproj file and add references to the Data, Models, and Contracts projects.

This can be done manually by copying and editing what we did above - or via the CLI.

<ItemGroup>
    <ProjectReference Include="..\EFConnect.Data\EFConnect.Data.csproj" />
    <ProjectReference Include="..\EFConnect.Models\EFConnect.Models.csproj" />
    <ProjectReference Include="..\EFConnect.Contracts\EFConnect.Contracts.csproj" />
</ItemGroup>

In .Contracts, add a reference to the Data and Models projects:

<ItemGroup>
    <ProjectReference Include="..\EFConnect.Data\EFConnect.Data.csproj" />
    <ProjectReference Include="..\EFConnect.Models\EFConnect.Models.csproj" />
</ItemGroup>

In .Models, add a reference to the Data project:

<ItemGroup>
    <ProjectReference Include="..\EFConnect.Data\EFConnect.Data.csproj" />
</ItemGroup>

Add References to the Metapackage

Now, we need to add references to the Microsoft.AspNetCore.All metapackage in the .Services and .Models projects:

<ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5"/>
</ItemGroup>

Add Angular Project

In your main EFConnect folder, run the following command:

ng new EFConnectSPA --skip-tests --style scss --skip-git

This scaffolds out a new Angular project and tells the CLI we'd like .scss instead of .css and that we don't want it to generate test files.

Next, we'll install a few packages: ngx-bootstrap, font-awesome, and Bootstrap 4.

Navigate into your SPA project and run the following command:

npm install ngx-bootstrap bootstrap font-awesome --save

Initialize Git Repository

Now that we have the basic structure of our project - it would be a good time to initialize a new Git repository!

Initialize a new git repository in your main EFConnect folder.

Last updated