XML Serialization Assembly Generation With Visual Studio

The built-in option to “generate XML serialization assembly” in Visual Studio does not work. It only works for SOAP web proxies and this seems to have been hard-coded by Microsoft and they are not changing it. The open Microsoft Connect bug reports have been outstanding since Visual Studio 2008 was released and still exists in 2010.

Here is how to workaround the problem. Other people just call SGEN in the project post-build commands, but that does not flag the result as project output. A better way is to edit the project file in Notepad and add a call to the SGen MSBuild task in the “AfterBuild” task, as follows:-

<!—Call XML serialization assembly generation task after build because built-in Visual Studio option does not work –>
<Target Name="AfterBuild" DependsOnTargets="GenSerializationAssembly" />
<!– XML Serialization Assembly Generation –>
<Target Name="GenSerializationAssembly"
        DependsOnTargets="AssignTargetPaths;Compile;ResolveKeySource"
        Inputs="$(MSBuildAllProjects);@(IntermediateAssembly)"
        Outputs="$(OutDir)$(_SGenDllName)">
  <SGen BuildAssemblyName="$(TargetFileName)"
        BuildAssemblyPath="$(OutDir)"
        References="@(ReferencePath)"
        ShouldGenerateSerializer="true"
        UseProxyTypes="false"
        KeyContainer="$(KeyContainerName)"
        KeyFile="$(KeyOriginatorFile)"
        DelaySign="$(DelaySign)"
        ToolPath="$(SGenToolPath)">
    <Output TaskParameter="SerializationAssembly" ItemName="SerializationAssembly" />
  </SGen>
</Target>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s