带有 MSBuild 的 .Net Core 项目的 ILRepack [英] ILRepack for .Net Core Projects with MSBuild

查看:29
本文介绍了带有 MSBuild 的 .Net Core 项目的 ILRepack的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 ILRepack 集成到我的 MSBuild 管道中,以便合并 .Net Core 项目将所有需要的 dll 整合到一个 exe/dll 中.

I want to integrate ILRepack in my MSBuild pipeline for a .Net Core project to merge all required dlls into a single exe/dll.

有用的 NuGet-Package ILRepack.MSBuild.Task 似乎很适合,但是 GitHub 自述文件中的示例对 .Net Core 项目不太适用,我无法弄清楚如何更改它以与 .Net Core 项目兼容:

The useful NuGet-Package ILRepack.MSBuild.Task seems well fitted for that, however the example in the GitHub readme does not quite work for .Net Core projects and I can't figure out how I have to change this to be compatible with a .Net Core project:

<!-- ILRepack -->
<Target Name="AfterBuild" Condition="'$(Configuration)' == 'Release'">

   <ItemGroup>
    <InputAssemblies Include="$(OutputPath)ExampleAssemblyToMerge1.dll" />
    <InputAssemblies Include="$(OutputPath)ExampleAssemblyToMerge2.dll" />
    <InputAssemblies Include="$(OutputPath)ExampleAssemblyToMerge3.dll" />
   </ItemGroup>

   <ItemGroup>
    <!-- Must be a fully qualified name -->
    <DoNotInternalizeAssemblies Include="ExampleAssemblyToMerge3" />
   </ItemGroup>

   <ILRepack 
    Parallel="true"
    Internalize="true"
    InternalizeExclude="@(DoNotInternalizeAssemblies)"
    InputAssemblies="@(InputAssemblies)"
    TargetKind="Dll"
    OutputFile="$(OutputPath)$(AssemblyName).dll"
   />

</Target>
<!-- /ILRepack -->

说明:

我只想使用 .Net-Core 引入的 .csproj-Format 但实际上使用 net461 作为 TargetPlatform.

Clarification:

I just want to use the .csproj-Format introduced with .Net-Core but actually using net461 as TargetPlatform.

推荐答案

将此用于 .Net Core 项目:

Use this for .Net Core projects:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>net461</TargetFramework>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="ILRepack" Version="2.0.15" />
        <PackageReference Include="ILRepack.MSBuild.Task" Version="1.0.9" />
    </ItemGroup>

    <!-- ILRepack -->
    <Target Name="ILRepack" AfterTargets="Build">

        <ItemGroup>
            <InputAssemblies Include="$(OutputPath)ExampleAssemblyToMerge1.dll" />
            <InputAssemblies Include="$(OutputPath)ExampleAssemblyToMerge2.dll" />
            <InputAssemblies Include="$(OutputPath)ExampleAssemblyToMerge3.dll" />
        </ItemGroup>

        <ItemGroup>
            <!-- Must be a fully qualified name -->
            <DoNotInternalizeAssemblies Include="ExampleAssemblyToMerge3" />
        </ItemGroup>

        <ILRepack
            Parallel="true"
            Internalize="true"
            InternalizeExclude="@(DoNotInternalizeAssemblies)"
            InputAssemblies="@(InputAssemblies)"
            TargetKind="Dll"
            OutputFile="$(OutputPath)$(AssemblyName).dll" />

    </Target>
    <!-- /ILRepack -->

</Project>

注意

您也可以使用一个<InputAssemblies Include="$(OutputPath)*.dll"/>来合并输出文件夹中的所有dll文件

Note

You can also use one <InputAssemblies Include="$(OutputPath)*.dll" /> to merge all dll-files in the output folder

这篇关于带有 MSBuild 的 .Net Core 项目的 ILRepack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆