是否有从 Visual Studio 项目中编译 CIL 代码的示例
-
28-09-2019 - |
题
我意识到有人询问并回答了 Visual Studio 不支持 CIL/MSIL 项目。这 MSBuildContrib 项目有一个 ILASM 任务,允许您在构建时编译 IL 文件。
谷歌搜索没有找到如何使用此任务的示例。
是否有使用 ILASM 作为 Visual Studio 解决方案一部分的示例?我意识到 #develope 和 ILIDE 支持 CIL...这里的目标是编译一些CIL文件 作为 Visual Studio 解决方案的一部分.
解决方案
您可以添加一个“生成文件的项目”。模板是在Visual C ++,将军。此项目类型允许您生成,清洁指定自定义生成命令和重建行动。环境会自动安装,所以你不必惹路径。 C ++的IDE还支持创建自定义生成规则,这样可以自动触发从文件扩展名(.il内)合适的工具程序(Ilasm.exe)。
这是关于然而尽善尽美。没有一个单一的构建命令的项目的多个文件的.il自动映射。写一个NMAKE.EXE生成文件需要拿到。和提防自定义生成规则的支持VS2010中得到打破。
其他提示
我对汉斯回答这个问题给予了赞扬,但经过一些实验,我得到了一个稍微接近事实的解决方案:
如何在 VISUAL STUDIO 内编译 CIL/MSIL
以下技巧将为您提供一个项目:
- 尊重调试与调试在 Visual Studio 中发布构建配置。
- (可选)使用项目首选项中设置的密钥文件对生成的 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>"$(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>
不隶属于 StackOverflow