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. |
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/)