C# 使用MSBuild的.Net核心项目的iRepack

C# 使用MSBuild的.Net核心项目的iRepack,c#,msbuild,.net-core,.net-assembly,ilrepack,C#,Msbuild,.net Core,.net Assembly,Ilrepack,我想在.Net核心项目的MSBuild管道中进行集成,以将所有必需的dll合并到单个exe/dll中 有用的NuGet软件包似乎非常适合这一点,但是GitHub自述文件中的示例对.Net核心项目不太适用,我不知道如何将其更改为与.Net核心项目兼容: <!-- ILRepack --> <Target Name="AfterBuild" Condition="'$(Configuration)' == 'Release'"> <ItemGroup>

我想在.Net核心项目的MSBuild管道中进行集成,以将所有必需的dll合并到单个exe/dll中

有用的NuGet软件包似乎非常适合这一点,但是GitHub自述文件中的示例对.Net核心项目不太适用,我不知道如何将其更改为与.Net核心项目兼容:

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

将其用于.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>

net461

您还可以使用一个
来合并输出文件夹中的所有dll文件

我担心iRepack不支持.net core。事实上可能是这样,但是,由于我刚刚使用了.Net Core和build for
net461
的项目格式,因此我看不出我的案例有什么问题。这似乎与
dotnet build
结合使用不起作用: