使用MSBuild进行.Net核心项目的ILRepack

时间:2018-01-09 14:01:39

标签: c# msbuild .net-core .net-assembly ilrepack

我希望在我的MSBuild管道中集成ILRepack以便.Net Core项目将所有必需的dll合并到一个exe / dll中。

有用的NuGet-Package ILRepack.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 -->

澄清:

我只想使用。{1}} - .Net-Core引入的格式,但实际上使用.csproj作为net461

1 个答案:

答案 0 :(得分:2)

将此用于.Net Core项目:

TargetPlatform

注意

您还可以使用一个<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> 合并输出文件夹中的所有dll文件