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.
-
Install the NuGet packages
Fody
andAbsence.Fody
. InstallingFody
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 ofFody
andAbsence.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.
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.
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 { }
}
Issues and pull requests are welcome to help this repository be the best it can be.
This repository falls under the MPL-2 license.