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

Centrally manage dependencies and its versions #96

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

Nirmal4G
Copy link
Contributor

@Nirmal4G Nirmal4G commented Jan 19, 2022

Info

Fixes CommunityToolkit/WindowsCommunityToolkit#4180
Extracted from CommunityToolkit/WindowsCommunityToolkit#4181

Changes

  • Use Static Graph restore when applicable.
  • Manage Packages Centrally using NuGet's CPVM feature.

Know more about NuGet's Central Package Version Management (CPVM) feature.

Currently, NuGet package references are spread across project files. It is difficult to track versions and upgrade them properly. This patch enables NuGet's upcoming feature to manage package versions centrally using Directory.Packages.props with the following item spec to store a package version.

  <ItemGroup>
    <PackageVersion Include="Vendor.Awesome.Package" Version="11.0.0" />
  </ItemGroup>

PR Checklist

  • Created a feature branch in your fork
  • Based off latest main branch of toolkit
  • PR doesn't include merge commits (always rebase on top of our main)
  • Header has been added to all new source files (ran build/Update-Headers.ps1)
  • Tested code with current supported SDKs
  • Contains NO breaking changes
  • Code follows all style conventions

Notes

  • Rebase merge if possible.
  • Wait for my refactor PR to be merged!
  • When merging, please update the commit title to PR title instead of the default Merge pull request #xxxx from repo/branch, and commit message to either PR message or messages of individual commits. The auto-merge option does this by default.

@Nirmal4G Nirmal4G force-pushed the feature/nuget-cpvm branch 3 times, most recently from 04a06d1 to 5767d37 Compare January 21, 2022 21:55
Copy link
Member

@Sergio0694 Sergio0694 left a comment

Choose a reason for hiding this comment

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

I know this is work in progress, but please don't have these changes based on top of the other branch, let's keep PRs smaller. I'm saying this because I can't say when/if that base PR will get merged, so I don't think it's worth it to block this until that one is resolved, as it's unrelated 🙂
Thanks!

@Nirmal4G
Copy link
Contributor Author

Nirmal4G commented Jan 21, 2022

There's a change in how we pack the SourceGen project into the parent project in this patch. I hope to create a new PR for that change but I will test it here before I do that. That change was made in response to this feature.

I don't want to update the workaround just to unblock the PR. This patch can wait as it needs support from VS IDE. As far as I know, v17.2 is the target to enable central package versioning in the NuGet PM UI.

@Nirmal4G
Copy link
Contributor Author

Please merge this only after merging #85 and #220 as it depends on some changes from those PRs. All the 3 PRs are correlated since the changes cascade into the other.

@Nirmal4G Nirmal4G marked this pull request as ready for review April 17, 2022 08:00
@Nirmal4G Nirmal4G force-pushed the feature/nuget-cpvm branch 5 times, most recently from cd49f35 to bfe8944 Compare April 19, 2022 11:39
@Nirmal4G Nirmal4G force-pushed the feature/nuget-cpvm branch 2 times, most recently from ba97f5e to b272630 Compare May 17, 2022 10:12
@Nirmal4G Nirmal4G requested a review from Sergio0694 May 17, 2022 11:08
Copy link
Contributor

@hymccord hymccord left a comment

Choose a reason for hiding this comment

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

The PR is doing more than it states. Even if you leave off the first three commits which are part of your refactor. You're tackling two different issues

  1. Building to a common path (a large portion of this PR)
  2. Moving to centrally managed package versions

I think you should get feedback on 1. before implementing it as changing the build path to something you want is subjective. What's wrong with the current system?

I've seen a lot of Microsoft repos have a common output that falls under artifacts/. Pretty much anything using the Arcade SDK. I've never seen a convention of outputting to ~build and ~packages (I searched across GitHub and only found your personal projects using it).

artifacts/bin, artifacts/obj, artifacts/packages, etc..

azure-pipelines.yml Outdated Show resolved Hide resolved
azure-pipelines.yml Outdated Show resolved Hide resolved
@Nirmal4G
Copy link
Contributor Author

Nirmal4G commented Jun 6, 2022

Initially, I wanted just two PRs, one for refactoring and another for central versioning but MVVM Changes are important enough to warrant an issue and PR of their own. But I can create a separate PR for common paths, if needed.

We can do artifacts if that's preferred strongly but having a build, publish and packages top-level directories makes sense, IMEX. And the tilde ~ symbol literally makes it top-level in the directory listing. That's why I choose this pattern.

My thoughts… tl;dr M$FT is lazy!

I experimented with Arcade SDK and found it lacking in so many ways, especially the defaults could've been better, IMHO! Explaining all the reasons why current defaults of .NET SDK is bad for large scale projects, would either need a blog series or a presentation talk!! 😂 Yeah, it's that bad!!! 🤦

And before you go on about how Microsoft uses Arcade for entire .NET Foundation projects, let me tell you, Arcade is simple defaults, low-config, too-many things, highly opinionated and tuned specific to only Microsoft managed .NET Foundation projects. It's goal is to take what M$FT repos would need and put them in a shared package so that everyone who needs it uses it without maintaining their own solution. It's not for general public.

I prefer M$FT products over others anyday but not a fan! I used to in the days of XP, Vista and 7 but not now. They have become lazy!

One thing you have to know about M$FT is that they do relatively minimal enough to get the project going since it requires a low maintainance cost, less work. It's how most corporates work and M$FT does it even less than others. They don't plan far ahead which is why most of their initiatives fail after a point in time.

It's like this, with M$FT, the final things they produce, be it software or hardware, they don't scale well, since the requirements are limited even though the ideas and design are good. Also, Exceptions are not examples!!

@Nirmal4G Nirmal4G force-pushed the feature/nuget-cpvm branch 4 times, most recently from d3a9294 to f612708 Compare June 9, 2022 19:06
@Nirmal4G Nirmal4G marked this pull request as draft June 9, 2022 19:20
@Nirmal4G Nirmal4G force-pushed the feature/nuget-cpvm branch 4 times, most recently from 0829810 to 4f5f5c3 Compare January 14, 2023 19:59
- Rename `build` folder to `eng`:
  - This is a standard build infra directory used in official dotnet projects.

- Rename NuGet Icon to `Icon.png`:
  - This is no longer used as a public reference point for NuGet icon URL.
  - Also, Icon URL is deprecated. Hence, it's safe to change.

- Normalize casing for `ReadMe.md`:
  - Repository information files such as ReadMe, License, etc... are only UPPER_CASE
    if they are without an extension. With extension, the casing becomes PascalCase
    or Kebab-Case. The primary reason is attention to the presentation of file names.
  - Do Kebab-Case when a phrase is presented. E.g., `Code-of-Conduct.md`.

- Rename solution file to `CommunityToolkit.sln`:
  - The `dotnet` seems implied and also doesn't stand-out in the file list because of the lower casing and `d` char.
  - Spaces are a main issue when doing automation (_like using `*.sln` in build scripts and in URLs it adds `%20`_).

- Move `toolkit.snk` file to `eng` sub-directory.
- Remove un-needed and deleted files from solution.

- Update Git Ignore entries to latest from upstream.
- Indent text in `ThirdPartyNotices.txt` with spaces instead.
- Fix the text flow warping in the MSBuild Console logging.
- Use checked version properties instead of hard-coded checks.
- Update the structure of the projects list in the Solution file.

- Refactor Roslyn multi-targeting to use multiple projects
  in the same project directory without using Shared projects.
  This refactoring is made in preparation for the solution to use
  the NuGet's CPVM (Central Package Versions Management) feature.
  This also slightly improves IDE load time and Build performance.
- Move the T4 MSBuild logic to a new file.
- Move Public Key to a new file 'toolkit.spk'.
- Move MSBuild logic to near-by `Directory.Build.{props|targets}` files.
Follow the following rules:

- SOF (_Start Of File_) Imports,
- Core properties, Package properties, build properties,
- Build items, Resource items, Content items, Misc. items,
- In-place Imports, Choose (_elements within follows outer sort order_)
- `ProjectReference` items, `PackageReference` items,
- Targets and Properties and Items close to said Targets,
- EOF (_End Of File_) Imports.

Where there's a condition by target properties, we should group them together under `Choose`.
For multiple target values, we should sort them by the order in which they are defined.
And the order in which they should be defined is either ascending or descending in terms of compatibility layering.
- Add necessary guard to check for pack.
- Remove redundant properties and values.
- Remove and adjust quotes in property functions.
- Use wildcards to generalize and reduce items declared.
- Remove redundant comments.
- Add missing comments on certain code blocks.
- Format code in comments with proper quote style.
Some property groups have conditions that also self-explain their purpose.
So, Add labels to bare property groups only to differentiate among themselves.
Then, when contributors add any additional properties, they'll know where to put them.
When the '$(IncludeContentInPack)' property is false, files specified via '@(None)', '@(Content)' items
are excluded from the NuGet package. Adding '@(PackageFile)' items directly to '%(_PackageFiles)' item
via the following target ensures that they will always be included in the package.

So, Use '%(PackageFile)' item to always include files in the package. By default, they are included in
the root of the package but can be overridden via '%(PackageFile.TargetPath)' metadata.
Previously, static output path to the MVVM SourceGen assembly was used to pack the MVVM project.
This leads to error when OutputPath was updated dynamically when testing or in forks.

So, here, we'll update the build so that the SourceGen build outputs will be dynamically packed.
- MSBuild Item update logic within target broke during 17.3-17.4!

  Previous logic referencing direct Item names worked fine before,
  but now needs a proxy/temporary item in order to process the includes.
  Same with the undefined Metadata, previously it returned empty string for
  items with the metadata undefined but now throws error. This may be correct
  behavior for items under target but this difference hinders sharing logic
  within and out of targets. This has a side-effect of needing to specify
  fully qualified name "%(Item.Metadata)" which makes it verbose.
The new Output paths point to...

Build    :  `build\{bin,obj}`
Pack     :  `packages`
Publish  :  `publish`
Restore  :  `build\ext`
Test     :  `build\TestResults`

with-in the repository root directory.
Manage Packages Centrally using NuGet's CPVM feature.
This uses `Directory.Packages.props` to store the package versions in one file.
- Features: Strict
  Setting this ensures that we won't fall into compiler bugs when using latest features.

- LangVersion: Latest
  Setting this ensures that we always compile against latest version against the using SDK.
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.

[Build] Centrally manage NuGet package versions
3 participants