feat: Add automatic .csproj/.fsproj project scanning and Bazel target generation#528
feat: Add automatic .csproj/.fsproj project scanning and Bazel target generation#528scottpledger wants to merge 1 commit intobazel-contrib:masterfrom
Conversation
56e210e to
13c6418
Compare
|
This is basically ready, but I need bazelbuild/bazel-central-registry#7387 to go in, along with a follow-up release to be published so I can drop the |
13c6418 to
6855a1f
Compare
|
Thanks for taking your time to add this. I'll take a look as soon as I can, am busy with other things at the moment. |
|
No problem! Totally understand needing some time on this one - it's rather large. To answer your question, I wouldn't mind using Gazelle for it, but that requires devs to make sure they run it whenever csproj/fsproj files change. My hope with this is to provide (slightly) better IDE support by allowing both IDEs and Bazel to read the csproj/fsproj directly and use them as the primary "source of truth". I'm also considering trying to add native NuGet support now that xml.bzl exists to parse it, if that's something you'd be open to. |
|
Hey @purkhusid! Just wanted to bump this :) |
|
I've not forgotten. Sorry about the delay. I'm just swamped with various work/life things. I'll see if I can make some time this week. |
|
This is awesome! I'll be excited to use this. |
|
I do like the ease-of-use of these rules but at the same time I am a bit skeptical about the repository rule approach since it does mean that the extension has to be recalculated every time a project file changes and I'm not sure how that is going to perform in larger repositories. I'm thinking that maybe we could mark these rules as experimental for a while and separate them more from the base rules if possible. This is mainly because I don't foresee me being able to help maintain this extension for the time being but at the same time I see that value in trying this out. Could you do the following:
I would be comfortable with merging this if we manage to de-couple it completely form the base rules for the time being. It might even make sense at some point to just provide these rules as a separate module that could be pushed to the Bazel registry. |
There was a problem hiding this comment.
I don't think we need e2e test for each TFM for the auto rules. How about just one e2e test with multiple projects instead?
e2e/net10.0/MODULE.bazel
Outdated
| path = "../..", | ||
| ) | ||
|
|
||
| bazel_dep(name = "xml.bzl", version = "0.2.2") |
There was a problem hiding this comment.
This should not be needed if the base module has xml.bzl as a non-dev dependency.
e2e/net8.0/MODULE.bazel
Outdated
| path = "../..", | ||
| ) | ||
|
|
||
| bazel_dep(name = "xml.bzl", version = "0.2.2") |
There was a problem hiding this comment.
This should not be needed if the base module has xml.bzl as a non-dev dependency.
e2e/net9.0/MODULE.bazel
Outdated
| path = "../..", | ||
| ) | ||
|
|
||
| bazel_dep(name = "xml.bzl", version = "0.2.2") |
There was a problem hiding this comment.
This should not be needed if the base module has xml.bzl as a non-dev dependency.
e2e/smoke/MODULE.bazel
Outdated
| path = "../..", | ||
| ) | ||
|
|
||
| bazel_dep(name = "xml.bzl", version = "0.2.2") |
There was a problem hiding this comment.
This should not be needed if the base module has xml.bzl as a non-dev dependency.
e2e/web_sdk/MODULE.bazel
Outdated
| path = "../..", | ||
| ) | ||
|
|
||
| bazel_dep(name = "xml.bzl", version = "0.2.2") |
There was a problem hiding this comment.
This should not be needed if the base module has xml.bzl as a non-dev dependency.
examples/MODULE.bazel
Outdated
| path = "..", | ||
| ) | ||
|
|
||
| bazel_dep(name = "xml.bzl", version = "0.2.2") |
There was a problem hiding this comment.
This should not be needed if the base module has xml.bzl as a non-dev dependency.
There was a problem hiding this comment.
Delete this file. We don't commit the lockfile since we test the rules using multiple Bazel versions.
6855a1f to
3ef7af3
Compare
So...... Yeah, after some tweaking and revisiting my initial designs/assumptions on this, I was able to move this into its own companion module! https://github.com/scottpledger/rules_auto_dotnet contains this feature now, and should work as a partner project to Having said that, if you ever want me to recombine these or if you'd like to help/have help with maintenance, let me know. My company is largely a C#/web shop that has adopted Bazel for the web stuff (npm/js builds), and we're just starting to look at using it for C# builds, and I'd love to help as much as I can! |
|
I think this is a good solution for the time being. I want to test out your module on my company's codebase as well to see how it works. And of course all future contributions are welcome! |
Summary
This PR introduces a major new feature that allows existing
.csprojand.fsprojfiles to serve as the source of truth for Bazel builds. Thedotnetmodule extension now supports ascan_projects()tag that automatically discovers .NET project files in the workspace and generates corresponding Bazel targets, enabling seamless integration with existing IDE infrastructure.Motivation
Maintaining both
.csproj/.fsprojfiles (for IDE support) andBUILD.bazelfiles (for Bazel builds) creates duplication and synchronization challenges. This feature allows developers to keep their existing .NET project files and have Bazel automatically derive build targets from them.Features
Automatic Project Scanning
.csprojand.fsprojfilesxml_tools).bzlfiles withauto_dotnet_targets()macros in the generateddotnet_projectsrepositoryToolchain Validation
TOOLCHAIN_COVERAGE.mdsummary in the@dotnet_projectsrepository (mostly for debugging)NuGet Package Collection
PackageReferenceelements across projectspaket.dependencies.generatedto bootstrap Paket integrationIDE Support for Generated Code
dotnet_generated_propsrule for syncing Bazel-generated sources with IDEswrite_source_filefrombazel-libto maintain.propsfilesCross-Platform Support
findvs PowerShell/cmd)Usage
Configuration Options
New Dependencies
.csproj/.fsprojfilesBreaking Changes
None - this is an additive feature. Existing
rules_dotnetusage is unaffected.File Change Detection
Bazel automatically re-scans when:
.csproj/.fsprojfiles are modifiedManual sync required (
bazel sync --only=@dotnet_projects) when:Test Plan
parser_test.bzl)generator_test.bzl)nuget_collector_test.bzl)tfm_utils_test.bzl)e2e/dotnet_projects_net8.0/)e2e/dotnet_projects_net9.0/)e2e/dotnet_projects_net10.0/)