使用 MSBuild 的 .Net Core 项目的 ILRepack
ILRepack for .Net Core Projects with MSBuild
我想将 ILRepack 集成到我的 .Net Core 项目的 MSBuild 管道中,以将所有必需的 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 -->
澄清:
我只想使用 .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>
备注
您还可以使用一个 <InputAssemblies Include="$(OutputPath)\*.dll" />
合并输出文件夹中的所有 dll 文件
我想将 ILRepack 集成到我的 .Net Core 项目的 MSBuild 管道中,以将所有必需的 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 -->
澄清:
我只想使用 .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>
备注
您还可以使用一个 <InputAssemblies Include="$(OutputPath)\*.dll" />
合并输出文件夹中的所有 dll 文件