title: How can a project be built as a portable or a normal class library depending on the selected configuration?
body: <p><strong>Context:</strong> We have a common library project called 'THEPROJECT' that is shared with a Xamarin mobile solution and a web project in visual studio. This shared library is a PCL Profile259 due to restrictions in Xamarin. In our web application solution we would like to mark the data models with the appropriate attributes for <a href="https://msdn.microsoft.com/en-us/library/system.data.linq.datacontext(v=vs.90).aspx" rel="nofollow noreferrer">DataContext</a> to work correctly (as we want to use LinqToSql).</p>
  
  <p><strong>Attempted Solution:</strong> We decided to look into the project for 'THEPROJECT' and change the msbuild in a way that would allow it to exist in a state of portable library / normal class library depending on the selected configuration in visual studio.</p>
  
  <p>We have looked at the solution in <a href="https://stackoverflow.com/questions/14551881/can-i-get-a-sometimes-portable-class-library-project-to-load-in-visual-studio">this post</a> however it is only part of the solution. We can get the project to exist as one or the other, however it requires a manual change to the project file. Now we get the error loading the following project. The  for a portable project must be '.NETPortable'.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
      &lt;PropertyGroup&gt;
          &lt;Configuration Condition=" '$(Configuration)' == '' "&gt;DebugDesktop&lt;/Configuration&gt;
          &lt;Platform Condition="'$(Platform)' == ''"&gt;AnyCPU&lt;/Platform&gt;
          &lt;ProjectGuid&gt;{426E7BD8-9DA8-4E15-9512-72E7C632B037}&lt;/ProjectGuid&gt;
          &lt;OutputType&gt;Library&lt;/OutputType&gt;
          &lt;AppDesignerFolder&gt;Properties&lt;/AppDesignerFolder&gt;
          &lt;RootNamespace&gt;THEPROJECT&lt;/RootNamespace&gt;
          &lt;AssemblyName&gt;THEPROJECT&lt;/AssemblyName&gt;
          &lt;TargetFrameworkVersion&gt;v4.5&lt;/TargetFrameworkVersion&gt;
          &lt;MinimumVisualStudioVersion&gt;10.0&lt;/MinimumVisualStudioVersion&gt;
          &lt;BuildMode&gt;Desktop&lt;/BuildMode&gt;
      &lt;/PropertyGroup&gt;
  
      &lt;!-- Define the Build Configurations --&gt;
      &lt;PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugDesktop|AnyCPU' "&gt;
          &lt;DebugSymbols&gt;true&lt;/DebugSymbols&gt;
          &lt;DebugType&gt;full&lt;/DebugType&gt;
          &lt;Optimize&gt;false&lt;/Optimize&gt;
          &lt;OutputPath&gt;bin\Desktop\Debug\&lt;/OutputPath&gt;
          &lt;DefineConstants&gt;TRACE;DEBUG;&lt;/DefineConstants&gt;
          &lt;ErrorReport&gt;prompt&lt;/ErrorReport&gt;
          &lt;WarningLevel&gt;4&lt;/WarningLevel&gt;
          &lt;ConsolePause&gt;false&lt;/ConsolePause&gt;
          &lt;BuildMode&gt;Desktop&lt;/BuildMode&gt;
      &lt;/PropertyGroup&gt;
      &lt;PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseDesktop|AnyCPU' "&gt;
          &lt;DebugType&gt;pdbonly&lt;/DebugType&gt;
          &lt;Optimize&gt;true&lt;/Optimize&gt;
          &lt;OutputPath&gt;bin\Desktop\Release\&lt;/OutputPath&gt;
          &lt;DefineConstants&gt;TRACE&lt;/DefineConstants&gt;
          &lt;ErrorReport&gt;prompt&lt;/ErrorReport&gt;
          &lt;WarningLevel&gt;4&lt;/WarningLevel&gt;
          &lt;BuildMode&gt;Desktop&lt;/BuildMode&gt;
      &lt;/PropertyGroup&gt;
      &lt;PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'DebugPCL|AnyCPU' "&gt;
          &lt;DebugSymbols&gt;true&lt;/DebugSymbols&gt;
          &lt;DebugType&gt;full&lt;/DebugType&gt;
          &lt;Optimize&gt;false&lt;/Optimize&gt;
          &lt;OutputPath&gt;bin\PCL\Debug\&lt;/OutputPath&gt;
          &lt;DefineConstants&gt;TRACE;DEBUG;&lt;/DefineConstants&gt;
          &lt;ErrorReport&gt;prompt&lt;/ErrorReport&gt;
          &lt;WarningLevel&gt;4&lt;/WarningLevel&gt;
          &lt;ConsolePause&gt;false&lt;/ConsolePause&gt;
          &lt;BuildMode&gt;Portable&lt;/BuildMode&gt;
      &lt;/PropertyGroup&gt;
      &lt;PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleasePCL|AnyCPU' "&gt;
          &lt;DebugType&gt;pdbonly&lt;/DebugType&gt;
          &lt;Optimize&gt;true&lt;/Optimize&gt;
          &lt;OutputPath&gt;bin\PCL\Release\&lt;/OutputPath&gt;
          &lt;DefineConstants&gt;TRACE&lt;/DefineConstants&gt;
          &lt;ErrorReport&gt;prompt&lt;/ErrorReport&gt;
          &lt;WarningLevel&gt;4&lt;/WarningLevel&gt;
          &lt;BuildMode&gt;Portable&lt;/BuildMode&gt;
      &lt;/PropertyGroup&gt;
  
      &lt;!-- Determine the correct properties for PCL/Desktop --&gt;
      &lt;Choose&gt;
          &lt;When Condition=" '$(BuildMode)' == 'Portable' "&gt;
              &lt;PropertyGroup&gt;
                  &lt;ProjectTypeGuids&gt;{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}&lt;/ProjectTypeGuids&gt;
                  &lt;TargetFrameworkProfile&gt;Profile259&lt;/TargetFrameworkProfile&gt;
                  &lt;TargetFrameworkIdentifier&gt;.NETPortable&lt;/TargetFrameworkIdentifier&gt;
                  &lt;DynamicImportPath&gt;$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets&lt;/DynamicImportPath&gt;
              &lt;/PropertyGroup&gt;
          &lt;/When&gt;
          &lt;When Condition=" '$(BuildMode)' == 'Desktop' "&gt;
              &lt;PropertyGroup&gt;
                  &lt;FileAlignment&gt;512&lt;/FileAlignment&gt;
                  &lt;TargetFrameworkProfile /&gt;
                  &lt;DynamicImportPath&gt;$(MSBuildToolsPath)\Microsoft.CSharp.targets&lt;/DynamicImportPath&gt;
              &lt;/PropertyGroup&gt;
              &lt;ItemGroup&gt;
                  &lt;Reference Include="System.Data.Linq" /&gt;
              &lt;/ItemGroup&gt;
          &lt;/When&gt;
      &lt;/Choose&gt;
  
      &lt;ItemGroup&gt;
          &lt;Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"&gt;
              &lt;HintPath&gt;..\..\mobileapplication\packages\Newtonsoft.Json.8.0.2\lib\portable-net40+sl5+wp80+win8+wpa81\Newtonsoft.Json.dll&lt;/HintPath&gt;
              &lt;Private&gt;True&lt;/Private&gt;
          &lt;/Reference&gt;
          &lt;Reference Include="System" /&gt;
          &lt;Reference Include="System.Core" /&gt;
          &lt;Reference Include="System.Xml.Linq" /&gt;
          &lt;Reference Include="Microsoft.CSharp" /&gt;
          &lt;Reference Include="System.Xml" /&gt;
      &lt;/ItemGroup&gt;
      &lt;ItemGroup&gt;
          &lt;ProjectReference Include="..\..\sqlite-net-extensions\SQLiteNetExtensions\SQLiteNetExtensions-PCL.csproj"&gt;
              &lt;Project&gt;{f723017d-ede5-49cc-a84f-881c067c6004}&lt;/Project&gt;
              &lt;Name&gt;SQLiteNetExtensions-PCL&lt;/Name&gt;
          &lt;/ProjectReference&gt;
          &lt;ProjectReference Include="..\..\sqlitenetpcl\src\SQLite.Net\SQLite.Net.csproj"&gt;
              &lt;Project&gt;{4971d437-0694-4297-a8cc-146ce08c3bd9}&lt;/Project&gt;
              &lt;Name&gt;SQLite.Net&lt;/Name&gt;
          &lt;/ProjectReference&gt;
      &lt;/ItemGroup&gt;
  
      &lt;Import Project="$(DynamicImportPath)" /&gt;
  
      &lt;!-- Source/Resx etc... --&gt;
  &lt;/Project&gt;
  </code></pre>