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

Implement group conditions for SDK-style projects #4247

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

Conversation

vgeronimos
Copy link

This is to fix #2394 - the condition values in paket.dependencies are now included in the obj/<project>.paket.props files after running dotnet restore.

@vgeronimos vgeronimos marked this pull request as draft February 15, 2024 05:30
@vgeronimos vgeronimos marked this pull request as ready for review February 15, 2024 06:04
@vgeronimos vgeronimos marked this pull request as draft February 19, 2024 01:50
@vgeronimos vgeronimos force-pushed the group-conditions-for-sdk-projects branch from d19eb66 to 5cb3a1c Compare February 21, 2024 04:07
@vgeronimos vgeronimos force-pushed the group-conditions-for-sdk-projects branch from 5cb3a1c to e6a4c06 Compare February 21, 2024 05:06
@vgeronimos
Copy link
Author

vgeronimos commented Feb 21, 2024

This ended up being a bit deeper than I expected. The changes here have a few steps:

  • When generating *.paket.props, add the group's ReferenceCondition to the condition grouping, and include it in the generated <ItemGroup>'s condition.
  • When generating *.paket.resolved, add the group's ReferenceCondition as the 10th item on each line.
  • Add a new public API method, GetConditions, to get a list of all of the conditions defined on groups
  • Adds a new overload to the FixNuspecs public API method to allow specifying which conditions to use when re-associating the nuspec package names with dependency groups
  • Adds a show-conditions subcommand and a --conditions parameter to fix-nuspecs to use the above changes
  • Modifies Paket.Restore.targets to make use of all of the above:
    • PaketRestore now reads the conditions for the lines in *.paket.resolved, and if specified will check if the corresponding property is defined before adding a <PackageReference>
    • PaketOverrideNuspec uses the show-conditions subcommand to get a list of properties that are relevant, and then constructs a list of the ones that evaluate to 'true'. If there are any, they are passed to fix-nuspecs.

I needed this to be able to produce packages that use different sets of dependencies based on the configuration being built. The build then sets properties based on which configuration is selected. With these changes to Paket, the assemblies are all built with the expected set of dependencies, and the resulting .nupkg files reflect that.

To be able to switch the values of the properties, I have to restore the project with msbuild -t restore -c <configuration> instead of dotnet restore because the dotnet command doesn't have a way to provide properties or configurations to the restore on the command line.

I haven't got any new tests for the majority of these changes - I had a look and got a bit lost on how to structure them and where to add them. I think these would go in the integration tests, with some cut down .csproj files, but I'm not sure.

@vgeronimos vgeronimos marked this pull request as ready for review February 21, 2024 05:11
@vgeronimos vgeronimos force-pushed the group-conditions-for-sdk-projects branch 2 times, most recently from 76c84ac to 227562f Compare March 7, 2024 23:27
@vgeronimos vgeronimos force-pushed the group-conditions-for-sdk-projects branch from 227562f to 25a809e Compare March 8, 2024 04:08
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.

Group conditions for dotnet sdk projects
1 participant