Creating .NET Core MVC and Angular 4 Single Page Application in Visual Studio 2017 from stratch

Hello everyone. This is my first English article. I will list the steps of creating an Angular 4 project on .NET Core MVC project using Visual Studio 2017 and Angular CLI.

  1. Install Visual Studio 2017 Community Edition on Windows. Use installer to install .NET Core and NodeJS workloads.
  2. Install latest version of NodeJS and NPM
  3. Install Angular CLI using npm
  4. Create a blank solution and add a .NET Core MVC Web Application to it using Visual Studio 2017. My project name is Admin. (do not use . (dot) and special characters in project name.)
  5. Open command prompt, go to solution directory using cd command, type the following command and press enter:
    ng new Admin --routing --skip-git --directory Admin

    Angular CLI adds an angular project to the the MVC project named Admin that we created at the previous step. After creation of the angular project, you can serve this angular project and test it.

  6. Open the .angular-cli.json at the root of the project, change the outDir as “wwwroot”
  7. Open the tsconfig.json and change the outDir as “./wwwroot/out-tsc”
  8. Open the Home/Index.cshtml change the content of it as follows:
    Layout = null;
<!doctype html>
  <meta charset="utf-8">
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  	<link rel="icon" type="image/x-icon" href="favicon.ico">
  <script type="text/javascript" src="~/inline.bundle.js"></script>
  <script type="text/javascript" src="~/polyfills.bundle.js"></script>
  <script type="text/javascript" src="~/styles.bundle.js"></script>
  <script type="text/javascript" src="~/vendor.bundle.js"></script>
  <script type="text/javascript" src="~/main.bundle.js"></script>

9. You should exclude node_modules directory from the project in Visual Studio.

10. Open Project Properties and go to tab Build Events write the following command at the textarea:

echo "building angular app" &&^
ng build

Now you can run the application from Visual Studio 2017. The angular app will be built and the you will see the app in browser. But this project does not support production build, so you have to manually build the angular app or restart the project again to see the changes.

The next step is to install and configure webpack to enable production build.

Happy coding.


Bir Cevap Yazın

Aşağıya bilgilerinizi girin veya oturum açmak için bir simgeye tıklayın: Logosu hesabınızı kullanarak yorum yapıyorsunuz. Çıkış  Yap /  Değiştir )

Facebook fotoğrafı

Facebook hesabınızı kullanarak yorum yapıyorsunuz. Çıkış  Yap /  Değiştir )

Connecting to %s