Tuesday, February 8, 2011

Why won't Visual Studio 2005 generate an Xml Serialization assembly?

Why isn't Visual Studio 2005 generating a serialization setting when I set the project setting "Generate Serialization Assembly" to "On"?

  • It turns out that Dev Studio only honors this setting for Web Services.

    For non-web services you can get this to work by adding an AfterBuild target to your project file:

      <Target Name="AfterBuild" DependsOnTargets="AssignTargetPaths;Compile;ResolveKeySource" Inputs="$(MSBuildAllProjects);@(IntermediateAssembly)"  Outputs="$(OutputPath)$(_SGenDllName)">         
          <SGen BuildAssemblyName="$(TargetFileName)" BuildAssemblyPath="$(OutputPath)"  References="@(ReferencePath)" ShouldGenerateSerializer="true" UseProxyTypes="false" KeyContainer="$(KeyContainerName)" KeyFile="$(KeyOriginatorFile)" DelaySign="$(DelaySign)" ToolPath="$(SGenToolPath)">
              <Output TaskParameter="SerializationAssembly" ItemName="SerializationAssembly" />
          </SGen>
      </Target>
    

    See also:

    flipdoubt : +1 for this help, Adam! As a follow up question, is adding the SGen task to a project considered a best or worst practice? I'm hoping that it speeds up the performance of my app.
    From Adam Tegen
  • It can be done manually with sgen.exe.

    From Adam Tegen
  • Hey Adam, nice answer. Can you figure out a way to use the SGen MSBuild task and pass it the /f parameter to force the recreation of the serialization assembly after it is built? I would use the sgen.exe as a post-build event, but I can't find an environment variable for its path that is valid in the post-build event. Any ideas?

    From flipdoubt

0 comments:

Post a Comment