将 "dotnet new Angular" 项目转换为 net461?

Convert a "dotnet new Angular" project to net461?

我一直在玩通过

创建的项目
dotnet new Angular.

我喜欢它!

但我需要从我的项目中引用一个 .net 4.6.1 项目。我的第一个想法是将 Angular 项目更改为 .net 4.6.1 项目,因为一个 461 项目显然可以引用另一个这样的项目。所以我尝试更改 .csproj 文件,替换

<TargetFramework>netcoreapp2.0</TargetFramework>

<TargetFramework>net461</TargetFramework>.

但后来我遇到了一堆构建错误,首先是:

Package Microsoft.AspNetCore.All 2.0.0 is not compatible with net461 (.NETFramework,Version=v4.6.1) / win7-x86. Package Microsoft.AspNetCore.All 2.0.0 supports: netcoreapp2.0 (.NETCoreApp,Version=v2.0)   Angular C:\Code\Learning\angular\foo\AngularTest\Angular\Angular.csproj 1   

如果我删除对 Microsoft.AspNetCore.All 的引用,我会从代码中得到错误,提示缺少 Microsoft.AspNetCore.All。

我之前在 .net 4.6.1 中使用 Angular 没有问题。所以应该有办法做到这一点。但它是什么?

您可以在 Angular 模板中定位 net461,但您必须在 .csproj 文件中单独列出引用的程序集,而不是使用Microsoft.AspNetCore.All.

文件顶部看起来像这样。

<PropertyGroup>
    <TargetFramework>net461</TargetFramework>
    <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
    <TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="2.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" 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.AspNetCore.NodeServices" Version="2.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" PrivateAssets="All" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" PrivateAssets="All" />
    <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" PrivateAssets="All" />
  </ItemGroup>

我自己做了切换,成功了。