clairernovotny / ReferenceGenerator

MIT License
75 stars 13 forks source link

First attempt at Mono build [NOT READY FOR MERGING] #17

Closed ErikSchierboom closed 7 years ago

ErikSchierboom commented 8 years ago

This PR is the first attempt at getting the project to build on Mono. To get it building, I have done the following:

The build.sh succesfully compiles the project on my machine now, but there is still one import step that is not working: the buildpackagelayout.sh throws an exception:

INFO: IL Repack - Version 2.0.8
INFO: Adding assembly for merge: ../src/ReferenceGenerator/bin/release/ReferenceGenerator.exe
INFO: Adding assembly for merge: ../src/ReferenceGenerator/bin/release/System.Collections.Immutable.dll
INFO: Adding assembly for merge: ../src/ReferenceGenerator/bin/release/System.Reflection.Metadata.dll
INFO: Adding assembly for merge: ../src/ReferenceGenerator/bin/release/Newtonsoft.Json.dll
WARN: Duplicate Win32 resource with id=0, parents=[,
                                                    ], name= in assembly System.Reflection.Metadata, Version=1.0.21.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, ignoring
INFO: Processing references
INFO: Processing types
INFO: Merging <Module>
INFO: Merging <Module>
INFO: Merging <Module>
INFO: Merging <Module>
INFO: Processing types
INFO: Processing resources
INFO: Fixing references
Mono.Cecil.ResolutionException: Failed to resolve System.Runtime.Serialization.Formatters.FormatterAssemblyStyle
  at Mono.Cecil.Mixin.CheckedResolve (Mono.Cecil.TypeReference self) <0x2a42d70 + 0x00053> in <filename unknown>:0 
  at Mono.Cecil.MetadataBuilder.GetConstantType (Mono.Cecil.TypeReference constant_type, System.Object constant) <0x46121c0 + 0x00053> in <filename unknown>:0 
  at Mono.Cecil.MetadataBuilder.AddConstant (IConstantProvider owner, Mono.Cecil.TypeReference type) <0x4612048 + 0x0002b> in <filename unknown>:0 
  at Mono.Cecil.MetadataBuilder.AddField (Mono.Cecil.FieldDefinition field) <0x4608900 + 0x00163> in <filename unknown>:0 
  at Mono.Cecil.MetadataBuilder.AddFields (Mono.Cecil.TypeDefinition type) <0x4608898 + 0x00043> in <filename unknown>:0 
  at Mono.Cecil.MetadataBuilder.AddType (Mono.Cecil.TypeDefinition type) <0x4607210 + 0x001e7> in <filename unknown>:0 
  at Mono.Cecil.MetadataBuilder.AddTypeDefs () <0x46071a8 + 0x00043> in <filename unknown>:0 
  at Mono.Cecil.MetadataBuilder.BuildTypes () <0x4606718 + 0x0002f> in <filename unknown>:0 
  at Mono.Cecil.MetadataBuilder.BuildModule () <0x4604000 + 0x000e3> in <filename unknown>:0 
  at Mono.Cecil.MetadataBuilder.BuildMetadata () <0x3af3fc0 + 0x00013> in <filename unknown>:0 
  at Mono.Cecil.ModuleWriter.BuildMetadata (Mono.Cecil.ModuleDefinition module, Mono.Cecil.MetadataBuilder metadata) <0x3af3eb0 + 0x0002b> in <filename unknown>:0 
  at Mono.Cecil.ModuleWriter.WriteModuleTo (Mono.Cecil.ModuleDefinition module, System.IO.Stream stream, Mono.Cecil.WriterParameters parameters) <0x3af1660 + 0x00153> in <filename unknown>:0 
  at Mono.Cecil.ModuleDefinition.Write (System.IO.Stream stream, Mono.Cecil.WriterParameters parameters) <0x3af1558 + 0x00063> in <filename unknown>:0 
  at Mono.Cecil.ModuleDefinition.Write (System.String fileName, Mono.Cecil.WriterParameters parameters) <0x3af14d0 + 0x0004b> in <filename unknown>:0 
  at Mono.Cecil.AssemblyDefinition.Write (System.String fileName, Mono.Cecil.WriterParameters parameters) <0x3af1498 + 0x00023> in <filename unknown>:0 
  at ILRepacking.ILRepack.Repack () <0x29e15f0 + 0x00b37> in <filename unknown>:0 
  at ILRepacking.Application.Main (System.String[] args) <0x7e4ed8 + 0x00123> in <filename unknown>:0 

I don't really know ILRepack, but to me it appears that it tries to resolve a dependency of Newtonsoft.Json.dllnamedSystem.Runtime.Serialization.Formatters.FormatterAssemblyStyle`, which it can't find. I did some Googling and found the following SO link. This appears to be related, but I'm not sure how I can fix this. Any ideas?

clairernovotny commented 8 years ago

A few thoughts --

While I appreciate the effort, I'm not sure there's much benefit to getting this to build on Mono. The official builds & packages are created as part of the CI build on AppVeyor here: https://ci.appveyor.com/project/onovotny/referencegenerator

What would be helpful is updating the included targets file (https://github.com/onovotny/ReferenceGenerator/blob/master/src/ReferenceGenerator/NuSpec.ReferenceGenerator.targets) so that the tool runs when other solutions are using it on mono.

There's also another issue - right now the tool needs the Reference Assemblies for the PCL references in order to read their assembly versions. These files are all present on a Windows dev system. I have no idea if/where they'd be on a system with Mono on it. What we need are the equivalent of the assemblies under C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\{version}\Profile\{ProfileNumber}\*.

Without those Reference assemblies, the tool cannot get the data it needs for a "classic PCL". It can still work for a "modern PCL," that is one that uses the .NET Core references with a project.json file. Note that you can also have a project.json PCL that uses "classic" references too. Here's an example of that: https://github.com/Humanizr/Humanizer/blob/dev/src/Humanizer/project.json#L6.

ErikSchierboom commented 8 years ago

Okay, so would you rather I'd ditch the whole Mono building? I could also support a Mono build but skip the actual creation of the RefGen.exe tool, thereby losing the need for an Mono version of the buildpackagelayout.cmd file.

As for the NuSpec.ReferenceGenerator.Targets file, I'll look into that.

clairernovotny commented 8 years ago

You're welcome to get it building on mono if you'd like but I'm just not sure what benefit that adds overall. I'd rather not have to keep too many differences just to build on mono. I think there's much more value in ensuring the tool runs well on mono.

ErikSchierboom commented 8 years ago

Okay, when I try to use Mono to run the executable I get: File does not contain a valid CIL image. My best bet is that that is due to the ILMerge command.

How would I go about creating a minimal test project to see if I can get it working?