0

Migrating project from Visual Studio 2008 to 2012 without changing the Target Framework, is changing the content of the output binary.

I'm using an MD5 signature to compare the file contents.

E9A487940134689A3D8E3B42FB1A9DCD - VS2008 compilation 11CC505F3B74A6B4AC5E9DB830F62B86 - VS2012 compilation

The changes made in the project during conversion is only in some source control bindings and no source code is changed.

Any ideas why the binary content changes?

Eric Lemes
  • 561
  • 3
  • 10
  • 4
    Um, because you're using a different compiler? Why do you need the binary to stay bytewise-identical? – Cameron Jul 28 '14 at 14:22
  • I'm just curious. If the build toolset is the same (same target version), I think it shouldn't change. Other idea is to convince some "managers" that changing the Visual Studio version won't have a huge impact in the application. – Eric Lemes Jul 28 '14 at 15:53
  • 1
    @EricLemes don't confuse target .NET Framework, language compiler, and the IDE. If you use a different language compiler then the output will be different. – jltrem Jul 28 '14 at 16:00
  • Fair enough :-) But the target framework does not dictate the toolchain -- the toolchain in VS2012 can compile code for older frameworks, but it is not the same as the toolchain from VS2008. I think running some tests (automated or by hand) on the new version would be a more practical choice for convincing management than identical binaries. – Cameron Jul 28 '14 at 16:00

1 Answers1

1

Different versions of the C# compiler support different language features. Sometimes there are significant differences between how something works in one version versus another (e.g., C#5's capture of the foreach iteration variable). Thus the output generated will be different. Jon Skeet's article on C# language versions is a nice overview.

VS2008 uses C#3 by default. VS2012 uses C#5.

You can specify a particular language version in a project's properties. Go to the Build tab, select the Advanced button, and pick from the Language Version dropdown. I'm assuming this is available in VS2012. I skipped from 2010 to 2013, and am going by the 2013 UI.

Community
  • 1
  • 1
jltrem
  • 12,124
  • 4
  • 40
  • 50
  • I'm not changing the target framework. The project is v3.5 and I didn't change it during the migration. Should the language version change even if I don't change the target framework? I'll do some tests with a C# project. Now I see that the project is VB.NET and didn't have the option to change the language version. – Eric Lemes Jul 28 '14 at 15:52
  • I mentioned nothing about Framework version. Moving to VC2008 to VC2012 will leave the targeted Framework alone. And if you were using the 'default' compiler for your project then it will change from using C#3 to C#5. I can't comment on VB but I imagine it would be similar. – jltrem Jul 28 '14 at 15:58
  • 1
    That's right. Using the same language version, the MD5 Hash are identical. – Eric Lemes Jul 28 '14 at 16:07
  • Any ideas on how to set the compiler version for VB.NET Projects? – Eric Lemes Jul 28 '14 at 16:15
  • (Disclaimer: I hate VB.NET, but this is a legacy application) – Eric Lemes Jul 28 '14 at 16:15
  • 1
    MSDN says there is a cmdln option, at least: http://msdn.microsoft.com/en-us/library/vstudio/dd547577(v=vs.110).aspx – jltrem Jul 28 '14 at 16:19
  • Weird. I did some digging into Microsoft.VisualBasic.targets and it sends the /langversion to VB Compiler using a "LangVersion" property. I set the propert inside the .vbproj (since it is a MSBuild file, it should work). I didn't have any error. In VS2008, the hash changed (because I've set the version to 9.0). In VS2012, using the same .vbproj, migrated with the LangVersion set, I have different Hashes... – Eric Lemes Jul 28 '14 at 16:42
  • This is getting conversational and drifting away from the original post. You might open another question on SO about this -- specifically dealing with compiler language versions & VB – jltrem Jul 28 '14 at 16:46