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

Reject multiple versions of same package #15367

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Winniexu01
Copy link
Member

@Winniexu01 Winniexu01 commented Dec 27, 2024

Related: dotnet/source-build#3391

Add a condition to check whether the package versions are consistent and remove other versions of the same package.

@@ -123,6 +123,7 @@

<ItemGroup>
<IntermediateNupkgFile Include="@(IntermediateNupkgArtifactFile)" PackagePath="artifacts" />
<IntermediateNupkgFile Remove="@(IntermediateNupkgFile)" Condition="'$(Version)' != '' and !$([System.Text.RegularExpressions.Regex]::Match(%(Identity),'$(Version)').Success)"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you just want to generate an error if you find multiple packages with the same ID in the input package set.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I have updated the code d6772cd, an error will be generated if I find the packages with multiple versions and will provide the package path.

@@ -129,6 +129,15 @@
<Output TaskParameter="Filtered" ItemName="IntermediatePackageFile" />
</RemoveDuplicates>

<ItemGroup>
<IntermediateFileWithoutVersion Include="$([System.Text.RegularExpressions.Regex]::Replace('%(IntermediatePackageFile.Identity)','\.(\d+\.){2}\d+(-\w+)?(\.(\d+\.){1}\d+)?',''))" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be simpler. nupkgs are always of the form .version.nupkg, so I don't think you need to use the more fragile regex match here.

In addition, I would strip the versions, then call RemoveDuplicates, then check that IntermediateNupkgFile's count matches IntermediateFileWithoutVersion's count

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be simpler. nupkgs are always of the form .version.nupkg, so I don't think you need to use the more fragile regex match here.

For example, in the roslyn repo, the paths of the packaged .nupkgs are all $(ArtifactsPackagesDir)Shipping and $(ArtifactsPackagesDir)NonShipping, and the version format all matches $(Version), so I can simply strip the versions with $(Version). But according to the information you gave to me, 3 versions of the same package will be created via the PackageReleasePackages target, the versions are not in the same format, so I used the regex replace to strip the versions.

Version Format Path
Release stable version 1.0.0 $(ArtifactsPackagesDir)Release
PreRelease stable version 1.0.0-preview $(ArtifactsPackagesDir)PreRelease
Non-stable version 1.0.0-preview.1234.5 $(ArtifactsShippingPackagesDir)

then call RemoveDuplicates, then check that IntermediateNupkgFile's count matches IntermediateFileWithoutVersion's count

This method is indeed simpler, but it may not provide information about the .nupkg.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mmitche , does the above explanation make sense to you? Or do I still need to modify the code according to your previous suggestions?

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

Successfully merging this pull request may close these issues.

2 participants