Repository navigation
Description
Package building is currently disabled on non-Windows builds. If you enable it, ILRepack in GitVersionExe fails; but after tracing back through ILRepack and Mono.Cecil, I discovered that the actual problem is that GitVersionCore has invalid IL which is produced by the Fody Caseless plugin. Eliminating the Caseless plugin from FodyWeavers.xml in GitVersionCore avoids the corruption and allows ILRepack to complete successfully.
As an example of the corruption, this is the IL generated by mcs for the method ""...
.locals init (
bool V_0)
IL_0000: ldarg.1
IL_0001: ldarg.0
IL_0002: ldfld string GitVersion.VersionAssemblyInfoResources.AssemblyVersionInfoTemplates/'<AssemblyVersionInfoTemplates>c__AnonStorey0'::enclosingNamespace
IL_0007: dup
IL_0008: brtrue IL_0013
IL_000d: pop
IL_000e: ldsfld string [mscorlib]System.String::Empty
IL_0013: callvirt instance bool string::StartsWith(string)
IL_0018: stloc.0
IL_0019: br IL_001e
IL_001e: ldloc.0
IL_001f: ret
...and here is the same method after Fody Caseless has modified it:
.locals init (
bool V_0)
IL_0000: ldarg.1
IL_0001: ldarg.0
IL_0002: ldfld string GitVersion.VersionAssemblyInfoResources.AssemblyVersionInfoTemplates/'<AssemblyVersionInfoTemplates>c__AnonStorey0'::enclosingNamespace
IL_0007: dup
IL_0008: brtrue.s IL_0013
IL_000a: pop
IL_000b: ldsfld string [mscorlib]System.String::Empty
IL_0010: ldc.i4.5
IL_0011: callvirt instance bool string::StartsWith(string, valuetype [mscorlib]System.StringComparison)
IL_0016: stloc.0
IL_0017: br.s IL_0019
IL_0019: ldloc.0
IL_001a: ret
Note that in both the unmodified and modified versions, instruction IL_0008 is a conditional jump to instruction IL_0013 (with the modified version using the short form of the instruction). However, unlike in the unmodified version, the modified version has no instruction IL_0013; the jump should instead be to IL_0010.
Fody Caseless does not seem to produce the same corruption on Windows...
Unmodified:
.locals init ([0] bool CS$1$0000)
IL_0000: ldarg.1
IL_0001: ldarg.0
IL_0002: ldfld string GitVersion.VersionAssemblyInfoResources.AssemblyVersionInfoTemplates/'<>c__DisplayClass7'::enclosingNamespace
IL_0007: dup
IL_0008: brtrue.s IL_0010
IL_000a: pop
IL_000b: ldsfld string [mscorlib]System.String::Empty
IL_0010: callvirt instance bool [mscorlib]System.String::StartsWith(string)
IL_0015: stloc.0
IL_0016: br.s IL_0018
IL_0018: ldloc.0
IL_0019: ret
Modified:
.locals init ([0] bool CS$1$0000)
IL_0000: ldarg.1
IL_0001: ldarg.0
IL_0002: ldfld string GitVersion.VersionAssemblyInfoResources.AssemblyVersionInfoTemplates/'<>c__DisplayClass7'::enclosingNamespace
IL_0007: dup
IL_0008: brtrue.s IL_0010
IL_000a: pop
IL_000b: ldsfld string [mscorlib]System.String::Empty
IL_0010: ldc.i4.5
IL_0011: callvirt instance bool [mscorlib]System.String::StartsWith(string,
valuetype [mscorlib]System.StringComparison)
IL_0016: stloc.0
IL_0017: br.s IL_0019
IL_0019: ldloc.0
IL_001a: ret
Note that csc generated the short form of brtrue to begin with, and Fody did not modify it; whereas mcs generated the long form, and Fody changed it to the short form, but did not correctly adjust the target.
Since disabling Fody Caseless is presumably not an option, as that could have a potentially significant impact on GitVersion functionality, I will look into fixing Fody to correctly handle this case.
Activity
gep13 commentedon Jun 5, 2016
Any chance @SimonCropp can provide some input to this one? Thanks!
asbjornu commentedon Jun 6, 2016
@eatdrinksleepcode Would issues like this be easier to discover if Fody ran on Travis (Linux)? If so, I'd love to help setting that up.
eatdrinksleepcode commentedon Jun 6, 2016
@asbjornu Certainly they would :) I had to make some changes to Caseless to get it working on Mono/non-Windows; I will submit a PR with those in the next day or so.
eatdrinksleepcode commentedon Jun 6, 2016
I have a repro and a couple of options for a fix for the corruption issue (and an explanation of why it's not happening on Windows, which was the part that was really bothering me). It will take me a little while to write up the issue in Caseless, but when I do I will link it here.
asbjornu commentedon Jun 6, 2016
@eatdrinksleepcode Awesome work, thanks!
JakeGinnivan commentedon Jul 10, 2016
Looks like we just need to update to Caseless 1.4.2 to fix this issue
eatdrinksleepcode commentedon Jul 10, 2016
That was included as part of #890, so this should be resolved.
JakeGinnivan commentedon Jul 10, 2016
Awesome