gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 00:10:31 30 4
gpt4 key购买 nike

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

谷歌搜索了有关如何使用此任务的示例。

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

最佳答案

我感谢 Hans 回答了这个问题,但经过一些实验,我得到了一个更接近家庭的解决方案:

如何在 VISUAL STUDIO 中编译 CIL/MSIL

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

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

  • 按着这些次序:
  • 创建一个空的 C# 类库
  • 在解决方案文件夹中,右键单击项目并选择“卸载项目”
  • 右键单击卸载的项目并选择“编辑项目”
  • 在 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>

    关于visual-studio - 是否有任何从 Visual Studio 项目中编译 CIL 代码的示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4068425/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com