title: How to set SGEN toolpath in Msbuild to target 3.5 framework
body: <p>I've just upgraded a project from VS2008 to VS2010 but I'm still targeting the 3.5 framework. </p>
  
  <p>In my project file I have a custom task to run SGEN to generate my XmlSerializers.dll. However the version of sgen being run targets the 4.0 framework. As a result, when I run my application I get the error message:</p>
  
  <p>"Could not load file or assembly 'XXXX.XXXX.XmlSerializers' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded."</p>
  
  <p>The Sgen task looks like this:</p>
  
  <pre><code>  &lt;Target Name="AfterBuild" DependsOnTargets="AssignTargetPaths;Compile;ResolveKeySource" Inputs="$(MSBuildAllProjects);@(IntermediateAssembly)" Outputs="$(OutputPath)$(_SGenDllName)"&gt;
      &lt;!-- Delete the file because I can't figure out how to force the SGen task. --&gt;
      &lt;Delete Files="$(TargetDir)$(TargetName).XmlSerializers.dll" ContinueOnError="true" /&gt;
      &lt;SGen BuildAssemblyName="$(TargetFileName)" BuildAssemblyPath="$(OutputPath)" References="@(ReferencePath)" ShouldGenerateSerializer="true" UseProxyTypes="false" KeyContainer="$(KeyContainerName)" KeyFile="$(KeyOriginatorFile)" DelaySign="$(DelaySign)" ToolPath="$(SGenToolPath)"&gt;
        &lt;Output TaskParameter="SerializationAssembly" ItemName="SerializationAssembly" /&gt;
      &lt;/SGen&gt;
    &lt;/Target&gt;
  </code></pre>
  
  <p>There's the <strong>ToolPath="$(SGenToolPath)"</strong>. How do I make it run the version that targets 3.5?</p>
  
  <p>There's a similar question <a href="https://stackoverflow.com/questions/2746372/sgen-doesnt-work-after-upgrading-from-vs2008-to-vs2010">here</a> but it doesn't help me much.</p>