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

发布于 2024-09-29 22:34:16 字数 316 浏览 3 评论 0原文

我意识到有人询问并回答了 Visual Studio 不支持 CIL/MSIL 项目。 MSBuildContrib 项目有一个 ILASM 任务,允许您在构建时编译 IL 文件。

谷歌搜索没有找到如何使用此任务的示例。

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟火散人牵绊 2024-10-06 22:34:16

我对 Hans 回答这个问题给予了赞扬,但经过一些实验,我得到了一个稍微接近我的解决方案:

如何在 VISUAL STUDIO 中编译 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>"$(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>

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>"$(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>
情绪 2024-10-06 22:34:16

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文