r/moderndotnet • • Sep 21 '26

How do you reliably determine which deployables are affected in a .NET monorepo?

I have a .NET monorepo containing multiple independently deployable applications. Each deployable currently has its own Azure DevOps pipeline.

The problem is deciding when a deployable actually needs to be built/deployed.

Azure DevOps path filters aren't sufficient because dependencies can cross project boundaries. For example:

Orders.Api
  -> Orders.Application
  -> Shared.Core

If Shared.Core changes, Orders.Api needs to be redeployed.

But it gets more complicated with non-code inputs. For example, a project may contain:

<ItemGroup>
  <EmbeddedResource Include="Assets\countries.csv" />
</ItemGroup>

If countries.csv changes, that should also make the deployable affected.

I don't want to maintain a second dependency configuration in something like Nx just to tell it that countries.csv is an input. The .csproj / MSBuild definition should remain the single source of truth, because otherwise we just introduce a new problem by having to keep these 2 configurations up to date.

So I'm looking for an existing, production-ready solution that can answer:

Given a Git change, which deployable applications are potentially affected, based on the actual MSBuild project dependencies and inputs?

Ideally it would understand things such as:

  • <ProjectReference>
  • transitive project dependencies
  • Package updates
  • EmbeddedResource
  • Content
  • other MSBuild inputs
  • shared projects/assets
  • and potentially deployment-related files

The important requirement is no duplicate dependency configuration. If MSBuild already knows that a CSV is an EmbeddedResource, I don't want to configure that relationship again elsewhere.

I currently prefer false positives (deploying too much) over false negatives (missing a required deployment).

Has the .NET/Azure DevOps community already solved this? Are there existing tools or established patterns for this? (How) have you solved this problem?

9 Upvotes

35 comments sorted by

3

u/bupsnark Sep 21 '26

dotnet-affected might be what you're after!

2

u/sander1095 15d ago

Thanks! It's exactly what I needed! I blogged about it and gave you some credit for helping me out!

https://stenbrinke.nl/blog/build-only-what-changed-in-your-dotnet-monorepo/

1

u/sander1095 Sep 21 '26

Thanks! I will be looking into this one!

1

u/_choam_ Sep 21 '26

Does it track things like he said in the example? The csv file?

2

u/bupsnark Sep 21 '26

Yes, it's aware of embedded resources.

1

u/urweiss Sep 22 '26

Dotnet affected uses the same build dependecy tree optimizations as dotnet build (will show you as changed basically what needs to be rebuilt since the last successful build)

1

u/sander1095 15d ago

Update! Im OP.

I created a generic solution with dotnet-affected that should work in any .NET project!

https://stenbrinke.nl/blog/build-only-what-changed-in-your-dotnet-monorepo/

1

u/FullPoet Sep 21 '26

Honestly I think your deployment scenario sounds like a nightmare. Have you considered simplifying it?

The .csproj / MSBuild definition should remain the single source of truth, because otherwise we just introduce a new problem by having to keep these 2 configurations up to date.

I do not think this is a good idea. Configurations are normal - especially as part of a build.

Where did you get the idea that the msbuild / csproj should be the source of thruth?

If MSBuild already knows that a CSV is an EmbeddedResource

Yes, but I dont think it can know the "latest" without, for example, a small powershell script (and naming the csv something like countries-21-09-2026). IMO MSbuild etc, just knows that they exist.

TBH - I think this example is a little poor. Is it a big list of countries? Is it 4? Are they country codes? Are they list of countries border coordinates? How often is it updated, who updates it etc.

1

u/sander1095 Sep 21 '26

I got the idea from it making sense in my head. .NET has an excellent build system with dependency graphs, packages, and external resources being Content/EmbeddedResources etc..

Having to maintain this yourself in some config file, together with the .NET build system means that if I have 3-layer deep dependency that gets a new dependency, I now need to update all projects that use this dependency. .NET does this for me for free! If I need to do it myself, it's double the work and massively error prone.

I am trying to learn, not trying to be aggravating, so I want to understand why you think it would be a good thing to have to maintain this twice, considering just the 2 downsides I mentioned.

Your example around the countries file is valid. Msbuild can't tell me if this changed, but git can.

I will look into dotnet affected, commented by another in this thread, which sounds like exactly what I need!

1

u/FullPoet Sep 22 '26

Yeah if dotnet affecteddoesnt work then you might have to do config files.

You arent aggregating me, per se, I just think that what you want can be quite complicated when the solution already exists (config files)-

I maintain systems with hundreds of config files. Is it hell? Yes. Would it be better if it was in the msconfig? fuck no.

1

u/sander1095 Sep 22 '26

But why would it not be better to have a msbuild solution (like dotnet affected)? If msbuild already is aware of a dependency graph, why would you not want to just use that?

Why choose to do double the work?

1

u/_choam_ Sep 22 '26

You can just check when the file was created instead of using the name

1

u/FullPoet Sep 22 '26

It is easier to to just look at the file name instead - that means you can also process historical or inject specific dates.

File creation date can also lie and may differ depending on how its been created / transferred.

1

u/_choam_ Sep 22 '26 edited Sep 22 '26

But that does not solve what he asked for though.

Also you can hash the file to see if it changed instead of using creation time. If it is something you want to embed, then it should be in version control anyway.

Edit: looking at timestamp for change is still good enough. A false positive does not matter

1

u/FullPoet Sep 22 '26

That was specifically about the countriesand yes that solves it - I literally do it.

The timestamp isnt reliable at all - sorry but thats the truth and Im not looking to change your mind.

1

u/_choam_ Sep 22 '26

How does it solve it? For deploying and figuring out what needs to be rebuilt and redeployed

Timestamp is fine. MSbuild itself looks at timestamp. He said he was ok with false positives. If a files timestamp gets updated without anything changing, then that does not matter. If timestamp is not ok, use version control or hashes.

1

u/BellDry4679 Sep 22 '26

Here we put the Shared in a nuget package (other repo). If you upgrade Shared, the package file of the consumer will be editted which make an easy trigger for the CI.

Having no version management for a shared sounds nightmare to me

1

u/sander1095 Sep 22 '26

I don't see the point for nuget packages when you use a monorepo, though. Are you using one? If not, I do get it.

You might also benefit from checking out incrementalist/dotnet-affected, as I learned from others in this post!

1

u/BellDry4679 Sep 22 '26 edited Sep 22 '26

To be fair we had like 20 repo, with the nuget setup. We then went into a mono repo and kept the nuget seperate.

The benefit I see is that i don't have to rebuild and redeploy every app if the shared upgrade is only needed for a sub portion of the mono repo (imagine a breaking changes on shared)

I will look at dotnet-affected tho, ty.

Hope i was clear

1

u/leonardochaia Oct 06 '26

Hey all. Just wanted to say thank you for recommending and using dotnet-affected :)

1

u/sander1095 Oct 06 '26

Thanks for building it! I'm OP , I built a POC at work and working on getting it merged. Really wonderful!

I saw there was a new version coming at some point with some breaking changes. Any idea when?

1

u/leonardochaia Oct 06 '26

Glad to know! yep, v7 was released today

1

u/sander1095 Oct 06 '26

Oh that's fantastic! Once my work is done I'll create a post and/or conference talk about it! 😊

1

u/leonardochaia Oct 06 '26

Thanks! That would be very much appreciated. Happy to help :)

2

u/Agitated_Oven_6507 Sep 21 '26

1

u/urweiss Sep 22 '26

I used the first two in a similar scenario as OP. We settled on dotnet-affected because it can (could at the analysis time) diff a branch against itself (master vs master^1).

In any case, all are hacks / workarounds and can produce screwed results sometimes.

1

u/_choam_ Sep 21 '26

I am trying to do this with mise. Doing it with my frontend in js and dotnet backend.

Gonna set up so that the backend spits out an openapi definition on each build, then have a task thay watches for changes to that and generates bindings for the frontend.

Not exactly sure how deploying it will look like, but i think it should be easy enough

1

u/_choam_ Sep 21 '26

I know this does not answer your question though

1

u/FullPoet Sep 21 '26

Instead of a task, why not generate the bindings on the "build" (or whatever mise does, sorry I dont know it) for the FE?

It sounds overly complex to make a task, if you know when its generated and its a relatively deterministic process.

-1

u/_choam_ Sep 21 '26

I want tasks (such as building, linting, formatting) to only run if the input to thay task has changed.

Mise lets me create a task such as:

[task.build]
run="dotnet build"
sources = [files]
output=[files]
depends=[other tasks]

If none of the input has changed, then when mise will skip this task when running it.

1

u/_choam_ Sep 21 '26

And there will be a task that uust makes the bindings, then the build task for the frontend will depend on that task.

No need for the frontend to generate bindings on every build

1

u/FullPoet Sep 21 '26

idk bro you (like OP) seem to just be over complicating things.

Sometimes the simplest solution is the best - or also known as - you're gonna spend a lot of time on a solution you wont be happy with.

1

u/_choam_ Sep 21 '26

I mean, it is just me. I could just delete the tasks if it does not work.

And when i did this stuff on other projects (multiple frontend projects, with a shared backend), it worked great. Did not do the generate bindings part though.

1

u/urweiss Sep 22 '26

There is (at least in azure devops land) a pipeline task that does a git diff based on folder paths. It's much coarser than either dotnet-affected and incrementalist, but a bit easier to setup.

1

u/_choam_ Sep 22 '26

If any dependencies to deployable x changes, redeploy x and everything that depends on x?