When I'm using aspnet_compiler.exe to pre-compile my website, I see a cvtres.exe process along with csc.exe. I'm assuming this is part of the .NET compilation process, and would also show when compiling my .NET assemblies. What is cvtres.exe and what does it do?
Windows Resource to Object Converter (CvtRes.exe) (from here)
As to what it does, well... I guess that it converts Resources to Objects.
Edit: As Scott says,
to be more specific, it is part of the C++ toolchain to turn resource
files (.res) in to compiled objects that can be linked using the
linker.
I was looking for something official that explains it, but the best I could find is an old support article that mentions it. Hope it helps!
What happens when I compile .NET source code (c# or vb) to .exe file? I wish to understand the process which happens during making an exe file and have viewed several questions regarding reverse engineering and decompilation (for example, How do I decompile a .NET EXE into readable C# source code? and What happens when user click .NET assembly (EXE)?)
Thanks in advance
The managed execution process includes the following steps
Choosing a compiler
To obtain the benefits provided by the common language runtime, you must use one or more language compilers that
target the runtime.
Compiling your code to MSIL
Compiling translates
your source code into Microsoft intermediate language (MSIL) and
generates the required metadata.
Compiling MSIL to native code
At execution time, a just-in-time (JIT) compiler translates the MSIL into
native code. During this compilation, code must pass a verification
process that examines the MSIL and metadata to find out whether the
code can be determined to be type safe.
Running code
The common language runtime provides the infrastructure that enables execution to
take place and services that can be used during execution.
look here for detailled information: http://msdn.microsoft.com/en-us/library/k5532s8a.aspx
you may take a look on the following links that i think they are usefull,
1- Image Describing CLR.
2- Wikipedia Description of .NET Framework
3- .Net Framework Architecture
How I can get IL code of C# code ? Can I do this with a extern library, or exists internal functions ?
EDIT : I want to show IL code in my application with a MessageBox.
Programmatically? You can use reflection to get a MethodInfo, and then call MethodBase.GetMethodBody to get the body. From the MethodBody, you can call GetILAsByteArray amongst other things.
Of course, if you just want to examine it yourself, there's Reflector, dotPeek, ildasm (part of the .NET SDK) and no doubt other tools...
Use IL Disassembler like this:
c:\il>csc Class.cs
c:\il>ildasm /output=Class.il Class.exe
you'll both have the IL & the exe.
Just open a Visual Studio command prompt and type ildasm - with ildasm you can open up any assembly and show the generated IL.
Take a look at LinqPad, it has options to see IL.
OR,
Start -> Programs -> Microsoft .NET Framework SDK (Version) -> Tools -> MSIL Disassembler
It's quite an old question, but I'd like to add some accuracies.
GetMethodBody() will give you at best a byte array, which you need to parse manually (which can be painful since some opcodes have two bytes) to get a human readable text.
I just want to mention ILSpy as an alternate solution.
It's open source, meaning you can debug it and integrate with it in your solution.
When importing a COM library (either directly with tlbimp, or indirectly with visual studio add reference dialog,) is there a way to generate C# source code instead of a binary interop assembly, like Interop.Word.dll, for example?
UPD: Reflector is bad idea. Problem is that for the com interface is not only a signature, but the order of the members. Reflector this order is violated
I would go ahead and generate the interop assembly using TLBIMP, and the use Reflector to disassemble it. The interop assembly has no actual implementation code, as you will see. You can then just copy and paste the code (or the CoClasses and interfaces you need) into a new .cs file in your project.
You cannot generate C# directly, but if your real problem is that you have a need to tweak the interop library then you might have better luck using the CLR Interop team's custom TLBIMP tool on codeplex - it's pretty flexible and you have full source [to it.]
http://clrinterop.codeplex.com/releases/view/17579
Update: If you're really trying avoid shipping binaries, then you could feasibly integrate the above tool (in source format) into your project so that you generate this interop library at runtime. Result? No binaries to ship.
In general it cannot be done. C# does not support all possible constructs needed to create a working interop assembly. You cannot add e.g. attributes to return types or method parameters in C# although they are needed sometimes to help the marshaller to correctly translate some C++ types.
Yours,
Alois Kruas
I'm new to .NET C# programming. I'm following few books. It is said that instead of compiling C# code directly to machine code, it is converted into an intermediate language (called MSIL aka CIL). But when I compile, I get an exe/dll file.
Is this MSIL/CIL contained in these exe/dll files?
I want to see that intermediate language code, just to get feel for its existence. How do I view it?
They are calling this exe/dll file an assembly. Are they using this "fancy word" just to differentiate these from the exe/dll files that contain native/machine code?
Yes it is, more exactly in the .text section of the PE file (portable executable = *.exe or *.dll). More information can be found here.
The best choice is to use ILSpy (Reflector is no longer free). It's a free disassembler that can dissassemble your assembly into MSIL but also C#, VB (to some extent). The .NET Framework SDK contains ILDasm, which is the official MSIL dissasembler.
Basically yes. An assembly is a file that contains MSIL code and corresponding metadata. This is not restricted to PE files per se, but all current CLR implementations use them.
If I may recommend a good book on that matter too, it's Expert .NET 2.0 IL Assembler by Serge Lidin. He's the guy who designed MSIL.
One of my favorite ways to see IL for a snippet of C# is to use the free LINQPad tool. After entering some code and choosing "C# statements" at the top (or "C# Program", whichever suits), click the "IL" button under the code entry area, and you will see the generated IL.
Using LINQPad for this is much more convenient than loading up Visual Studio or running the compiler from the command line, then loading up ILDASM and opening the .il file with a text editor.
If you want it online, .NET Fiddle is excellent. Just paste your code and click View IL option at the top right.
Another option: Use ReSharper
Source / IL synced view: left blue background line corresponds with right IL Block
In Visual Studio:
Choose ReSharper | Windows | IL Viewer
or Context Menu: Navigate | IL Code
Supports synced view of Source Code and IL - when you click on a statement in source, the corresponding block in IL is highlighted (and vice versa). Displays descriptions for IL from Microsoft Developer Network and "Common Intermediate Language (CIL) instruction set" from ECMA standard specification.
see Viewing Intermediate Language (IL) in Resharper Help. Picture above is from Resharper Help.
Free option is to use Jetbrains dotPeek
see also: "Exploring Intermediate Language (IL) with ReSharper and dotPeek", by Maarten Balliauw, January 19, 2017 - Jetbrains Blog
sharplab is an online tool, great for simple use cases. Type your code on the left, IL shows up on the right.
I believe that they are called "assemblies" because an assembly is a set of modules, assembled together by a manifest.
(source: microsoft.com)
See Assembly Contents for details.
Yes it is in assembly.
You need .NET Reflector or ILDasm.
More details on assembly check HERE.
P.S As you are following some books I will highly recommend you CLR via C#.
In many respects, .NET assemblies are similar to Java bytecode packages.
Yes. They also contain manifests and other data, but the CIL is part of the exe/dll.
Use ILDasm or Reflector - most people would say Reflector, as it is much more powerful. Both will show you what CIL was produced. Wikipedia has a list of all CIL instructions, for a better feel (it is assembly like).
I guess it is meant as an assembly of code. A good way to differentiate it from native.
I know this is an old question, and I'd prefer any of the tools above. However, in a pinch, there has been an MSIL viewer in the box with Visual Studio since at least Version 2005.
The tool is named ildasm.exe, and is located in the following folders after default Visual Studio installations:
Visual Studio 2005
"C:\Program Files (x86)\Microsoft Visual Studio 8\SDK\v2.0\Bin\ildasm.exe"
Visual Studio 2008
"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\ildasm.exe"
Visual Studio 2010
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\ildasm.exe"
For more information, see: "How to: View Assembly Contents" in the MSDN Library.
I have just spent a couple of hours searching for the best tool that could let me view the IL code directly inside Visual Studio.
The only solution I found so far is Msiler https://visualstudiogallery.msdn.microsoft.com/60fc53d4-e414-461b-a27c-3d5d2a53f637
it works quite well!
Otherwise the second best solution, but without visual studio integration, is JetBrains dotPeek, which is quite awesome to be honest.
From my experience the best source of IL-related knowledge is Andrew Troelsen “Pro C# and .NET Platform”. Starting from 3rd edition he has really, really outstanding chapter (approx 50 pages) on how to understand IL and even write your own code and use ILAsm. I’ve employed that information to investigate whether multiple inheritance exists in .NET world. Also you could try to employ some very interesting features in IL (e.g. filtering of exceptions which only exists in VB but not in C#).
I highly recommend to read that chapter.
Eventually, .NET Reflector is an enterprise standard for investigating IL code of assemblies and Richter's book is definitely "must read" stuff. But from other books like mentioned above you could reveal really useful things :)
Yes, each assembly in .NET world holds some IL code (alongsite with manifest) which could be viewed thru Reflector or ILDasm. Even more, Reflector could show you C# and VB optimized code. This means that any person could view the source code of an assembly and that's why in commercial products obfuscators are used.
I you want to view the intermediate language, Try downloading JustDecompile from Telerik (Which is currently free, requires a sign up though).
Drag in your DLL and choose IL from the drop down box at the top!
There is now another option. You can do this in VS Code with this extension built with Roslyn. This is currently limited to .NET Core.