On the front page we showed a code hierarchy and said that Monobuild could do all of the following:
In this section we will show how to do all of the things we stated as possible on the front page. The diagram above shows the project structure from a dependency point of view, but a more common layout directory wise would be as below:
The script below creates a Demo directory, creates the project structure of the first diagram in the directory structure of the second and initialises a Git repository and commits our work.
md Demo
cd Demo
dotnet new gitignore
dotnet new classlib -o src/Utilities
dotnet new classlib -o src/ServiceA.API/
dotnet new webapi -o src/ServiceA
dotnet new webapi -o src/ServiceB
dotnet new mvc -o src/Site
dotnet new sln
dotnet sln add ./src/Utilities/
dotnet sln add ./src/ServiceA/
dotnet sln add ./src/ServiceB/
dotnet sln add ./src/Site
dotnet sln add ./src/ServiceA.API/
dotnet add ./src/ServiceA/ServiceA.csproj reference ./src/Utilities/
dotnet add ./src/ServiceA/ServiceA.csproj reference ./src/ServiceA.API/
dotnet add ./src/ServiceB/ServiceB.csproj reference ./src/Utilities/
dotnet add ./src/Site/Site.csproj reference ./src/ServiceB
dotnet add ./src/Site/Site.csproj reference ./src/ServiceA.API/
git init
git add .
git commit -m"Intitial Commit"
src/Utilities/Class1.cs
git add .
and git commit -m "update utilties"
monobuild -t .src/Site
, you should see the results below: ❯ monobuild -t ./src/Site
The following files changed:
src/Utilities/Class1.cs
<YES>
Site
and Utilities
we need to create one, create a file in src/Site/.monobuild.deps
with the content below:../utilities
../utilities/**/*
monobuild -t .src/Site
again, you should see the results below.❯ monobuild -t ./src/Site
<NO>
This is simply a case of adding an ignore to our ignore file, but we will also demonstrate that ignore files only affect the build directory which they are parented in.
src/Site/readme.md
src/ServicB/readme.md
git add .
and git commit -m"Added readme files"
monobuild -t .src/Site
you should see:❯ monobuild -t ./src/Site
The following files changed:
src/Site/readme.md
src/ServiceB/readme.md
<YES>
src/Site/.monobuild.ignore
add **/*.md
the complete file will now look like this:../utilities/**/*
**/*/md
monobuild -t .src/Site
, you should see the results below:The following files changed:
src/ServiceB/readme.md
<YES>
Notice we have only removed the file in
Site
to ignore Markdown files inServiceB
we need to add another ignore file toServiceB
src/ServiceB/.monobuild.ignore
with **/*.md
as the ignore glob.monobuild -t .src/Site
, no build is now required.For this we need to ignore all changes in ServiceB
, we no how to achieve this by ignoring all files in ServiceB
and create a build dependency for the contracts folder.
src/ServiceB/
called contracts.git add .
and git commit -m "Updated contracts"
monobuild -t .src/Site
a build will be required.src/Site/.monobuild.ignore
, add a line ../ServiceB/**/*
, to ignore all files in ServiceB.monobuild -t .src/Site
a build will not be required we are ignoring all files.src/Site/.monobuild.deps
, add a line ../ServiceB/Contracts
monobuild -t .src/Site
a build will be required.You can test that any other change committed in src/ServiceB
will not cause a build only changes within the contracts directory.
In both Don’t want to release the site because of a change in utilities and Don’t want to release site for any changes in ServiceB unless it is in the contracts directory, we manually created a dependency.
Dependencies for a build can be created by adding a .monobuild.deps
and listing the dependencies one per line. The dependencies should be relative to the current directory so you will normally need to exit the current directory by prefixing your directory using "../"
.