Closed jstevenson72 closed 4 years ago
If you provide your one ILRepack.targets file then it won't execute the CleanUp job as you can see from here. If you want to clean up the directory afterward then you can copy that task in your targets file or use the default targets file provided with the project.
Here is my modified ILRepack.targets file. It still doesn't appear to execute the cleanup, even though I've removed the condition from the Target.
Any thoughts?
Also when I remove my .targets file, and the .props files from the project, and try to use the default targets file, it misses all of the satellite assemblies which is why I'm having to use the custom targets file. Also the default targets file, doesn't delete the source satellite assemblies eitehr.
<?xml version="1.0" encoding="utf-8" ?>
<!-- ILRepack -->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="AfterBuild">
<ItemGroup>
<InputAssemblies Include="$(OutputPath)$(AssemblyName).dll" />
<InputAssemblies Include="$(OutputPath)de\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)es\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)en\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)fr\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)it\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)ja\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)ko\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)pt-pt\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)zh-cn\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)zh-tw\$(AssemblyName).resources.dll" />
</ItemGroup>
<ILRepack Parallel="true" Verbose="true" LogFile="c:\temp\output.txt" InputAssemblies="@(InputAssemblies)" LibraryPath="$(OutputPath)" KeyFile="$(AssemblyOriginatorKeyFile)" OutputFile="$(OutputPath)$(AssemblyName).dll" />
</Target>
<Target
AfterTargets="ILRepack"
Name="CleanReferenceCopyLocalPaths">
<Delete Files="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')" />
<ItemGroup>
<Directories Include="$([System.IO.Directory]::GetDirectories('$(OutDir)%(DestinationSubDirectory)', '*', System.IO.SearchOption.AllDirectories))" />
<Directories>
<Files>$([System.IO.Directory]::GetFiles("%(Directories.Identity)", "*", System.IO.SearchOption.AllDirectories).get_Length())</Files>
</Directories>
</ItemGroup>
<RemoveDir Directories="@(Directories)" Condition="%(Files)=='0'" />
</Target>
</Project>
<!-- /ILRepack -->
You specified "ILRepack" as AfterTargets. Try using the following.
<?xml version="1.0" encoding="utf-8" ?>
<!-- ILRepack -->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="AfterBuild">
<ItemGroup>
<InputAssemblies Include="$(OutputPath)$(AssemblyName).dll" />
<InputAssemblies Include="$(OutputPath)de\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)es\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)en\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)fr\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)it\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)ja\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)ko\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)pt-pt\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)zh-cn\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)zh-tw\$(AssemblyName).resources.dll" />
</ItemGroup>
<ILRepack Parallel="true" Verbose="true" LogFile="c:\temp\output.txt" InputAssemblies="@(InputAssemblies)" LibraryPath="$(OutputPath)" KeyFile="$(AssemblyOriginatorKeyFile)" OutputFile="$(OutputPath)$(AssemblyName).dll" />
</Target>
<Target
AfterTargets="AfterBuild"
Name="CleanReferenceCopyLocalPaths">
<Delete Files="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')" />
<ItemGroup>
<Directories Include="$([System.IO.Directory]::GetDirectories('$(OutDir)%(DestinationSubDirectory)', '*', System.IO.SearchOption.AllDirectories))" />
<Directories>
<Files>$([System.IO.Directory]::GetFiles("%(Directories.Identity)", "*", System.IO.SearchOption.AllDirectories).get_Length())</Files>
</Directories>
</ItemGroup>
<RemoveDir Directories="@(Directories)" Condition="%(Files)=='0'" />
</Target>
</Project>
<!-- /ILRepack -->
I've modified it as you specified, and again it still does the merge, but leaves the satellite dll files there.
<?xml version="1.0" encoding="utf-8" ?>
<!-- ILRepack -->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="AfterBuild">
<ItemGroup>
<InputAssemblies Include="$(OutputPath)$(AssemblyName).dll" />
<InputAssemblies Include="$(OutputPath)de\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)es\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)en\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)fr\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)it\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)ja\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)ko\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)pt-pt\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)zh-cn\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)zh-tw\$(AssemblyName).resources.dll" />
</ItemGroup>
<ILRepack Parallel="true" Verbose="true" LogFile="c:\temp\output.txt" InputAssemblies="@(InputAssemblies)" LibraryPath="$(OutputPath)" KeyFile="$(AssemblyOriginatorKeyFile)" OutputFile="$(OutputPath)$(AssemblyName).dll" />
</Target>
<Target
AfterTargets="AfterBuild"
Name="CleanReferenceCopyLocalPaths">
<Delete Files="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')" />
<ItemGroup>
<Directories Include="$([System.IO.Directory]::GetDirectories('$(OutDir)%(DestinationSubDirectory)', '*', System.IO.SearchOption.AllDirectories))" />
<Directories>
<Files>$([System.IO.Directory]::GetFiles("%(Directories.Identity)", "*", System.IO.SearchOption.AllDirectories).get_Length())</Files>
</Directories>
</ItemGroup>
<RemoveDir Directories="@(Directories)" Condition="%(Files)=='0'" />
</Target>
</Project>
<!-- /ILRepack -->
I'm so sorry to bother you with this, I had hoped it was something simple. Also do you have a Patreon / PayPal or donation page. I'd like to donate.
Is it possible that this line, only deletes the files in the output directory and not any subdirectories created from the build?
<Delete Files="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')" />
And do these lines, only delete Empty Directories?
<ItemGroup>
<Directories Include="$([System.IO.Directory]::GetDirectories('$(OutDir)%(DestinationSubDirectory)', '*', System.IO.SearchOption.AllDirectories))" />
<Directories>
<Files>$([System.IO.Directory]::GetFiles("%(Directories.Identity)", "*", System.IO.SearchOption.AllDirectories).get_Length())</Files>
</Directories>
</ItemGroup>
<RemoveDir Directories="@(Directories)" Condition="%(Files)=='0'" />
I modified the Targets to add some logging, and it appears as though the ReferenceCopyLocalPaths is empty, and the CleanReferenceCopyLocalPaths still isn't being called.
<?xml version="1.0" encoding="utf-8" ?>
<!-- ILRepack -->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="AfterBuild">
<Message Importance="high" Text="ILRepack Step." />
<Message Importance="high" Text="1. ReferencePath:%0D%0A%09@(ReferencePath->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)', '%0D%0A%09')" />
<Message Importance="high" Text="2. ReferenceCopyLocalPaths:%0D%0A%09@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)', '%0D%0A%09')" />
<ItemGroup>
<InputAssemblies Include="$(OutputPath)$(AssemblyName).dll" />
<InputAssemblies Include="$(OutputPath)de\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)es\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)en\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)fr\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)it\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)ja\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)ko\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)pt-pt\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)zh-cn\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)zh-tw\$(AssemblyName).resources.dll" />
</ItemGroup>
<ILRepack Parallel="true" Verbose="true" LogFile="c:\temp\output.txt" InputAssemblies="@(InputAssemblies)" LibraryPath="$(OutputPath)" KeyFile="$(AssemblyOriginatorKeyFile)" OutputFile="$(OutputPath)$(AssemblyName).dll" />
</Target>
<Target
AfterTargets="AfterBuild"
Name="CleanReferenceCopyLocalPaths">
<Message Importance="high" Text="Clean Source Files Target Step." />
<Delete Files="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')" />
<ItemGroup>
<Directories Include="$([System.IO.Directory]::GetDirectories('$(OutDir)%(DestinationSubDirectory)', '*', System.IO.SearchOption.AllDirectories))" />
<Directories>
<Files>$([System.IO.Directory]::GetFiles("%(Directories.Identity)", "*", System.IO.SearchOption.AllDirectories).get_Length())</Files>
</Directories>
</ItemGroup>
<RemoveDir Directories="@(Directories)" Condition="%(Files)=='0'" />
</Target>
</Project>
<!-- /ILRepack -->
I solved the problem by only using a single <Target/>
and included individual <Delete/>
tasks to delete all of the source files.
Then the code you already had, deleted the folders because they were now empty.
<?xml version="1.0" encoding="utf-8" ?>
<!-- ILRepack -->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="AfterBuild">
<Message Importance="high" Text="ILRepack Step." />
<Message Importance="high" Text="1. ReferencePath:%0D%0A%09@(ReferencePath->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)', '%0D%0A%09')" />
<Message Importance="high" Text="2. ReferenceCopyLocalPaths:%0D%0A%09@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)', '%0D%0A%09')" />
<ItemGroup>
<InputAssemblies Include="$(OutputPath)$(AssemblyName).dll" />
<InputAssemblies Include="$(OutputPath)de\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)es\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)en\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)fr\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)it\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)ja\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)ko\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)pt-pt\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)zh-cn\$(AssemblyName).resources.dll" />
<InputAssemblies Include="$(OutputPath)zh-tw\$(AssemblyName).resources.dll" />
</ItemGroup>
<ILRepack Parallel="true" Verbose="true" LogFile="c:\temp\output.txt" InputAssemblies="@(InputAssemblies)" LibraryPath="$(OutputPath)" KeyFile="$(AssemblyOriginatorKeyFile)" OutputFile="$(OutputPath)$(AssemblyName).dll" />
<Message Importance="high" Text="Clean Source Files Target Step." />
<Delete Files="$(OutputPath)de\$(AssemblyName).resources.dll" />
<Delete Files="$(OutputPath)es\$(AssemblyName).resources.dll" />
<Delete Files="$(OutputPath)en\$(AssemblyName).resources.dll" />
<Delete Files="$(OutputPath)fr\$(AssemblyName).resources.dll" />
<Delete Files="$(OutputPath)it\$(AssemblyName).resources.dll" />
<Delete Files="$(OutputPath)ja\$(AssemblyName).resources.dll" />
<Delete Files="$(OutputPath)ko\$(AssemblyName).resources.dll" />
<Delete Files="$(OutputPath)pt-pt\$(AssemblyName).resources.dll" />
<Delete Files="$(OutputPath)zh-cn\$(AssemblyName).resources.dll" />
<Delete Files="$(OutputPath)zh-tw\$(AssemblyName).resources.dll" />
<Delete Files="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')" />
<ItemGroup>
<Directories Include="$([System.IO.Directory]::GetDirectories('$(OutDir)%(DestinationSubDirectory)', '*', System.IO.SearchOption.AllDirectories))" />
<Directories>
<Files>$([System.IO.Directory]::GetFiles("%(Directories.Identity)", "*", System.IO.SearchOption.AllDirectories).get_Length())</Files>
</Directories>
</ItemGroup>
<RemoveDir Directories="@(Directories)" Condition="%(Files)=='0'" />
</Target>
</Project>
<!-- /ILRepack -->
That's great but maybe language satellite assemblies won't work when merged. You have to embed them first then run the merger. I opened the issue about this on original project. You can see it from here. I usually embed satellite assemblies using Resource.Embedder before merging them.
You were correct, by the way, about the merged satellite assemblies not working. The English resource was fine, because it is the main dll, but all the other languages were not found, using the ILRepacked assembly.
Thank you @ravibpatel so much! The Resource.Embedder worked flawlessly and with very little effort. I really appreciate the time you took to help me with this issue. Have a good day!
I'm not able to get the CleanReferenceCopyLocalPaths Target to happen. I've enabled verbose logging, and don't see anything related to it.
I've setup both a ILRepack.Config.props file and an ILRepack.targets file within my Project.
Here is my targets file:
And here is my props file:
It merges all of the correct DLLs but does not cleanup the source .dlls. Could anyone help me?