weaving .net assemblies with fody
DESCRIPTION
This presentation is about Weaving .NET assemblies with Fody. Manipulating the IL of an assembly as part of a build requires a significant amount of plumbing code. This plumbing code involves knowledge of both the MSBuild and Visual Studio APIs. Fody attempts to eliminate that plumbing code through an extensible add-in model.TRANSCRIPT
WEAVING .NET ASSEMBLIES WITH FODY
ANURAJ P
@anuraj
www.dotnetthoughts.net
Weaving .NET assemblies with Fody - www.dotnetthoughts.net
WHAT IS CODE (IL) WEAVING?
Weaving refers to the process of injecting functionality into an existing program. Modifying an existing .NET assembly requires the following tasks to be done:
1. Injection of the MSBuild task into the build pipeline
2. Resolving the location of the assembly and pdb
3. Abstracts the complexities of logging to MSBuild
4. Reads the assembly and pdb into the Mono.Cecil object model
5. Re-applying the strong name if necessary
6. Saving the assembly and pdb.
These tasks are performed by an IL reader/writer, excepted the task 3 (detection of injection points), which is typically the task of the code weaver.
Weaving .NET assemblies with Fody - www.dotnetthoughts.net
WHAT IS FODY?
An Extensible tool for weaving .NET assemblies.
Manipulating the IL of an assembly as part of a build requires a significant amount of plumbing code. This plumbing code involves knowledge of both the MS Build and Visual Studio APIs. Fody attempts to eliminate that plumbing code through an extensible add-in model.
It uses Mono.Cecil and an add-in based approach to modifying the IL of .NET assemblies at compile time.
Weaving .NET assemblies with Fody - www.dotnetthoughts.net
HOW FODY WORKS?
.NET CodeMS Build (Visual Studio)
MSIL
FodyIL WeavingModified IL
Weaving .NET assemblies with Fody - www.dotnetthoughts.net
ADVANTAGES OF FODY
1. Many pre-built weavers
2. Uses Mono.Cecil
3. Integrates into Build process and works on build servers as well.
4. Leaves no references *
5. Versatile - .Net 3.5 - .Net 4.5, Mono, PCL, Windows Phone 7 & 8, Windows Store apps
Weaving .NET assemblies with Fody - www.dotnetthoughts.net
SOME USEFUL FODY ADD-INS
1. EmptyConstructor Adds an empty constructor to classes even if a non empty one is defined.
2. EmptyStringGuard Adds empty string argument checks to an assembly.
3. Fielder Converts public fields to public properties.
4. Janitor Simplifies the implementation of IDisposable.
5. NullGuard Adds null argument checks to an assembly
6. PropertyChanged Injects INotifyPropertyChanged code into properties.
Weaving .NET assemblies with Fody - www.dotnetthoughts.net
DEMO
Weaving .NET assemblies with Fody - www.dotnetthoughts.net
WRITE YOUR OWN FODY ADD IN
You can write your own Fody add in.
Basic solution can be found here https://github.com/Fody/BasicFodyAddin
Weaving .NET assemblies with Fody - www.dotnetthoughts.net
LINKS
Fody project - https://github.com/Fody/Fody
Basic Fody Add in - https://github.com/Fody/BasicFodyAddin
Weaving .NET assemblies with Fody - www.dotnetthoughts.net
QUESTIONS?
Weaving .NET assemblies with Fody - www.dotnetthoughts.net
THANK YOU