title: How to Multi target a library project with WPF controls
body: <p>I have a class library project that needs to target .NET 3.5 and .NET 4.0, and the way it is done now is the typical way of creating separate projects per target framework and linking files in each project to the same source.</p>
  
  <p>I would like to take advantage of the new csproj format that has come out with .NET Core projects because multitargeting is much simpler with the new csproj format.</p>
  
  <p>I created a new Class Library (.NET Core) project and started to try porting my existing library over.</p>
  
  <p>I don't really need to target .netcoreapp2.0, so my target frameworks look like this</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;PropertyGroup&gt;
    &lt;TargetFrameworks&gt;net35;net40&lt;/TargetFrameworks&gt;
  &lt;/PropertyGroup&gt;
  </code></pre>
  
  <p>and I have the following block of code to help with the <a href="https://github.com/Microsoft/msbuild/issues/1333#issuecomment-296346352" rel="nofollow noreferrer">.NET 3.5 oddities</a> with the new csproj format.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;PropertyGroup&gt;
    &lt;FrameworkPathOverride Condition="'$(TargetFramework)' == 'net35'"&gt;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client&lt;/FrameworkPathOverride&gt;
  &lt;/PropertyGroup&gt;
  </code></pre>
  
  <p>So far so good. Where things started going downhill is the fact that my class library has WPF Controls. I was getting compile errors because it couldn't find <code>System.Windows</code> and other WPF related items.</p>
  
  <p>I found I could add references to other windows assemblies, so I added the following</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;ItemGroup&gt;
    &lt;Reference Include="PresentationFramework" /&gt;
    &lt;Reference Include="PresentationCore" /&gt;
    &lt;Reference Include="WindowsBase" /&gt;
  &lt;/ItemGroup&gt;
  </code></pre>
  
  <p>This got rid of most of my errors, but now I am getting errors like <code>The name 'InitializeComponent' does not exist in the current context</code></p>