是否有任何从Visual Studio项目中编译CIL代码的示例

Mar*_*ark 5 il cil visual-studio ilasm

我意识到已经被问及并回答Visual Studio不支持CIL/MSIL项目.该MSBuildContrib项目有ILASM任务,它允许您编译IL文件在制作的时候.

关于如何使用此任务的示例,Google搜索结果为空.

是否有任何使用ILASM作为Visual Studio解决方案的一部分的示例?我意识到#develope和ILIDE支持CIL ......这里的目标是编译一些CIL文件作为Visual Studio解决方案的一部分.

Mar*_*ark 13

我回答这个问题时给了汉斯的信任,但经过一些实验,我得到了一个更接近家的解决方案:

如何在可视化工作室内编译CIL/MSIL

以下hack为您提供了一个项目:

  • 尊重Visual Studio中的调试与发布版本配置.
  • (可选)使用项目首选项中设置的密钥文件对生成的CIL程序集进行签名.
  • 可以添加到源代码管理中.

跟着这些步骤:

  1. 创建一个空的C#类库
  2. 在解决方案文件夹中,右键单击项目并选择"卸载项目"
  3. 右键单击卸载的项目,然后选择"编辑项目"
  4. 在csprof文件中,向下滚动到底部,找到"Import ... Project ="$(MSBuildBinPath)\ Microsoft.CSharp.targets"的行,并将其替换为http:// pastebin中的代码. com/KEJtyQLu(复制如下)

这是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>
Run Code Online (Sandbox Code Playgroud)


Han*_*ant 1

您可以添加一个“makefile 项目”。该模板位于 Visual C++、常规下。此项目类型允许您为“构建”、“清理”和“重建”操作指定自定义构建命令。环境将自动设置,因此您不必弄乱路径。C++ IDE 还支持创建自定义构建规则,以便您可以从文件扩展名 (.il) 自动触发正确的工具 (ilasm.exe)。

然而,这已经是最好的了。项目中的多个 .il 文件不会自动映射到单个构建命令。需要编写 nmake.exe makefile 才能获得该文件。并注意自定义构建规则支持在 vs2010 中被破坏。