What tools do postcompilation modification of IL?

A recent mention of PostSharp reminded me of this:

Last year, when I worked, we thought of using PostSharp to inject tools into our code. This was in the Team Team Server Build / Continuous Integration environment.

Thinking about it, I felt how PostSharp works - it edits IL, which is generated by compilers. It bothered me a little.

I was not so concerned that PostSharp did not do its job correctly; I was worried about what I first heard about such an instrument. I was worried that other tools might not take this into account.

In fact, as we moved forward, we had some problems with PostSharp getting confused about which folder the original IL was in. This violated our builds. Apparently, this is due to a conflict with the goal of MSBUILD, which solves project links. The conflict appears to be related to PostSharp using a temporary directory to store unmodified versions of IL.

Anyway, I didn't have StackOverflow to reference then! Now that I do this, I would like to ask you all if you know any other tools that edit IL as part of the build process; or Microsoft takes this tool to an account in Visual Studio, MSBUILD, Team Build, etc.


Update: Thanks for the answers.

The bottom line is that, at least with VS 2010, Microsoft really needs to know that this can happen. Therefore, if there are problems in this area in VS2010, Microsoft may share the blame.

+5
c # postsharp intermediate-language
source share
4 answers

I know that Dotfuscator, code obfuscator, modifies the IL assembly of assembly assemblies and is used in many assembly processes.

IL has been modified not only to obfuscate and protect the code, but also to add additional features to your applications (see our blog posts (PreEmptive) in Runtime Intelligence here .

In addition, Microsoft Common Compiler Infrastructure has the ability to read in assemblies, modify and rewrite them. See CodePlex for a project.

+3
source share

I know about Mono.Cecil , a framework library that extends the System.Reflection toolkit used by the Lin Fu project.

I'm not sure about the support of the build process, you should check their size.

+4
source share

.NET 4.0 includes a Microsoft Research code contract project that fulfills runtime (and some compilation) requirements for the pre / post conditions of your methods. Assertions are implemented in the library, and the .NET compiler emits pre / post conditions as method calls in IL. However, since contracts are usually indicated at the beginning of a method, the second tool needs to rewrite IL to correctly place statements and locations.

EDIT:

  • cccheck is a tool that runs post-build and is a static validator that validates contracts at compile time
  • ccrewrite is a tool that runs post cccheck, rewrites IL, and generates runtime checks from contracts

(I can not find additional technical information about these tools)

I have not used Visual Studio 2010 yet, but I saw a demonstration of the Code Contracts feature and is integrated into the IDE build process. cccheck should always be run, returning code if contracts are present in the inline assembly. If they are present, the code will mean that ccrewrite should work.

+4
source share

Fody is an extensible tool for weaving .net collections based on the plugin architecture.

+1
source share

All Articles