Skip to content

Conversation

@MichaelSimons
Copy link
Member

@MichaelSimons MichaelSimons commented Jan 29, 2025

Introduced two new constructs to encapsulated customizations to the generated artifacts.

  • Customizations.props - Automatically imported by the generated project. Use it for additive changes such as NoWarns or additional source files.
  • Customizations.cs - This is not automatically included by the generated project. Use it to add new types or members to partial classes.

The benefit of using these files is that they will be preserved when the packages are regenerated. These constructs are not intended to support all scenarios e.g. add an attribute to a property or tweak a nuspec.

I am open to suggestions on the names of these constructs.

A number of projects were updated to utilize these new constructs.

@MichaelSimons MichaelSimons requested review from a team and ViktorHofer January 29, 2025 18:16
@ViktorHofer
Copy link
Member

We briefly talked about this in chat. Manual edits to NuGet.config are hard to isolate into separate files but there don't seem to be many. For the Customizations.cs, this definitely helps with new types or new members. Changing member is unfortunately not possible unless we tell GenAPI to exclude certain members (which is possible) and then add them to that secondary file. I don't think that's a good use here though as it would mean that we would need to list those symbols separately for GenAPI.

Aside from that, this looks good and will definitely help with re-generating packages.

Comment on lines 2 to 5
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp1.1' or '$(TargetFramework)' == 'netstandard1.5'">
<!-- Needs additional APIs that don't exist in the contract. -->
<Compile Include="$(MSBuildThisFileDirectory)Customizations.cs" />
</ItemGroup>
Copy link
Member

Choose a reason for hiding this comment

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

It might be easier to just always import Customizations.cs files if they exist and put these TFM checks directly into that file. The roslyn repo often prefers that over conditioning in the project file and that worked great for them.

This would mean that the Customizations.cs would start with a #if NETCOREAPP1_1 || NETSTANDARD1_5 line.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, I originally thought this pattern would provide more flexibility but I don't think that is necessarily the case. The pattern you suggest reduces the onboarding maintenance/ease of use. I will make this change.

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed in 394218c

Copy link
Member

@mthalman mthalman left a comment

Choose a reason for hiding this comment

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

This is pretty slick.

@MichaelSimons MichaelSimons merged commit 3cdc6c1 into dotnet:main Jan 30, 2025
4 checks passed
@MichaelSimons MichaelSimons deleted the custom-infra branch January 30, 2025 14:48
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.

3 participants