ravibpatel / ILRepack.Lib.MSBuild.Task

MSBuild task for ILRepack which is an open-source alternative to ILMerge.
Other
110 stars 31 forks source link

Release configuration merges more assemblies when needed #16

Closed FixRM closed 4 years ago

FixRM commented 5 years ago

Hello @ravibpatel,

I have the following configuration and it works great for Debug builds:

 <Target Name="AfterBuild">
    <ItemGroup>
      <InputAssemblies Include="$(OutputPath)\$(AssemblyName).dll" />
      <InputAssemblies Include="$(OutputPath)\D365Extensions.dll" />
      <InputAssemblies Include="$(OutputPath)\Newtonsoft.Json.dll" />
    </ItemGroup>
    <ILRepack Parallel="true" DebugInfo="true" InputAssemblies="@(InputAssemblies)" KeyFile="$(AssemblyOriginatorKeyFile)" LibraryPath="$(OutputPath)" OutputFile="$(OutputPath)\$(AssemblyName).dll" />
  </Target>

as you can see, there is no conditions or something. For some reasons I see the following output for Release build: 1> SomePlugin -> C:...\bin\Release\SomePlugin.dll 1> Added assembly 'bin\Release\SomePlugin .dll' 1> Added assembly 'bin\Release\D365Extensions.dll' 1> Added assembly 'bin\Release\Newtonsoft.Json.dll' 1> Merging 3 assembies to 'bin\Release\SomePlugin.dll' 1> Merge succeeded in 0,8986863 s 1> Added assembly 'bin\Release\SomePlugin.dll' 1> Added assembly 'bin\Release\D365Extensions.dll' 1> Added assembly 'bin\Release\Newtonsoft.Json.dll' 1> Added assembly 'bin\Release\SomePlugin .dll' 1> Added assembly 'bin\Release\D365Extensions.dll' 1> Added assembly 'bin\Release\Microsoft.Crm.Sdk.Proxy.dll' 1> Added assembly 'bin\Release\Microsoft.Xrm.Sdk.dll' 1> Added assembly 'bin\Release\Microsoft.Xrm.Sdk.Workflow.dll' 1> Added assembly 'bin\Release\Newtonsoft.Json.dll' 1> Merging 9 assembies to 'bin\Release\SomePlugin.dll' 1>C:...\packages\ILRepack.Lib.MSBuild.Task.2.0.16.1\build\ILRepack.Lib.MSBuild.Task.targets(19,5): error : Failed to resolve assembly: 'Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Both Debug and Release configurations are not customized. Any ideas?

FixRM commented 5 years ago

Hello? :)

ravibpatel commented 5 years ago

Sorry for a very late reply. I was very busy with another project. I think there is a reference still remains for default targets file. Are you providing the target file as "ILRepack.targets" in the project directory?

FixRM commented 5 years ago

Hello @ravibpatel, thank you for the reply. It looks like I cant copy paste proj file here, but I can give you a link: https://github.com/FixRM/DuplicateDetectionAlwaysOn/blob/master/DuplicateDetectionAlwaysOn/Plugins/Plugins.csproj.

This is just a basic task setup. I only added <Target Name="AfterBuild"> as described in doc

ravibpatel commented 5 years ago

@FixRM Yes, You added your Target directly into your Project file. Rather than doing that I suggest you should make a file named 'ILRepack.targets' in the root directory (Directory where your .csproj file resides) of your project and add your Target inside it.

Please look at the Usage section of the documentation.

Feel free to ask if you still encounter any issues.

FixRM commented 5 years ago

Thank you for your answer, @ravibpatel. I miss this from doc. But why Debug build work as expected? The second question is can we make Release build works in the same way as I believe that creating additional .target files is not very convenient option

ravibpatel commented 5 years ago

@FixRM Debug works as expected cause default targets file only executes for Release builds and not for Debug builds. So when you are in Release build both yours and default target runs.

I think creating another target file is a lot better option than adding things to .csproj file directly. Also, I created a default target in such a way that if you provide your target file it will execute only your target file.

FixRM commented 5 years ago

Still don't understand... Ok, let it run twice but why it merges different set of assemblies?

ravibpatel commented 5 years ago

Default target file looks for dependent assemblies automatically so it is merging everything it finds while you are providing the assemblies manually in your target file.

To remedy the issue you are having I changed it so you can provide your own targets file. You can see #6.

FixRM commented 5 years ago

Now I see, there is default target file what is suitable for some projects and it merges every assembly found in build folder... I'm not sure if it was a good idea but now I understand the source of the problem :)

Issue is solved, thank you.

chiragknzariya commented 4 years ago

Hello @ravibpatel

I am getting same error, while merging "Microsoft.Xrm.Sdk" dll.

I have created separate target file as you have suggested above and set "Copy Local" to "FALSE" which excludes specified DLLs from merge.

https://gist.githubusercontent.com/chiragknzariya/0dd53f37a5820ee20f12af89a976f303/raw/c8f4651406879d9e578c4416e8493b1f74581a2d/ILRepack.targets

But still I am getting below error :

Failed to resolve assembly: 'Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

Any help will be appreciated.!

FixRM commented 4 years ago

@chiragknzariya, please find sample file here: https://github.com/FixRM/BulletproofProjectTemplate/blob/master/Plugins/ILRepack.targets

chiragknzariya commented 4 years ago

Hello @FixRM, my target file is very much similar to your sample file, however I have tried yours but still the same error occurs.

FixRM commented 4 years ago

@chiragknzariya, can you try to build my solution? I'm pretty much sure it works.

Key thing to solve problem is to correctly set LibraryPath parameter.

chiragknzariya commented 4 years ago

Hi @FixRM , much appreciate your help!

Please find below url for my proj file. D365.csproj

I have used https://github.com/FixRM/BulletproofProjectTemplate/blob/master/Plugins/ILRepack.targets.

Error :

:\Users\admin_ck\source\repos\D365.Plugins.New\packages\ILRepack.Lib.MSBuild.Task.2.0.16.1\build\ILRepack.Lib.MSBuild.Task.targets(11,3): error : Failed to resolve assembly: 'Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

chiragknzariya commented 4 years ago

Hello @ravibpatel,

I have found the part of the problem and it's because of I am using early bound class file, which uses "[assembly: Microsoft.Xrm.Sdk.Client.ProxyTypesAssemblyAttribute()]".

What do you think could be the problem? Can you please share the solution of the problem.

Thanks

siddiquemahsud commented 3 years ago

Hello @chiragknzariya,

I'm facing the same issue, have you got any solution?

I'm using early bound classes: when adding "Microsoft.Xrm.Sdk.dll" to merge then merge is ok but got issues while registering the plugin. When not adding "Microsoft.Xrm.Sdk.dll" to merge then facing "Failed to resolve assembly.." issue for "Microsoft.Xrm.Sdk"

Thanks

FixRM commented 3 years ago

Guys, I use provided above config for dozens of projects and it works like a charm. Are you sure your setup is ok?

siddiquemahsud commented 3 years ago

I'm using a similar target file (https://github.com/FixRM/D365Extensions), but having the issue "Failed to resolve assembly: 'Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' "

<?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)\BingMapsRESTToolkit.dll" />
      <InputAssemblies Include="$(OutputPath)\ABC.Common.CRM.dll" />
      <InputAssemblies Include="$(OutputPath)\ABC.Common.CSharp.dll" />
      <InputAssemblies Include="$(OutputPath)\ABC.CRM.Business.dll" />
      <InputAssemblies Include="$(OutputPath)\ABC.CRM.DA.dll" />
      <InputAssemblies Include="$(OutputPath)\ABC.CRM.Services.dll" />
      <InputAssemblies Include="$(OutputPath)\D365Extensions.dll" />
    </ItemGroup> 
    <ILRepack Parallel="true"
             InputAssemblies="@(InputAssemblies)"
             LibraryPath="$(OutputPath)"
             KeyFile="$(AssemblyOriginatorKeyFile)"
             OutputFile="$(OutputPath)\$(AssemblyName).dll" />
  </Target>
</Project>

When I was merging the DLLs with ILMerge the namespace Microsoft.Xrm.Sdk.Client was not adding to the output DLL, but here I think the dependency issue is due to Microsoft.Xrm.Sdk.Client, I think the process of merging could not found "Microsoft.Xrm.Sdk.Client" in D365Extensions. Please help

FixRM commented 3 years ago

Your config look good... I guess you can try adding each assembly one by one to check if one particular assembly cause the problem. May be there are a circular dependencies or something similar out there?