.NetCore应用多个target framework

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
<TargetFrameworks>net462;netcoreapp2.0</TargetFrameworks>
</PropertyGroup> <ItemGroup Condition="'$(TargetFramework)' == 'net462'">
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
</ItemGroup>
</Project>

csporj如上所示

TargetFrameworks可添加多个运行框架
在ItemGroup中增加Condition条件判断即可引用不同版本的package

.NetCore应用多个target framework

调试时可选择不同framework进行调试

.NetCore应用多个target framework

发布时也可选择不同framework进行发布

上一篇:利用git+hugo+markdown 搭建一个静态网站


下一篇:使用EF Code First搭建一个简易ASP.NET MVC网站,允许数据库迁移