Skip to content

Emik03/Absence.Fody

Repository files navigation

Absence.Fody

NuGet package License

This is an add-in for Fody which lets you trim unused private/internal types during compile-time.

This project has a dependency to Emik.Morsels, if you are building this project, refer to its README first.



Installation

  • Install the NuGet packages Fody and Absence.Fody. Installing Fody explicitly is needed to enable weaving.

    PM> Install-Package Fody
    PM> Install-Package Absence.Fody
    
  • Add the PrivateAssets="all" metadata attribute to the <PackageReference /> items of Fody and Absence.Fody in your project file, so they won't be listed as dependencies.

  • If you already have a FodyWeavers.xml file in the root directory of your project, add the <Absence /> tag there. This file will be created on the first build if it doesn't exist:

<Weavers>
    <Absence />
</Weavers>

See Fody usage for general guidelines, and Fody Configuration for additional options.

Configuration

You can add an Except attribute to exclude namespaces or types separated by any amount of whitespace:

<Weavers>
    <Absence Exclude="Foo DoNotExcludeMe
                      Do.Not.Exclude.Me" />
</Weavers>

Types may either be fully qualified, or not at all. Partially qualified names are not supported due to potential ambiguity.

Example

What you write:

public class Public 
{
    public class NestedPublic { }
    
    [ImplicitlyUsed]
    class NestedPrivateWithAttribute { }
    
    class NestedPrivate { }
}

[ImplicitlyUsed]
class InternalWithAttribute
{
    public class NestedPublic { }
    
    [ImplicitlyUsed]
    class NestedPrivateWithAttribute { }
    
    class NestedPrivate { }
}

class Internal 
{
    public class NestedPublic { }
    
    [ImplicitlyUsed]
    class NestedPrivateWithAttribute { }
    
    class NestedPrivate { }
}

What gets compiled:

public class Public 
{
    public class NestedPublic { }
    
    [ImplicitlyUsed]
    class NestedPrivateWithAttribute { }
}

[ImplicitlyUsed]
class InternalWithAttribute
{
    public class NestedPublic { }
    
    [ImplicitlyUsed]
    class NestedPrivateWithAttribute { }
}

Contribute

Issues and pull requests are welcome to help this repository be the best it can be.

License

This repository falls under the MPL-2 license.