cake-contrib/Cake.Json

ILMerge of the Addin

phillipsj opened this issue ยท 20 comments

Experiencing JSON .NET conflicts between other addins when this one is used. Would be it possible to consider using ILMerge for this addin?

I created a PR (#19) to embed the Newtonsoft.Json assembly in the Cake.Json assembly.

kcamp commented

+1 for doing something to make this work with other Cake addins using different versions of Newtownsoft.Json. The Fody solution proposed seems like it would serve well. Thanks!

gep13 commented

@pascalberger @AdmiringWorm I believe I am right in saying that ILMerge'ing, at least via Fody isn't currently possible on .Net Standard. I would love it if someone can prove me wrong on this though.

I've created cake-build/cake#2582 to discuss integration of this adidn into Cake.Common, which IMHO would make sense since Cake already has a dependency on JSON.NET

gep13 commented

@AdmiringWorm what was the issue that you ran into recently with regard to using Fody on one of your addins? Do you know if things have changed in this area since you last investigated?

@gep13 the issue I was running into was related to using Costura.
While it would embed the referenced library binaries, it would never load them when they were needed.

There haven't been a new release of Costure since I tested, so I doubt anything have changed there.

gep13 commented

@AdmiringWorm thanks for clarifying. That is what I remembered you telling me. What you have described would fit with what @phillipsj is currently seeing as well.

@gep13 I do believe it would work if the addin was a program, and not a library.
Looking at the Readme file for costura, it seems Module Initializers don't work in libraries (and mono) and need to be initialised from the program itself.

So definitely not doable in an addin library ๐Ÿ˜ข
https://github.com/Fody/Costura#costurautility

gep13 commented

So, if there was "somewhere" that we could call CosturaUtility.Initialize(); then things would start to work?

I think so, but it could also be that it needs to be called from the program itself.
I haven't tested it, as I got compile errors when trying to call the CosturaUtility in one of the aliases I tested on a different addin.

via Fody isn't currently possible on .Net Standard.

Fody works with netstandard

but costura wont work in this case. costura doesnt change the dependency name/version. so the runtime will still try to load the dependency, the fact that it is loading from an assembly resource does not prevent binding issues

gep13 commented

@SimonCropp thank you for all the information, I think this will really help!

This is likely going to be a silly question, but here goes anyway...

What is the different between ilmerge (which is what I think Fody.Costura) is doing, and ilrepack?

both ilmerge and ilrepack merge the IL of the dependencies into the target assembly. resulting in a new assembly with no dependency.

ilmerge and ilrepack use the same approach, although with a different feature set and api. ilmerge is written in c++ (i think), ilrepack uses mono cecil and is written in c#

Costura embeds the dependencies binary as a resource in the target assembly, the target assembly still has a reference to those dependencies, then with a runtime sleight-of-hand, that dependency is loaded from a resource.

for your purposes: ilmerge and ilrepack will fix binding redirect issues, costura will not.

gep13 commented

@SimonCropp said...
Costura embeds the dependencies binary as a resource in the target assembly, the target assembly still has a reference to those dependencies, then with a runtime sleight-of-hand, that dependency is loaded from a resource.

Oh I see! This is the part that I was missing.

@SimonCropp said...
for your purposes: ilmerge and ilrepack will fix binding redirect issues, costura will not.

Yip, I think I am coming to the same conclusion. For me personally, Fody.Costura is just SO simple to use (thanks!!! ๐Ÿ˜„), that I was hoping that it would work in this scenario, but now I get why it isn't going to work in this case.

Thanks again for your help with this, really appreciate you taking the time!

no worries. let me know if u need any help with making ilmerge/ilrepack work with your build process

I have a working build for Cake.AzureStorage leveraging ILRepack. I am in the process of testing, but it is something to work with. https://github.com/cake-contrib/Cake.AzureStorage/blob/develop/src/Cake.AzureStorage/Cake.AzureStorage.csproj