Create a .NET 4.0 library from a PCL project where the code is identical

This is pretty annoying, I have a portable class library library (PCL) that had to abandon .NET 4.0 in the profile in order to access the correct API β€œon the PCL ground”. However, these APIs exist in .NET 4.0, so if the same code is in a .NET 4.0 project, it compiles just fine.

I need a minimal way to continue recompiling the code in this PCL project on .net 4.0, so I can include it in the Nuget package.

+3
source share
2 answers

.csproj msbuild .net 4.0.

Build.proj:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <ItemGroup> 
        <ProjectToBuild Include="MyPortableSolution.sln">
            <Properties>Configuration=Release;</Properties>
        </ProjectToBuild>
        <ProjectToBuild Include="MyPortableSolution.sln">
            <Properties>Configuration=Release;OutputPath=bin\Release.net40\;IntermediateOutputPath=obj\Release.net40\;UseNet40=true;</Properties>
        </ProjectToBuild>
    </ItemGroup>
    <Target Name="Build">
        <MSBuild Projects="@(ProjectToBuild)"/>
    </Target>
</Project>

MyPortableProj.csproj:

:

<TargetFrameworkProfile>Profile46</TargetFrameworkProfile>

<UseNet40 Condition=" '$(UseNet40)' == '' ">false</UseNet40>
<TargetFrameworkProfile Condition="$(UseNet40) == false">Profile46</TargetFrameworkProfile>

:

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />

<Import Condition="$(UseNet40) == true" Project="$(SolutionDir)\refs.targets" />
<Import Condition="$(UseNet40) == true" Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Condition="$(UseNet40) == false" Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />

refs.targets

( ):

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <Reference Include="mscorlib" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System" />
    <Reference Include="System.Core" />
  </ItemGroup>
</Project>

: , Visual Studio .

msbuild Build.proj

lib bin\Release .net 40 lib bin\Release.net40

+8

, " ".

pcl analyzer, , 4.0

  • , pcl , .
  • , .
+3

All Articles