Skip to content

Split C# NuGet into library and tool packages#6912

Merged
jkschneider merged 1 commit intomainfrom
jkschneider/csharp-dotnet-tool
Mar 10, 2026
Merged

Split C# NuGet into library and tool packages#6912
jkschneider merged 1 commit intomainfrom
jkschneider/csharp-dotnet-tool

Conversation

@jkschneider
Copy link
Copy Markdown
Member

@jkschneider jkschneider commented Mar 10, 2026

Summary

  • Split OpenRewrite.csproj into two projects: OpenRewrite.CSharp (library) and OpenRewrite.CSharp.Tool (tool). PackAsTool=true causes NuGet to place DLLs in tools/ instead of lib/, making types unavailable at compile time for downstream PackageReference consumers. Since the project was both a library and a tool, the packed .nupkg was unusable as a dependency.
  • OpenRewrite.CSharp (library) contains all SDK types (Recipe, CSharpVisitor, etc.), packable with DLLs in lib/ — this is what downstream projects reference via PackageReference.
  • OpenRewrite.CSharp.Tool (tool) contains just Program.cs with a ProjectReference to the library, packed with PackAsTool=true for dotnet tool install rewrite-csharp.
  • Added csharpPublishLocal Gradle task for local NuGet feed development (~/.nuget/local-feed/).
  • Simplified snapshot version logic to always use timestamps (removed -dev suffix for non-CI builds).

Test plan

  • Verify ./gradlew :rewrite-csharp:csharpPack produces both .nupkg files in dist/
  • Verify dotnet tool install works with the OpenRewrite.CSharp.Tool package
  • Verify PackageReference to OpenRewrite.CSharp resolves SDK types at compile time
  • Verify ./gradlew :rewrite-csharp:csharpPublishLocal publishes to ~/.nuget/local-feed/

PackAsTool=true causes NuGet to place DLLs in tools/ instead of lib/,
making types unavailable at compile time for downstream PackageReference
consumers. The OpenRewrite.csproj was both a library (SDK types like
Recipe, CSharpVisitor) and a tool (Program.cs for the RPC server), so
the packed .nupkg put everything in tools/ and was unusable as a
dependency.

Split into two projects:
- OpenRewrite.CSharp (library) — all SDK types, packable with DLLs in
  lib/ via PackageReference
- OpenRewrite.CSharp.Tool (tool) — just Program.cs with a
  ProjectReference to the library, packed with PackAsTool=true for
  dotnet tool install

Also adds a csharpPublishLocal task for local NuGet feed development and
simplifies the snapshot version logic to always use timestamps.
@jkschneider jkschneider force-pushed the jkschneider/csharp-dotnet-tool branch from 6425235 to 2b6dda3 Compare March 10, 2026 14:53
@jkschneider jkschneider merged commit 32095ac into main Mar 10, 2026
@jkschneider jkschneider deleted the jkschneider/csharp-dotnet-tool branch March 10, 2026 14:55
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant