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:
- Create an empty C# classs library
- In the solution folder, right click the project and choose "unload project"
- Right click the unloaded project and choose "edit project"
- 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>"$(FrameworkPath)\Ilasm.exe" /NOLOGO /DLL /OUTPUT:"@(IntermediateAssembly)" </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:"$(AssemblyOriginatorKeyFile)" </IlAsmCommand>
</PropertyGroup>
<Exec Command="$(IlAsmCommand) @(Compile->'"%(FullPath)"', ' ')"
Outputs="@(IntermediateAssembly)" />
<CallTarget Targets="$(TargetsTriggeredByCompilation)" Condition="'$(TargetsTriggeredByCompilation)' != ''" />
</Target>