Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mono-repo with one-way dependee-only pathFiltering completely ignores version config #1102

Closed
AnorZaken opened this issue Oct 4, 2024 · 9 comments

Comments

@AnorZaken
Copy link

AnorZaken commented Oct 4, 2024

EDIT: This was my user error - the NBGV nuget wasn't inheriting properly because of my mistake!
Original content below:

Repo and setup

So I have a mono-repo with a few projects in it:

  • I have a root-level version config with all settings.
  • I one project that is versioned separately with inherit: false, lets call it Independent.
  • I one project which is a dependee only = it inherits and also defines it's own version, lets call it Dependee.
  • I have a bunch of other projects versioned together with inherit: true, lets say ProjA and ProjB.

So the root level config is a big full config with most settings defined.
It defines version, and specifically so none of the other projects are affected by Independent:

"version": "2.0-beta",
"pathFilters": [ "!/Independent" ],

And inside Independent/version.json for the same reason:

"inherit": false,
"version": "2.0-beta",
"pathFilters": [ "." ],

The Dependee-only project is not part of the primary release for this repo, it needs to bump Patch version if any of the other code is changed - but I don't want other projects to be affected by changes in this project.
However since I don't want to repeat all the other parts of the root-config, I followed the suggestion from here, which is to both inherit and set a version: #1004

"inherit": true,
"version": "2.0-beta",
"versionHeightOffset": 0

The "regular" projects that are versioned together (ProjA and ProjB) should ignore Dependee and have this config:

"inherit": true,
"pathFilters": [
  "!/Dependee"
]

Now to the issue.

I have everything commited, and sitting in the repo-root...
I build dotnet build Build.csproj -c Release /p:CI=true
I pack dotnet pack Build.csproj --no-build -c Release /p:PackageOutputPath=..\.nupkgs /p:CI=true

...and I get these packages:

  • Independent.2.0.x-beta.nupkg
  • Dependee.1.0.0.nupkg <-- ?? Version completely ignored :(
  • ProjA.2.0.x-beta.nupkg
  • ProjB.2.0.x-beta.nupkg
@AnorZaken
Copy link
Author

AnorZaken commented Oct 4, 2024

Ok I found what the cause was.
It happens because Dependee.csproj has:

<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>

But this is quite unexpected to me.

Is it supposed to work like that...?

I thought this setting was only for dependencies, not for what should happen when I build and pack the project.
After all, the version of this package is not managed centrally - it specifically overrides the version in its version.json.

@AnorZaken
Copy link
Author

Also the problem comes back if I add a Directory.Packages.props file in /Dependee - it's version becomes 1.0.0 again.

This seems like a bigger problem to me.
My real repo has more than the projects listed above, and being forced to move all package versions to the root-Directory.Packages.props file and define all overrides in induividual csproj files is not great.

You are supposed to be able to have Directory.Packages.props files in subfolders that only affect the projects that are in/below that folder.

@AArnott
Copy link
Collaborator

AArnott commented Oct 4, 2024

ManagePackageVersionsCentrally should have nothing to do with this.
The GitVersionBaseDirectory property (if you're using it) would likely screw up what you're trying to do though, since it overrides the path in which the version is calculated.

@AArnott
Copy link
Collaborator

AArnott commented Oct 4, 2024

If Dependee is producing 1.0.0 unexpected, maybe try running nbgv get-version in the dependee folder and see what you get.

@AnorZaken
Copy link
Author

AnorZaken commented Oct 4, 2024

Running /Dependee/nbgv get-version does print out the correct version.

Running /dotnet build ... + /dotnet pack from the root does not give correct versions though.

Am I building it wrong somehow..?

@AnorZaken
Copy link
Author

AnorZaken commented Oct 4, 2024

I have not set GitVersionBaseDirectory as far as I'm aware. I have never used this setting so I'm not sure.

EDIT:
Aha, if it is a setting inside Directory.Packages.props then no, I'm not using that anywhere in this repo.

@AnorZaken
Copy link
Author

AnorZaken commented Oct 4, 2024

Could this have something to do with me building all projects from one Build.csproj in root?

<Project Sdk="Microsoft.Build.Traversal/2.0.24">
  <ItemGroup>
    <!-- <ProjectReference Include="benchmarks/**/*.csproj" /> -->
    <ProjectReference Include="SharedNameHere*/*.csproj" />
    <!-- <ProjectReference Include="tests/**/*.csproj" /> -->
  </ItemGroup>
</Project>

@AArnott
Copy link
Collaborator

AArnott commented Oct 4, 2024

if it is a setting inside Directory.Packages.props then no, I'm not using that anywhere in this repo.

Directory.Packages.props is just another msbuild imported file. It can set properties just like any other imported file. The GitVersionBaseDirectory property may be set within dependee.csproj or (more likely) any other imported file in your repo (or even a nuget package that you consume that delivers additional imports.)

Running /Dependee/nbgv get-version does print out the correct version.

That's good.

Running /dotnet build ... + /dotnet pack from the root does not give correct versions though.

That suggests it's an msbuild-unique issue, which brings me back to that GitVersionBaseDirectory property as the most likely. If you can send me binlog for your build of dependee, I can take a look too.

@AnorZaken
Copy link
Author

@AArnott Aaah, I'm an idiot - I was trying to make a minimal reproducible repo with this issue, and as I was setting it up it dawned on me...

root Directory.Packages.props contains this part of course:

  <ItemGroup>
    <GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.6.143"/>
  </ItemGroup>

...well if I'm not inheriting that, then of course it's not going to work! 🙃
You can close this issue if you want, sorry for wasting your time. 🙏

@AArnott AArnott closed this as not planned Won't fix, can't repro, duplicate, stale Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants