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

Disallow duplicates in Packages.props #177

Open
erikness opened this issue May 13, 2020 · 3 comments
Open

Disallow duplicates in Packages.props #177

erikness opened this issue May 13, 2020 · 3 comments
Labels
Feature Request New feature or request Help Wanted Looking for community contributions!

Comments

@erikness
Copy link
Contributor

erikness commented May 13, 2020

With Central Package Versions, you can have a Packages.props that does this:

<ItemGroup>
  <PackageReference Update="Foo" Version="[3.1.4]" />
  <PackageReference Update="Bar" Version="[1.6.1]" />
  <PackageReference Update="Foo" Version="[2.7.1]" />
</ItemGroup>

Update "items" seem to be executed sequentially, so the second "Foo" line will take effect and the first will be totally ignored.

Now, this is a mistake in any Packages.props that has this - you can only have 1 global version. But it's a silent mistake and an easy one to make. So it would be nice to have some logic to catch this and break the build when there are duplicates.

While I think that rationale is easy to justify, the problem is that can't think of a good way to implement this in the MSBuild language. You can't do filtering or transforms on the update lines because they are not the actual PackageReference items, they're essentially just statements that change the metadata.

I can always make an XML parsing script to check for duplicates for my own team. Or we could be more disciplined about keeping update lines alphabetized (though I don't know how to enforce that with MSBuild either). But if there's a way to do this, it would be a big help.

@jeffkl jeffkl added the Feature Request New feature or request label May 13, 2020
@jeffkl
Copy link
Contributor

jeffkl commented May 13, 2020

This seems like a great feature, I agree that it can be a tough mistake to catch. Off the top of my head, the only way to detect this would be to look at the XML which might be slow. I can ask the MSBuild team to see if there's a better way.

@bddckr
Copy link

bddckr commented May 13, 2020

I actually got bitten by this by importing a different .props into Packages.props. So if this feature can even notice those cases, that would be even better.

@jeffkl jeffkl added the Help Wanted Looking for community contributions! label Nov 18, 2021
@stan-sz
Copy link
Contributor

stan-sz commented Jul 13, 2022

See dotnet/msbuild#1777 and the links from it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request New feature or request Help Wanted Looking for community contributions!
Projects
None yet
Development

No branches or pull requests

4 participants