Question

I realize that it's been asked and answered that Visual Studio does not support CIL/MSIL projects. The MSBuildContrib project has an ILASM task which allows you to compile IL files at build time.

Googled came up empty on examples for how to use this task.

Are there any examples of using ILASM as part of a Visual Studio solution? I realize that #develope and ILIDE support CIL... the objective here is to compile some CIL files as part of a Visual Studio solution.

Was it helpful?

Solution

You could add a "makefile project". The template is under Visual C++, General. This project type allows you to specify custom build commands for the Build, Clean and Rebuild actions. The environment will be setup automatically so you don't have to mess with paths. The C++ IDE also supports creating a custom build rule so you can automatically trigger the right tool (ilasm.exe) from the file name extension (.il).

That's however about as good as it gets. There is no automatic mapping of multiple .il files in the project to a single build command. Writing an nmake.exe makefile is required to get that. And beware that custom build rules support got broken in vs2010.

OTHER TIPS

I gave Hans credit for answering this question, but after some experimentation I've got a solution which comes slightly closer to home:

HOW TO COMPILE CIL/MSIL INSIDE VISUAL STUDIO

The following hack gets you a project which:

  • Respects the Debug vs. Release build configuration in Visual Studio.
  • Optionally signs the resulting CIL assembly with the key file set up in the project preferences.
  • Can be added to source control.

Follow these steps:

  1. Create an empty C# classs library
  2. In the solution folder, right click the project and choose "unload project"
  3. Right click the unloaded project and choose "edit project"
  4. In the csprof file, scroll down to the bottom, and find the line which says "Import ... Project="$(MSBuildBinPath)\Microsoft.CSharp.targets", and replace it with the code at http://pastebin.com/KEJtyQLu (copied below)

Here's the XML:

  <Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" />

  <Target Name="CreateManifestResourceNames" />

  <Target Name="CoreCompile" Inputs="$(MSBuildAllProjects);@(Compile);" Outputs="@(IntermediateAssembly);$(NonExistentFile);">
    <GetFrameworkPath>
      <Output TaskParameter="Path" PropertyName="FrameworkPath" />
    </GetFrameworkPath>

    <PropertyGroup>
      <IlAsmCommand>&quot;$(FrameworkPath)\Ilasm.exe&quot; /NOLOGO /DLL /OUTPUT:&quot;@(IntermediateAssembly)&quot; </IlAsmCommand>
    </PropertyGroup>

    <PropertyGroup Condition=" '$(Configuration)' == 'Debug' " >
      <IlAsmCommand>$(IlAsmCommand) /DEBUG </IlAsmCommand>
    </PropertyGroup>

    <PropertyGroup Condition=" '$(Configuration)' == 'Release' " ><IlAsmCommand>$(IlAsmCommand) /OPTIMIZE </IlAsmCommand></PropertyGroup>

    <PropertyGroup Condition=" '$(AssemblyOriginatorKeyFile)' != '' " >
      <IlAsmCommand>$(IlAsmCommand) /KEY:&quot;$(AssemblyOriginatorKeyFile)&quot; </IlAsmCommand>
    </PropertyGroup>

    <Exec Command="$(IlAsmCommand) @(Compile->'&quot;%(FullPath)&quot;', ' ')" 
          Outputs="@(IntermediateAssembly)" />

    <CallTarget Targets="$(TargetsTriggeredByCompilation)" Condition="'$(TargetsTriggeredByCompilation)' != ''" />

  </Target>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top