Question

It seems that SGen does not use the file version from the parent assembly but the AssemblyVersion instead. This is problematic if you want to keep the strong name constant and release via MSI API compatible patches.

If for example new data types are added the generated XmlSerializers assembly needs to be patched on the target machine. But MSI does only look at the file version (which is equal) and will do nothing.

Is there a way to instruct SGen to use as file version the one from the source assembly?

Example:

Source Assembly:

  [assembly: AssemblyVersion("2.0.0.0")]
  [assembly: AssemblyFileVersion("35.0.0.0")]

The generated Serializer Assembly will get 2.0.0.0 in PE Header for File and Product Version. This is wrong.

As last resort I would consider patching the file version of the generated assembly but I do fear that if the assembly is strong named it will not load anymore (have not tried it yet) because at least previous .NET Versions did create a hash of the complete file including the PE header.

Was it helpful?

Solution

The way to solve this problem is to create a code file that contains an assembly attribute for AssemblyFileVersion and tell sgen to include that file.

Create a file named XmlSerializersAssemblyInfo.cs with the following code:

[assembly:System.Reflection.AssemblyTitleAttribute("title")] 
[assembly:System.Reflection.AssemblyDescriptionAttribute("description")] 
[assembly:System.Reflection.AssemblyCompanyAttribute("company")] 
[assembly:System.Reflection.AssemblyProductAttribute("product")] 
[assembly:System.Reflection.AssemblyFileVersionAttribute("1.2.3.4")]

The sgen utility allows you to add compiler switches by using /c as follows:

sgen.exe" /a:"$(TargetPath)" /f /c:/keyfile:"$(ProjectDir)myApp.snk" /c:"$(ProjectDir)XmlSerializersAssemblyInfo.cs"

Add the sgen command to your post build events and voila! You get an XmlSerializer DLL with the AssemblyFileVersion and other assembly attributes that you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top