RefFile 0.2.0

dotnet add package RefFile --version 0.2.0
                    
NuGet\Install-Package RefFile -Version 0.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RefFile" Version="0.2.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RefFile" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="RefFile">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RefFile --version 0.2.0
                    
#r "nuget: RefFile, 0.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RefFile@0.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RefFile&version=0.2.0
                    
Install as a Cake Addin
#tool nuget:?package=RefFile&version=0.2.0
                    
Install as a Cake Tool

RefFile

NugetShield

A generator for .NET 10 file-based apps, designed to reference external source files.

This generator allows you to reference another file and include its contents in the build.
Since multi-file support for file-based apps is expected to be added in .NET 11, this is intended as a temporary workaround until then.
Note that this generator assumes the referenced file is C# source code.
It is not valid for other types of files.

Usage

Add the RefFileAttribute to the assembly and specify the referenced filename as its argument.
The filename is interpreted as a relative path from the file where the attribute is declared.

Important note: any file-based apps directives written at the beginning of the referenced file will be removed.
Therefore, directives such as #:package or #:property inside the referenced file will have no effect.

Example

  • common.cs

    #:package Humanizer.Core@3.0.1
    // File-based directives within referenced files will be deleted.
    using Humanizer;
    
    public record CommonData(long Value)
    {
        public void Print() => Console.WriteLine(this.Value.ToMetric(decimals: 2));
    }
    
  • app.cs

    #!/usr/bin/env -S dotnet run --file
    #:package RefFile@0.2.0
    // Package references should be written in the main file.
    #:package Humanizer.Core@3.0.1
    
    [assembly: RefFile("common.cs")]
    
    var data = new CommonData(123456);
    data.Print();
    
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.0 702 12/1/2025