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

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

问题描述

我想在我的MSBuild管道中集成 ILRepack ,以便将.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格式,但实际上使用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核心项目的ILRepack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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