1

我想将ILRepack集成到我的 MSBuild 管道中,用于 .Net Core 项目,以将所有必需的 dll 合并到单个 exe/dll 中。

有用的 NuGet-PackageILRepack.MSBuild.Task似乎非常适合,但是 GitHub 自述文件中的示例对 .Net Core 项目不太适用,我不知道如何更改它以与 .Net Core 项目兼容:

<!-- 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 -->

澄清:

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

4

1 回答 1

1

将此用于 .Net Core 项目:

<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 文件

于 2018-01-09T14:01:39.130 回答