Skip to content

Commit

Permalink
Make ILMerge targets incremental (NuGet#4337)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkl authored Nov 15, 2021
1 parent 685aaf9 commit c14b85a
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 44 deletions.
30 changes: 21 additions & 9 deletions src/NuGet.Clients/NuGet.CommandLine/NuGet.CommandLine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,30 +93,42 @@
</EmbeddedResource>
</ItemGroup>

<!-- Since we are moving some code and strings from NuGet.CommandLine to NuGet.Commands, we opted to go through normal localization process
(build .resources.dll) and then add them to the ILMerged nuget.exe -->
<!-- This will also be called from CI build, after assemblies are localized, since our test infra takes nuget.exe before Localization -->
<Target Name="ILMergeNuGetExe" AfterTargets="Build" Condition="'$(BuildingInsideVisualStudio)' != 'true' and '$(SkipILMergeOfNuGetExe)' != 'true'" >
<Target Name="DetermineILMergeNuGetExeInputsOutputs">
<PropertyGroup>
<!-- when done after build, no localizedartifacts are built yet, so expected localized artifact count is 0. -->
<ExpectedLocalizedArtifactCount Condition="'$(ExpectedLocalizedArtifactCount)' == ''">0</ExpectedLocalizedArtifactCount>
<PathToBuiltNuGetExe>$(OutputPath)NuGet.exe</PathToBuiltNuGetExe>
<PathToMergedNuGetExe>$(ArtifactsDirectory)$(VsixOutputDirName)\NuGet.exe</PathToMergedNuGetExe>
</PropertyGroup>
<ItemGroup>
<BuildArtifacts Include="$(OutputPath)\*.dll" Exclude="@(MergeExclude)" />
<!-- NuGet.exe needs all NuGet.Commands.resources.dll merged in -->
<LocalizedArtifacts Include="$(ArtifactsDirectory)\NuGet.Commands\**\$(NETFXTargetFramework)\**\*.resources.dll" />
</ItemGroup>
<Message Text="$(MSBuildProjectName) -&gt; $(PathToMergedNuGetExe)" Importance="High" />
</Target>

<!-- Since we are moving some code and strings from NuGet.CommandLine to NuGet.Commands, we opted to go through normal localization process
(build .resources.dll) and then add them to the ILMerged nuget.exe -->
<!-- This will also be called from CI build, after assemblies are localized, since our test infra takes nuget.exe before Localization -->
<Target Name="ILMergeNuGetExe"
AfterTargets="Build"
DependsOnTargets="DetermineILMergeNuGetExeInputsOutputs"
Inputs="$(PathToBuiltNuGetExe);@(BuildArtifacts);@(LocalizedArtifacts)"
Outputs="$(PathToMergedNuGetExe)"
Condition="'$(BuildingInsideVisualStudio)' != 'true' and '$(SkipILMergeOfNuGetExe)' != 'true'" >
<PropertyGroup>
<!-- when done after build, no localizedartifacts are built yet, so expected localized artifact count is 0. -->
<ExpectedLocalizedArtifactCount Condition="'$(ExpectedLocalizedArtifactCount)' == ''">0</ExpectedLocalizedArtifactCount>
</PropertyGroup>
<Error Text="Build dependencies are inconsistent with mergeinclude specified in ilmerge.props" Condition="'@(BuildArtifacts-&gt;Count())' != '@(MergeInclude-&gt;Count())'" />
<Error Text="Satellite assemblies count ILMerged into NuGet.exe should be $(ExpectedLocalizedArtifactCount), but was: @(LocalizedArtifacts-&gt;Count())"
Condition="'@(LocalizedArtifacts-&gt;Count())' != '$(ExpectedLocalizedArtifactCount)'" />
<PropertyGroup>
<PathToBuiltNuGetExe>$(OutputPath)NuGet.exe</PathToBuiltNuGetExe>
<IlmergeCommand>$(ILMergeExePath) /lib:$(OutputPath) /out:$(ArtifactsDirectory)$(VsixOutputDirName)\NuGet.exe @(MergeAllowDup -> '/allowdup:%(Identity)', ' ') /log:$(OutputPath)IlMergeLog.txt</IlmergeCommand>
<IlmergeCommand>$(ILMergeExePath) /lib:$(OutputPath) /out:$(PathToMergedNuGetExe) @(MergeAllowDup -> '/allowdup:%(Identity)', ' ') /log:$(OutputPath)IlMergeLog.txt</IlmergeCommand>
<IlmergeCommand Condition="Exists($(MS_PFX_PATH))">$(IlmergeCommand) /delaysign /keyfile:$(MS_PFX_PATH)</IlmergeCommand>
<!-- LocalizedArtifacts need fullpath, since there will be duplicate file names -->
<IlmergeCommand>$(IlmergeCommand) $(PathToBuiltNuGetExe) @(BuildArtifacts->'%(filename)%(extension)', ' ') @(LocalizedArtifacts->'%(fullpath)', ' ')</IlmergeCommand>
</PropertyGroup>
<MakeDir Directories="$(ArtifactsDirectory)$(VsixOutputDirName)" />
<MakeDir Directories="$([System.IO.Path]::GetDirectoryName($(PathToMergedNuGetExe)))" />
<Exec Command="$(IlmergeCommand)" ContinueOnError="false" />
</Target>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,29 @@
</EmbeddedResource>
</ItemGroup>

<Target Name="ILMergeNuGetMssignExe" AfterTargets="Build" Condition="'$(BuildingInsideVisualStudio)' != 'true'">
<Target Name="DetermineILMergeNuGetMssignExeInputsOutputs">
<PropertyGroup>
<PathToBuiltNuGetExe>$(OutputPath)NuGet.exe</PathToBuiltNuGetExe>
<PathToMergedNuGetExe>$(ArtifactsDirectory)$(VsixOutputDirName)\NuGet.Mssign.exe</PathToMergedNuGetExe>
</PropertyGroup>
<ItemGroup>
<BuildArtifacts Include="$(OutputPath)\*.dll" Exclude="@(MergeExclude)" />
</ItemGroup>
<Message Text="$(MSBuildProjectName) -&gt; $(PathToMergedNuGetExe)" Importance="High" />
</Target>

<Target Name="ILMergeNuGetMssignExe"
AfterTargets="Build"
DependsOnTargets="DetermineILMergeNuGetMssignExeInputsOutputs"
Inputs="$(PathToBuiltNuGetExe);@(BuildArtifacts)"
Outputs="$(PathToMergedNuGetExe)"
Condition="'$(BuildingInsideVisualStudio)' != 'true'">
<Error Text="Build dependencies are inconsistent with mergeinclude specified in ilmerge.props" Condition="'@(BuildArtifacts-&gt;Count())' != '@(MergeInclude-&gt;Count())'" />
<PropertyGroup>
<PathToBuiltNuGetExe>$(OutputPath)NuGet.exe</PathToBuiltNuGetExe>
<IlmergeCommand>$(ILMergeExePath) $(PathToBuiltNuGetExe) /lib:$(OutputPath) @(BuildArtifacts->'%(filename)%(extension)', ' ') /out:$(ArtifactsDirectory)$(VsixOutputDirName)\NuGet.Mssign.exe @(MergeAllowDup -> '/allowdup:%(Identity)', ' ')</IlmergeCommand>
<IlmergeCommand>$(ILMergeExePath) $(PathToBuiltNuGetExe) /lib:$(OutputPath) @(BuildArtifacts->'%(filename)%(extension)', ' ') /out:$(PathToMergedNuGetExe) @(MergeAllowDup -> '/allowdup:%(Identity)', ' ')</IlmergeCommand>
<IlmergeCommand Condition="Exists($(MS_PFX_PATH))">$(IlmergeCommand) /delaysign /keyfile:$(MS_PFX_PATH)</IlmergeCommand>
</PropertyGroup>
<MakeDir Directories="$(ArtifactsDirectory)$(VsixOutputDirName)" />
<MakeDir Directories="$([System.IO.Path]::GetDirectoryName($(PathToMergedNuGetExe)))" />
<Exec Command="$(IlmergeCommand)" ContinueOnError="false" />
</Target>

Expand Down
48 changes: 37 additions & 11 deletions src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project>
<Project>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), 'README.md'))\build\common.props" />
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />

Expand Down Expand Up @@ -85,16 +85,29 @@
</PropertyGroup>
</Target>

<Target Name="ILMergeNuGetPack" DependsOnTargets="GetILMergePlatformArg" Condition="'$(TargetFramework)' != '' AND '$(IsBuildOnlyXPLATProjects)' != 'true' ">
<Target Name="DetermineILMergeNuGetPackInputsOutputs">
<PropertyGroup>
<ILMergeResultDir>$(OutputPath)ilmerge</ILMergeResultDir>
<PathToBuiltNuGetPack>$(OutputPath)NuGet.Build.Tasks.Pack.dll</PathToBuiltNuGetPack>
<PathToMergedNuGetPack>$(OutputPath)ilmerge\NuGet.Build.Tasks.Pack.dll</PathToMergedNuGetPack>
</PropertyGroup>
<MakeDir Directories="$(ILMergeResultDir)" />
<ItemGroup>
<BuildArtifacts Include="$(OutputPath)*.dll" Exclude="$(OutputPath)*Pack.dll" />
</ItemGroup>
<Message Text="$(MSBuildProjectName) -&gt; $(PathToMergedNuGetPack)" Importance="High" />
</Target>

<Target Name="ILMergeNuGetPack"
DependsOnTargets="GetILMergePlatformArg;DetermineILMergeNuGetPackInputsOutputs"
Inputs="$(PathToBuiltNuGetPack);@(BuildArtifacts)"
Outputs="$(PathToMergedNuGetPack)"
Condition="'$(TargetFramework)' != '' AND '$(IsBuildOnlyXPLATProjects)' != 'true' ">
<PropertyGroup>
<ILMergeResultDir>$([System.IO.Path]::GetDirectoryName($(PathToMergedNuGetPack)))</ILMergeResultDir>
</PropertyGroup>

<MakeDir Directories="$(ILMergeResultDir)" />

<PropertyGroup>
<PathToMergedNuGetPack>$(ILMergeResultDir)\NuGet.Build.Tasks.Pack.dll</PathToMergedNuGetPack>
<IlmergeCommand>$(ILMergeExePath) ^
/out:$(PathToMergedNuGetPack) ^
$(ILMergePlatformArg) ^
Expand All @@ -106,22 +119,35 @@
/delaysign ^
/keyfile:$(MS_PFX_PATH)</IlmergeCommand>
<IlmergeCommand>$(IlmergeCommand) ^
$(OutputPath)NuGet.Build.Tasks.Pack.dll ^
$(PathToBuiltNuGetPack) ^
@(BuildArtifacts, ' ')</IlmergeCommand>
</PropertyGroup>
<Exec Command="$(IlmergeCommand)" ContinueOnError="false" />
</Target>

<Target Name="ILMergeNuGetPackResources" DependsOnTargets="GetILMergePlatformArg" Condition="'$(TargetFramework)' != '' AND '$(CurrentCulture)' != ''">
<Target Name="DetermineILMergeNuGetPackResourcesInputsOutputs">
<PropertyGroup>
<ILMergeResultDir>$(OutputPath)ilmerge\$(CurrentCulture)</ILMergeResultDir>
<PathToBuiltNuGetPackResource>$(OutputPath)$(CurrentCulture)NuGet.Build.Tasks.Pack.resources.dll</PathToBuiltNuGetPackResource>
<PathToMergedNuGetPackResource>$(OutputPath)ilmerge\$(CurrentCulture)NuGet.Build.Tasks.Pack.resources.dll</PathToMergedNuGetPackResource>
</PropertyGroup>
<MakeDir Directories="$(ILMergeResultDir)" />
<ItemGroup>
<ResourceArtifacts Include="$(OutputPath)$(CurrentCulture)NuGet*.resources.dll" Exclude="$(OutputPath)$(CurrentCulture)*Pack.resources.dll" />
</ItemGroup>
<Message Text="$(MSBuildProjectName) -&gt; $(PathToMergedNuGetPackResource)" Importance="High" />
</Target>

<Target Name="ILMergeNuGetPackResources"
DependsOnTargets="GetILMergePlatformArg;DetermineILMergeNuGetPackResourcesInputsOutputs"
Inputs="$(PathToBuiltNuGetPackResource);@(ResourceArtifacts)"
Outputs="$(PathToMergedNuGetPackResource)"
Condition="'$(TargetFramework)' != '' AND '$(CurrentCulture)' != ''">
<PropertyGroup>
<ILMergeResultDir>$([System.IO.Path]::GetDirectoryName($(PathToMergedNuGetPackResource)))</ILMergeResultDir>
</PropertyGroup>

<MakeDir Directories="$(ILMergeResultDir)" />

<PropertyGroup>
<PathToMergedNuGetPackResource>$(ILMergeResultDir)NuGet.Build.Tasks.Pack.resources.dll</PathToMergedNuGetPackResource>
<IlmergeCommand>$(ILMergeExePath) ^
/out:$(PathToMergedNuGetPackResource) ^
$(ILMergePlatformArg) ^
Expand All @@ -134,7 +160,7 @@
/delaysign ^
/keyfile:$(MS_PFX_PATH)</IlmergeCommand>
<IlmergeCommand>$(IlmergeCommand) ^
$(OutputPath)$(CurrentCulture)NuGet.Build.Tasks.Pack.resources.dll ^
$(PathToBuiltNuGetPackResource) ^
@(ResourceArtifacts, ' ')</IlmergeCommand>
</PropertyGroup>
<Exec Command="$(IlmergeCommand)" ContinueOnError="false" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), 'README.md'))\build\common.props" />
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
<Import Project="ilmerge.props" />

<PropertyGroup>
<Description>NuGet's understanding of packages. Reading nuspec, nupkgs and package signing.</Description>
Expand Down Expand Up @@ -348,13 +347,33 @@
</EmbeddedResource>
</ItemGroup>

<Target Name="ILMergeNPE" Condition="'$(BuildingInsideVisualStudio)' != 'true' and '$(SkipILMergeOfNPE)' != 'true'" >
<Target Name="DetermineILMergeNPEInputsOutputs">
<PropertyGroup>
<PathToBuiltNPE>$(OutputPath)NuGet.Packaging.Extraction.dll</PathToBuiltNPE>
<PathToMergedNPE>$(ILMergeDirectory)NuGet.Packaging.Extraction.dll</PathToMergedNPE>
</PropertyGroup>
<ItemGroup>
<BuildArtifacts Include="$(OutputPath)\*.dll" Exclude="@(MergeExclude)" />
<MergeInclude Include="$(OutputPath)NuGet.Common.dll"/>
<MergeInclude Include="$(OutputPath)NuGet.Configuration.dll"/>
<MergeInclude Include="$(OutputPath)NuGet.Frameworks.dll"/>
<MergeInclude Include="$(OutputPath)NuGet.Versioning.dll"/>

<MergeAllowdup Include="Strings"/>
<MergeAllowdup Include="EncodingUtility"/>
<MergeAllowdup Include="EqualityUtility"/>
<MergeAllowdup Include="HashCodeCombiner"/>
<MergeAllowdup Include="Extensions"/>
</ItemGroup>
<Message Text="$(MSBuildProjectName) -&gt; $(PathToMergedNPE)" Importance="High" />
</Target>

<Target Name="ILMergeNPE"
DependsOnTargets="DetermineILMergeNPEInputsOutputs"
Inputs="$(PathToBuiltNPE);@(MergeInclude)"
Outputs="$(PathToMergedNPE)"
Condition="'$(BuildingInsideVisualStudio)' != 'true' and '$(SkipILMergeOfNPE)' != 'true'" >
<PropertyGroup>
<PathToBuiltNPE>$(OutputPath)NuGet.Packaging.Extraction.dll</PathToBuiltNPE>
<IlmergeCommand>$(ILMergeExePath) /lib:$(OutputPath) /t:library /out:$(ILMergeDirectory)NuGet.Packaging.Extraction.dll @(MergeAllowDup -> '/allowdup:%(Identity)', ' ')</IlmergeCommand>
<IlmergeCommand>$(ILMergeExePath) /lib:$(OutputPath) /t:library /out:$(PathToMergedNPE) @(MergeAllowDup -> '/allowdup:%(Identity)', ' ')</IlmergeCommand>
<IlmergeCommand Condition="Exists($(MS_PFX_PATH))">$(IlmergeCommand) /delaysign /keyfile:$(MS_PFX_PATH)</IlmergeCommand>
<IlmergeCommand>$(IlmergeCommand) $(PathToBuiltNPE) @(MergeInclude->'%(fullpath)', ' ')</IlmergeCommand>
</PropertyGroup>
Expand Down
15 changes: 0 additions & 15 deletions src/NuGet.Core/NuGet.Packaging.Extraction/ilmerge.props

This file was deleted.

0 comments on commit c14b85a

Please sign in to comment.