asp.net-mvc – 使用.net mvc在IIS角度2应用程序上发布

我用mvc设置了一个有角度的2应用程序.

我正在使用typescript 2.3.1.0 for visual studio.

我安装了节点模块并添加了对angular 2的引用.

意见 – >首页 – >索引文件 –

@{
    ViewBag.Title = "Home Page";
}
<div class="jumbotron">
    <h1>Angular 2 QuickStart</h1>
</div>
<div class="row">
    <div class="col-md-4">
        <!-- Angular2 Code -->
        <my-app>Loading...</my-app>
        <!-- Angular2 Code -->
    </div>
</div>

我添加了所有对我的观点的引用 – >共享 – >布局文件 –

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="google-signin-client_id" content="118134028665-i6h833e7irrrhk0n52bgj7ve6fet4vgr.apps.googleusercontent.com">
    <title>@ViewBag.Title - My ASP.NET Application</title>

    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")

    <!-- Angular2 Code -->
    <base href="/">
    <link rel="stylesheet" href="styles.css">
    <!-- Polyfill(s) for older browsers -->
    <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Intl.~locale.en"></script>
    <script src="https://code.angularjs.org/tools/system.js"></script>
    <script src="node_modules/core-js/client/shim.min.js"></script>
    <script src="node_modules/zone.js/dist/zone.js"></script>
    <script src="node_modules/reflect-metadata/Reflect.js"></script>
    <script src="node_modules/systemjs/dist/system.src.js"></script>
    <script src="systemjs.config.js"></script>
    <script>
      System.import('app').catch(function(err){ console.error(err); });
    </script>
    <!-- Angular2 Code -->

</head>
<body>
    <script src="~/Scripts/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script src="~/JS/SocialLogin.js" type="text/javascript"></script>
    <script src="https://apis.google.com/js/platform.js" async defer></script>
    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
            </div>
            <div class="navbar-collapse collapse">
            </div>
        </div>
    </div>
    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
        </footer>
    </div>

    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)
</body>
</html>

这是我的package.json文件 –

{
  "name": "angular-quickstart",
  "version": "1.0.0",
  "scripts": {
    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
    "lite": "lite-server",
    "postinstall": "typings install",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "typings": "typings"
  },
  "license": "ISC",
  "dependencies": {
    "@angular/common": "2.0.0",
    "@angular/compiler": "2.0.0",
    "@angular/core": "2.0.0",
    "@angular/forms": "2.0.0",
    "@angular/http": "2.0.0",
    "@angular/platform-browser": "2.0.0",
    "@angular/platform-browser-dynamic": "2.0.0",
    "@angular/router": "3.0.0",
    "@angular/upgrade": "2.0.0",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.3",
    "rxjs": "5.0.0-beta.12",
    "systemjs": "0.19.27",
    "zone.js": "^0.6.23",
    "angular2-in-memory-web-api": "0.0.20",
    "bootstrap": "^3.3.6"
  },
  "devDependencies": {
    "concurrently": "^2.2.0",
    "lite-server": "^2.2.2",
    "typescript": "^2.0.2",
    "typings":"^1.3.2"
  }
}

这是我的systemjs.config.js文件 –

(function (global) {
  System.config({
    paths: {
      // paths serve as alias
      'npm:': 'node_modules/'
    },
    // map tells the System loader where to look for things
    map: {
      // our app is within the app folder
      app: 'app',
      // angular bundles
      '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
      '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
      '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
      '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
      '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
      '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
      '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
      // other libraries
      'rxjs':                      'npm:rxjs',
      'angular-in-memory-web-api': 'npm:angular-in-memory-web-api',
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        main: './main.js',
        defaultExtension: 'js'
      },
      rxjs: {
        defaultExtension: 'js'
      },
      'angular-in-memory-web-api': {
        main: './index.js',
        defaultExtension: 'js'
      }
    }
  });
})(this);

当节点模块文件夹未包含在项目中时,它是成功构建的,当我运行它时工作正常.

一旦我发布它并将发布移动到开发服务器并将其部署在IIS上,mvc就会运行但是角度2不会.
这些是我得到的错误 –

《asp.net-mvc – 使用.net mvc在IIS角度2应用程序上发布》

我假设我得到这个错误,因为缺少节点模块文件夹.

如果我回到项目并在项目中包含节点模块并构建它,我会收到这些错误 –

Severity Code Description Project File Line Suppression State
Error Build:File
‘E:/MyApp/MyApp/MyApp.Site/node_modules/browser-sync/node_modules/rx/ts/core/linq/observable/mergeproto.ts’
not found. MyApp.Site E:\MyApp\MyApp\MyApp.Site\tsc

Severity Code Description Project File Line Suppression State
Error Build:File
‘E:/MyApp/MyApp/MyApp.Site/node_modules/browser-sync/node_modules/rx/ts/core/linq/observable/zipproto.ts’
not found. MyApp.Site E:\MyApp\MyApp\MyApp.Site\tsc

我该如何解决这个问题?
在iis上使用.net mvc部署angular 2应用程序的正确方法是什么?
在此项目中包含节点模块的正确方法是什么?

谢谢!

最佳答案 我也面临同样的问题,没有得到适当的解决方案,

所以我使用了另一种解决方案.

>在IIS上独立部署MVC(API).
>使用ng prod单独构建Angular 2应用程序.
>部署Angular 2应用程序(dist文件夹)作为静态网站
    在IIS上.
>在Angular 2 API中使用已部署的API进行数据访问.

如果你有任何错误ping我.

点赞