Tools

File-Based Apps in .NET 11: Includes, Refs and CLI Package Management

Barret Blake
Tools

A practical walkthrough of how small file-based C# utilities grow in .NET 11: #:include for helper sources, the new #:ref for a separate assembly, and dotnet CLI commands that manage dependencies right against the file.

Key points

  • #:include FileReport.cs compiles a helper into the same app; neighbouring .cs files are not picked up automatically.
  • dotnet package add|list|remove --file writes and edits the #:package directive inside the C# file.
  • #:ref gives another C# file its own assembly; it needs #:property OutputType=Library since it has no entry point.
  • dotnet reference add|list|remove --file links an existing class library through the #:project directive.
  • Directives now accept quoted property values and MSBuild item metadata such as PrivateAssets=all on a package.
  • Publishing still defaults to Native AOT; opt out with #:property PublishAot=false, and glob includes disable the build cache.

Real-world use

  • Twenty-line repository utilities such as counting the Markdown files in a folder
  • A single-file tool that adds a NuGet package instead of being turned into a console project
  • A command-line helper that reuses an existing SharedTools class library instead of copying code

This summary was generated by the agent from the original post on Barret Blake. The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message