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

查看:148
本文介绍了将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应用程序来启动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项目

  • 配置和设置详细信息:< a href = https://medium.com/@levifuller/building-an-angular-application-with-asp-net-core-in-visual-studio-2017-visualized-f4b163830eaa rel = noreferrer>链接

  • Create VS Project.
  • Create Angular Project via Angular CLI
  • Configuration and setup details : Link

Visual Studio 2015(项目.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核心模板包

  • 注意:我不会赞同VS插件,Mads Kristensen做得很好。

  • 配置和设置详细信息:博客po st

  • Asp.Net Core Template Pack
  • Note: I wouldn't endorse a bad VS Plugin, Mads Kristensen does good work.
  • Configuration and setup details : Blog post

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

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

  • Configuration and setup details : Microsoft Tutorial

Asp.Net MVC 5 + AngularJS(〜1.5)

Asp.Net MVC 5 + AngularJS (~1.5)

  • Pluralsight Blog Guide

注:还有许多种其他方式可以使Angular与ASP.Net/.NetCore项目一起使用,例如NPM,Bower,NuGet等。试图强调那些简单且实际可行的方法。根据上述Pluralsight博客文章,这些也符合Microsoft的发展方向。

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]

几个月前我当时正好在同一点上,我决定去角cli。我感谢上帝,我做出了这个决定。
更加无比清晰,它实际上将它们放置为应有的样子:.net核心Web api后端和完全分离的有角度的客户端。就像您不会将iphone / android应用程序放入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.

UPDATE
要么将MVC与Razor一起使用,要么将Angular用作SPA,如果您使用Angular,请使用Angular CLI。
如果您使用angular,请使用asp.net(核心)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天全站免登陆