weaving .net assemblies with fody

11

Click here to load reader

Upload: anuraj-p

Post on 26-Jun-2015

649 views

Category:

Software


2 download

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

Page 1: Weaving .net assemblies with Fody

WEAVING .NET ASSEMBLIES WITH FODY

ANURAJ P

@anuraj

www.dotnetthoughts.net

Page 2: Weaving .net assemblies with Fody

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.

Page 3: Weaving .net assemblies with Fody

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.

Page 4: Weaving .net assemblies with Fody

Weaving .NET assemblies with Fody - www.dotnetthoughts.net

HOW FODY WORKS?

.NET CodeMS Build (Visual Studio)

MSIL

FodyIL WeavingModified IL

Page 5: Weaving .net assemblies with Fody

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

Page 6: Weaving .net assemblies with Fody

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.

Page 7: Weaving .net assemblies with Fody

Weaving .NET assemblies with Fody - www.dotnetthoughts.net

DEMO

Page 8: Weaving .net assemblies with Fody

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

Page 9: Weaving .net assemblies with Fody

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

Page 10: Weaving .net assemblies with Fody

Weaving .NET assemblies with Fody - www.dotnetthoughts.net

QUESTIONS?

Page 11: Weaving .net assemblies with Fody

Weaving .NET assemblies with Fody - www.dotnetthoughts.net

THANK YOU