You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sorry this is not really an issue, but I didn't know where else I could reach out to get some insight on a project I have. I recently was tasked with creating a new asp.net core application, and I wanted to used Angular2 (via the angular cli), but I wasn't able to find any good documentation on how to get the two technologies working together. There is a yoeman generator to scaffold a .Net Core app with angular 2, but it doesn't make use of the CLI and uses a static index.cshtml as the root of the application so the links to the script files must also then be static.
I'm a really big fan of the angular-cli so I set out to create a solution that would allow me to take advantage of it. Here is what I've come up with Angular2AspNetCoreStarter but I didn't know where to go to get feedback, and I wanted to share this in case it can solve someone else's need for the cli in their .net core application.
Again I apologize for opening an issue for this, and if there is a more appropriate channel for these types of things I'd be happy to close the issue and move it there.
@wickdninja this is great, cheers. We're all traveling at the moment, but I'll forward this over to the people working on templates and such for Asp and VS with angular 👍
@wickdninja Would you mind writing up a brief tutorial about how to get Angular 2 running on an ASP.Net Core web server using the Angular CLI? I'd love to learn how to do this from scratch and I can't seem to get Angular to load (after generating a new project in wwwroot)
@Brocco reached out to me via twitter last week, but unfortunately I have not had the free time to start on the tutorial yet. It's on my schedule for this weekend though.
Would it be more useful to document the workflow I followed to create an Angular2 (via CLI)/ .Net Core project, or should I attempt to contribute to angular/angular.io#2850 ?
@wickdninja Exactly - Just the steps to get an Angular 2 app running and hosted on ASP.NET Core.
@juleskremer That tutorial looks like it uses razor so it technically wouldn't be an SPA, right? I'd prefer just to have the NG2 app statically hosted on an ASP.NET Core server.
I started my project this way and then separated the server and the client parts into two different projects. Much more manageable this way and VisualSutido 2015 sucks on editing .ts files.
Actually, the only IDE I know with ability to highlight syntax in internal templates is WebStorm.
Anyway, I run my .net core restful site on one port and separately run Angular app on 4200 using anular cli.
When I make a build for deployment I just tell anular cli to use wwwroot as output folder.
Of course in production you most likely will run both server and client parts on the same port so I prefix all my web service calls with variable from environment.???.ts file. For dev it could be 'http://localhost:60068/api'
and for prod just '/api'
app.Use(async(context,next)=>{awaitnext();if(context.Response.StatusCode==404){Console.WriteLine("passing to client");context.Request.Path="/";awaitnext();}});
Open browser and navigate to http://localhost:5000
Notice app works! text from our AppComponent is displayed on the screen
Verify API is working
Navigate to http://localhost://5000/api/values
The response should be the following JSON ["value1","value2"]
Reacted by yaronmil, sebastiaoherodes, Sebastian Nyberg, Thomas Sobieck, Ruslan Makrenko, Helmuth Saatkamp, Rok Dvojmoč, Bùi Xuân Hải, Cocioaba Cornel, albertchan and 1 more
@sebastiaoherodes I've used Visual Studio 2015 with a previous project using a similar setup. However, I still used VSCode for client side (angular) development, and only used Visual Studio for .Net code. If I can find some free time this weekend I'll extend the tutorial to include a similar setup. Off the top of my head I think the only differences would be to install the NPM Task Runner extension, disable Typescript compilation in Visual Studio 2015, and then inside the project.json file in the scripts section call the appropriate npm script or angular-cli command.
I wrote up a blog post on using Angular CLI inside of a Visual Studio MVC Web application with a different approach. All the relevant commands are included, plus a git repo with the final result and commits for each step along the way that you can review.
Essentially, you have 2 separate projects, a CLI project and an MVC web app (or core app), and a pre-build for the MVC web app does an ng build on the CLI project and copies the few output files to a folder of the MVC app which is then set as a Controller view. See the article for the details.
Are there any examples where this has been done together with server side rendering? All of the examples I have found so far uses webpack but I was hoping I could just use the Angular CLI like I do currently.
Activity
hansl commentedon Dec 15, 2016
(notifying our developer relationship team) @robwormald @StephenFluin @juleskremer Would this be useful somewhere as a reference?
@Brocco we could have a section on our WIKI for this too.
Closing this as it's not an issue.
Brocco commentedon Dec 15, 2016
I added this as a nice-to-have on the documentation tracking issue #2711
wickdninja commentedon Dec 15, 2016
thanks for the quick response
robwormald commentedon Dec 15, 2016
@wickdninja this is great, cheers. We're all traveling at the moment, but I'll forward this over to the people working on templates and such for Asp and VS with angular 👍
ChuckkNorris commentedon Feb 2, 2017
@wickdninja Would you mind writing up a brief tutorial about how to get Angular 2 running on an ASP.Net Core web server using the Angular CLI? I'd love to learn how to do this from scratch and I can't seem to get Angular to load (after generating a new project in
wwwroot)juleskremer commentedon Feb 2, 2017
FYI: we do have some work started on a tutorial which you can see here: angular/angular.io#2850
We are also working on VS templates for ASP.NET but will not look at CLI integration until later in the year.
wickdninja commentedon Feb 2, 2017
@ChuckkNorris
@Brocco reached out to me via twitter last week, but unfortunately I have not had the free time to start on the tutorial yet. It's on my schedule for this weekend though.
Would it be more useful to document the workflow I followed to create an Angular2 (via CLI)/ .Net Core project, or should I attempt to contribute to angular/angular.io#2850 ?
ChuckkNorris commentedon Feb 2, 2017
@wickdninja Exactly - Just the steps to get an Angular 2 app running and hosted on ASP.NET Core.
@juleskremer That tutorial looks like it uses razor so it technically wouldn't be an SPA, right? I'd prefer just to have the NG2 app statically hosted on an ASP.NET Core server.
ctrl-brk commentedon Feb 2, 2017
I started my project this way and then separated the server and the client parts into two different projects. Much more manageable this way and VisualSutido 2015 sucks on editing .ts files.
Actually, the only IDE I know with ability to highlight syntax in internal templates is WebStorm.
Anyway, I run my .net core restful site on one port and separately run Angular app on 4200 using anular cli.
When I make a build for deployment I just tell anular cli to use wwwroot as output folder.
Of course in production you most likely will run both server and client parts on the same port so I prefix all my web service calls with variable from environment.???.ts file. For dev it could be 'http://localhost:60068/api'
and for prod just '/api'
wickdninja commentedon Feb 6, 2017
@Brocco @ChuckkNorris
Here's my first crack at it.
Repo: https://github.com/wickdninja/DotNetCoreAngular2Demo
ReadMe is the step by step guide. Any feedback would be greatly appreciated.
Copied below as well.
ASP.NET Core / Angular 2 via CLI Quick Start
Disclaimer
This guide was created using the following versions, and provides no guarentee for compatibility with any other versions.
Install Project Dependencies
$ npm i -g yo$ npm i -g generator-aspnet$ npm i -g angular-cliGenerate Project
$ yo aspnetDemoApp$ cd DemoAppServer Setup
Open project.json
Exclude
node_modulesfrom compilationAdd the following to
"buildOptions"Add StaticFiles dependency
"Microsoft.AspNetCore.StaticFiles": "1.0.0"todependenciesRestore dependencies
$ dotnet restoreConfigure server to handle api routes and client side routes
Startup.csConfiguremethod add the following to itConfigure CORS
Route requests to root for client side spa
Enable static files (without allow directory browsing)
Setup routes for API
Verify changes by building server
$ dotnet buildClient Setup
$ ng new DemoApp$ mv DemoApp/* ..editorconfig$ mv DemoApp/.editorconfig .$ mv DemoApp/.git .DemoApp/.gitignoreinto./gitignore#wwwroot#character$ rm -rf DemoAppangular-cli.jsonoutDir"outDir": "wwwroot"$ ng buildBuild Scripts
Open
project.jsonscriptswith the followingRun App
$ npm startNow listening on: http://localhost:5000http://localhost:5000app works!text from our AppComponent is displayed on the screenhttp://localhost://5000/api/values["value1","value2"]sebastiaoherodes commentedon Feb 17, 2017
@wickdninja Great Work!. Is there a way to use Visual Studio 2015?
wickdninja commentedon Feb 17, 2017
@sebastiaoherodes I've used Visual Studio 2015 with a previous project using a similar setup. However, I still used VSCode for client side (angular) development, and only used Visual Studio for .Net code. If I can find some free time this weekend I'll extend the tutorial to include a similar setup. Off the top of my head I think the only differences would be to install the NPM Task Runner extension, disable Typescript compilation in Visual Studio 2015, and then inside the
project.jsonfile in the scripts section call the appropriate npm script or angular-cli command.Such as
Do you think this would be a useful addition?
michael-lang commentedon Apr 12, 2017
I wrote up a blog post on using Angular CLI inside of a Visual Studio MVC Web application with a different approach. All the relevant commands are included, plus a git repo with the final result and commits for each step along the way that you can review.
http://candordeveloper.com/2017/04/12/how-to-use-angular-cli-with-visual-studio-2017/
Essentially, you have 2 separate projects, a CLI project and an MVC web app (or core app), and a pre-build for the MVC web app does an ng build on the CLI project and copies the few output files to a folder of the MVC app which is then set as a Controller view. See the article for the details.
juleskremer commentedon Apr 12, 2017
@michael-lang thanks, I'm on vacation but will review when I return.
ChuckkNorris commentedon Apr 12, 2017
@michael-lang also wrote up an article for creating an ASP.NET Core app with the Angular-CLI in a single project.
https://medium.com/@levifuller/building-an-angular-application-with-asp-net-core-in-visual-studio-2017-visualized-f4b163830eaa
grzech666 commentedon May 14, 2017
I tested following: http://www.sparkhound.com/learn/blog/setting-up-an-asp-net-core-project-with-angular-2-utilizing-angular-cli by Vance F., this is the best solution for me,
challe commentedon Jun 15, 2017
Are there any examples where this has been done together with server side rendering? All of the examples I have found so far uses webpack but I was hoping I could just use the Angular CLI like I do currently.
maxisam commentedon Sep 11, 2017
@challe I just put together a repo like what you were asking
https://github.com/maxisam/DotNetCoreNgCli/tree/master/dotNetCoreNgCli
angular-automatic-lock-bot commentedon Sep 7, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.