将 Angular 4 添加到 ASP.NETCore 项目 [英] Add Angular 4 to an ASP.NETCore Project

查看:19
本文介绍了将 Angular 4 添加到 ASP.NETCore 项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Visual Studio 2017 中的 ASP.NetCore 1.1 项目中使用 Angular 4(读取为:*.csproj 文件)

I want to utilize Angular 4 in my ASP.NetCore 1.1 project, within Visual Studio 2017 (read as: *.csproj file)

在以前的 ASP.NET Core 1.0 和 Visual Studio 2015 中,您可以简单地将 AngularJS (1.xx) 作为依赖项添加到 project.json 中,它会自行连接.

Previously with ASP.NET Core 1.0 and Visual Studio 2015, you could simply add AngularJS (1.x.x) into the project.json as a dependency and it would wire itself in.

现在,使用 ASP.NetCore 和 VS2017,project.json 文件已经消失,我能找到的唯一文档是使用 CLI 和使用 CLI 启动 Angular 4 项目生成一个新的角度应用程序.我真的不想要一个新项目,也不需要重构我创建的所有东西来为单独的 UI 项目提供服务.我只是想通过一些额外的客户端 UI 体验来增强我的应用程序.

Now, with ASP.NetCore and VS2017, the project.json file has gone away, and the only documentation I can find refers to STARTING an Angular 4 project by using the CLI and using the CLI to generate a NEW angular app. I don't really want a new project or have to refactor everything I have created to provide a service to a separate UI project. I just want to augment my app with some added client-side UI experience.

有什么建议吗?

这个问题已经获得了很多关注,而且信息没有什么帮助,所以我提供了这个更新.

This questions has been getting a lot of views and the information is of little help so I'm providing this update.

Visual Studio 2017 (*.csproj)

Visual Studio 2017 (*.csproj)

  • Asp.Net Core 2.0 + Angular (v2.0~v4.0) :: 使用内置模板!最佳选择 IMO.

  • Asp.Net Core 2.0 + Angular (v2.0~v4.0) :: Use the built in template! Best option IMO.

Asp.Net Core 1.X + Angular (v2.0~v4.0)

Asp.Net Core 1.X + Angular (v2.0~v4.0)

  • 创建 VS 项目.
  • 通过 Angular CLI 创建 Angular 项目
  • 配置和设置详情:链接

Visual Studio 2015 (project.json)

Visual Studio 2015 (project.json)

  • 工具:最高版本 -preview2 - 没有进一步更新,所有新的 .NET Core 功能都将移至 VS 2017

  • Tooling: up to version -preview2 - No further updates, all new .NET Core features will be moving to VS 2017

  • Asp.Net Core 1.X + Angular (v2.0~v4.0)

  • Asp.Net Core 1.X + Angular (v2.0~v4.0)

  • Asp.Net Core 模板包
  • 注意:我不会认可糟糕的 VS 插件,Mads Kristensen 做得很好.
  • 配置和设置详情:博文

Asp.Net Core 1.X + AngularJS (~1.5)

Asp.Net Core 1.X + AngularJS (~1.5)

Asp.Net MVC 5 + AngularJS (~1.5)

Asp.Net MVC 5 + AngularJS (~1.5)

注意:还有 许多 其他方法可以让 Angular 与 ASP.Net/.NetCore 项目(如 NPM、Bower、NuGet 等)一起工作.我试图强调那些简单且实际工作.根据上面的 Pluralsight 博客文章,这些也符合微软的发展方向.

Notes: There are many other ways to get Angular to work with ASP.Net / .NetCore projects such as NPM, Bower, NuGet, etc. I tried to highlight the ones which are simple and actually work. Also these are in line with the direction Microsoft is moving in, according to the Pluralsight blog post above.

推荐答案

[我知道你没有特别问这个问题,只是想分享一个我认为非常相关的想法]

[i am aware you didn't ask this specifically but just wanted to share a thought which is very relevant in my opinion]

几个月前我处于完全相同的位置,我决定使用 angular cli.我感谢上帝,我做出了这个决定.无比清晰,它实际上把事情放在了应有的样子:.net core web api 后端和完全分离的 angular 客户端.就像您不会将您的 iphone/android 应用程序放入 VS 解决方案一样,也没有真正的理由将 Angular 应用程序放入 VS 解决方案中.

I was at the exactly the same point a few months ago and i decided going with angular cli. and i thank God i made that decision. Uncomparably more clear and it actually put things how they should be: .net core web api backend and completely separated angular client. just exactly the same as you wouldn't put your iphone/android app into VS solution, there is no real reason to put angular one neither.

更新要么将 MVC 与 Razor 一起使用,要么将 Angular 用作 SPA,如果您使用 Angular,请使用 Angular CLI.如果您使用 Angular,请使用 asp.net (core) Web Api 作为 REST 后端将数据输入其中

UPDATE Either use MVC with Razor, OR use Angular as a SPA, and if you use Angular, use the Angular CLI. And if you use angular, feed data into it with asp.net (core) Web Api as a REST backend

这篇关于将 Angular 4 添加到 ASP.NETCore 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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