Error When Merging With ILMerge/Repack

Error When Merging With ILMerge/Repack

ricky.chen6SZNU
Participant Participant
1,356 Views
3 Replies
Message 1 of 4

Error When Merging With ILMerge/Repack

ricky.chen6SZNU
Participant
Participant

I want to combine my Revit add-in's DLLs together to work around version conflicts. I am using ILRepack to accomplish this. I have 3 projects and their dependency structure is A depends on B depends on C. I am also using the Autodesk.Revit.SDK Nuget package.

 

I have a build target like follows:

 

<Target Name="ILRepack" AfterTargets="Build">
   <Exec
       WorkingDirectory="$(OutDir)"
       ConsoleToMsBuild="true"
	   Command="$(PkgILRepack)\tools\ILRepack.exe /out:Merged.dll ^
       /target:library ^
	   B.dll C.dll
    /> 
</Target>

 

 

The build fails on any combination of merge targets EXCEPT C.dll, which makes me think it has something to do with the dependency structure. The projects all reference Autodesk.Revit.SDK, which makes the fact C builds successfully even more mysterious. I've also tried merging several DLLs without project dependencies together and that works as well.

 

The build fails with this error:

 

EXEC : error : Failed to load assembly B.dll
  Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'RevitAPI, Version=20.0.0.0, Culture=neutral, PublicKeyToken=null'

 

 

Does anyone know what's happening here?

0 Likes
1,357 Views
3 Replies
Replies (3)
Message 2 of 4

jeremy_tammik
Alumni
Alumni

Interesting undertaking. However, I doubt that makes much sense. I assume your purpose is to run a Revit add-in. That requires a running session of Revit.exe. On startup, Revit will automatically load its installed Revit API DLLs, because they are needed internally as well for many purposes. I do not think you can modify or influence these steps in any way. So, when you come along later with your package containing RevitAPI.dll, it will conflict with the version already loaded I see no way around that. So, I would suggest you try a different approach.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 4

ricky.chen6SZNU
Participant
Participant

The idea behind using ILMerge/Repack is to copy the code that the add-in will use into one project (including third party DLLs), which should combat the issue of having conflicting versions of common packages (ex: Log4Net). I'm trying to explicitlynot merge the Revit API DLLs since I know they will already be loaded when the add-in is loaded. This seems to work fine when a project is only dependent on third party DLLs, but when I try to merge a project that depends on other projects, it throws the above error.

 

I went through your blog post about this issue, and this is the only method that seems to work for my requirements. Are there any other methods that have released since this post?

 

0 Likes
Message 4 of 4

jeremy_tammik
Alumni
Alumni

That post is rather old. This topic came up several times since then. Here os the most recent related post:

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes