How to Include Paths and Exclude All Others

I am in the process of building out several pipelines that correspond with projects within my .NET 6 solution. I did not want a pipeline to run if it didn’t need to. If a change was made to Project B and Project B isn’t connected to Project A through project references, I don’t want Project A’s build pipeline to run.
I was initially doing this with the path exclusions but I realized that this isn’t maintainable. Doing this would mean i need to specify every part of the solution that doesn’t need to be triggering this build. New projects, pipeline yaml files, or other files could be added later and I would have to go in and add it to the list of excluded paths. Here’s an example

paths:
  exclude:
    - myapp/api/*
    - azure-pipelines-api.yml
    - templates/api/*

Lets say this is an example yaml file for my Vue app. I don’t need to deploy my Vue app every time I change some business logic in my API therefore, at first it might seem like this is a good solution. I have already mentioned why it is not.

So I had the brilliant thought that I should be able to include only the relevant folders and files and exclude all others. I found something that said I should be able to simply specify a path include as I did with the path exclude, except this time specify the folders and files that should trigger this pipeline.

paths:
  include:
    - myapp/vueapp/*
    - azure-pipelines-vueapp.yml
    - templates/vueapp/*

At the time I tried this, I had already created a pull request. The commit that I was making only had the one to the api, but the vue app was getting triggered every time for some reason. Well I realized that the reason the vue app was still being triggered was due to the fact that I was updating a pull request that did have changes to the vue app. So even though I was only modifying on api file with this commit, all of the files modified in the pull request were what was being compared against the specified paths.

For more information about specifying paths in the yaml of an azure devops pipeline, here is the official documentation.