生产从PCL项目一个.NET 4.0的图书馆,code是相同的 [英] Produce a .NET 4.0 library from a PCL Project where code is identical

查看:177
本文介绍了生产从PCL项目一个.NET 4.0的图书馆,code是相同的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是相当令人沮丧,我有一个可移植类库(PCL)库,必须在配置文件拖放.NET 4.0能够访问正确的API提出的PCL土地。然而,这些API的确实存在在.NET 4.0中,这样,如果完全相同的code是在.NET 4.0的项目它编译就好了。

It's quite frustrating, I have a Portable Class Library (PCL) library that had to drop .NET 4.0 in the profile to have access to the right API's "in PCL land". However, these API's do exist in .NET 4.0, such that if the exact same code is in a .NET 4.0 project it compiles just fine.

我希望有一个最小的后续维护的方式来重新编译code在此PCL项目.NET 4.0,所以我可以将其包含在的NuGet包。

I want a minimal ongoing maintenance way to recompile the code in this PCL project to .net 4.0 so I can include it in a Nuget package.

推荐答案

通过最小的条件调整 .csproj的,可以创建一个MSBuild项目编译移植库解决方案,以产生额外的.NET 4.0配置文件的二进制文件。

With minimal conditional adjustments to the .csproj, an msbuild project can be created to compile a portable library solution to produce additional .net 4.0 profile binaries.

<?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

这是用汇编引用的文件,你需要的(编辑从项目到项目)的:

Include a refs.targets

This is a file with the assembly references you need (edit from project to project):

<?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的分析和以其他方式显示它

这将在斌\发布和.net在斌\ Release.net40 40具体的lib

这篇关于生产从PCL项目一个.NET 4.0的图书馆,code是相同的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆