Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CleanReferenceCopyLocalPaths Not Happening v2.0.18.1 #25

Closed
jstevenson72 opened this issue Apr 22, 2020 · 9 comments
Closed

CleanReferenceCopyLocalPaths Not Happening v2.0.18.1 #25

jstevenson72 opened this issue Apr 22, 2020 · 9 comments

Comments

@jstevenson72
Copy link

jstevenson72 commented Apr 22, 2020

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:

<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="AfterBuild">
    <ItemGroup>
      <InputAssemblies Include="$(OutputPath)\$(AssemblyName).dll" />
      <InputAssemblies Include="$(OutputPath)\de\*.dll" />
      <InputAssemblies Include="$(OutputPath)\es\*.dll" />
      <InputAssemblies Include="$(OutputPath)\en\*.dll" />
      <InputAssemblies Include="$(OutputPath)\fr\*.dll" />
      <InputAssemblies Include="$(OutputPath)\it\*.dll" />
      <InputAssemblies Include="$(OutputPath)\ja\*.dll" />
      <InputAssemblies Include="$(OutputPath)\ko\*.dll" />
      <InputAssemblies Include="$(OutputPath)\pt-pt\*.dll" />
      <InputAssemblies Include="$(OutputPath)\zh-cn\*.dll" />
      <InputAssemblies Include="$(OutputPath)\zh-tw\*.dll" />
    </ItemGroup>
    <ILRepack Parallel="true" Verbose="true" LogFile="c:\temp\output.txt" InputAssemblies="@(InputAssemblies)" LibraryPath="$(OutputPath)" KeyFile="$(AssemblyOriginatorKeyFile)" OutputFile="$(OutputPath)\$(AssemblyName).dll" />
  </Target>
</Project>

And here is my props file:

<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <ILRepackTargetsFile>$(ProjectDir)ILRepack.targets</ILRepackTargetsFile>
    <ClearOutputDirectory>True</ClearOutputDirectory>
  </PropertyGroup>
</Project>

image
I'm hoping it would delete all of the satelite assemblies in the language subfolders shown above. But they appear to still all be there.

image

It merges all of the correct DLLs but does not cleanup the source .dlls. Could anyone help me?

@jstevenson72 jstevenson72 changed the title CleanReferenceCopyLocalPaths Not Happening CleanReferenceCopyLocalPaths Not Happening v2.0.18.1 Apr 22, 2020
@ravibpatel
Copy link
Owner

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.

@jstevenson72
Copy link
Author

jstevenson72 commented Apr 22, 2020

ILRepack.zip

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

@ravibpatel
Copy link
Owner

ravibpatel commented Apr 22, 2020

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

@jstevenson72
Copy link
Author

I've modified it as you specified, and again it still does the merge, but leaves the satellite dll files there.

image

<?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.

@jstevenson72
Copy link
Author

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'" />

@jstevenson72
Copy link
Author

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

image

@jstevenson72
Copy link
Author

jstevenson72 commented Apr 22, 2020

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

@ravibpatel
Copy link
Owner

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.

@jstevenson72
Copy link
Author

jstevenson72 commented Apr 23, 2020

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants