スポンサーリンク

Yeomanのgenerator-aspnetがBeta 7対応した

generator-aspnet – yo generator for ASP.NET 5

情報源: OmniSharp/generator-aspnet

Yeomanのgenarator-aspnetがアップデートしてASP.NET 5 Beta 7対応したので試してみます。

既にインストールされている人は以下でアップデートします。

$ npm update -g genartor-aspnet

新規にインストールする場合は過去記事を参照。

インストール/アップデートが終わったとして、yoでアプリケーションを作ります。

$ yo aspnet

     _-----_
    |       |    .--------------------------.
    |--(o)--|    |      Welcome to the      |
   `---------´   |   marvellous ASP.NET 5   |
    ( _´U`_ )    |        generator!        |
    /___A___\    '--------------------------'
     |  ~  |
   __'.___.'__
 ´   `  |° ´ Y `

? What type of application do you want to create?
  Empty Application
  Console Application
> Web Application
  Web Application Basic [without Membership and Authorization]
  Web API Application
  Nancy ASP.NET Application
  Class Library
  Unit test project

作成するWeb Applicationの名前を聞いてくるので、HelloWebとします。

? What type of application do you want to create? Web Application
? What's the name of your ASP.NET application? HelloWeb
   create HelloWeb\gulpfile.js
   create HelloWeb\.bowerrc
 .
 .
 .
   create HelloWeb\wwwroot\js\site.js


Your project is now created, you can use the following commands to get going
    cd "HelloWeb"
    dnu restore
    dnu build (optional, build will also happen when it's run)
    dnx ConsoleApplication for console projects
    dnx kestrel or dnx web for web projects

これでアプリケーションが作成されたので、HelloWebディレクトリに移動して、dnu restoreします。

$ dnu restore
Microsoft .NET Development Utility CoreCLR-x64-1.0.0-beta7-15532

  CACHE https://www.nuget.org/api/v2/
Restoring packages for C:\Users\ishisaka\src\aspnet\HelloWeb\project.json
  CACHE https://www.nuget.org/api/v2/FindPackagesById()?id='System.Threading.ThreadPool'
  CACHE https://www.nuget.org/api/v2/FindPackagesById()?id='System.Net.Sockets'
Writing lock file C:\Users\ishisaka\src\aspnet\HelloWeb\project.lock.json
Restore complete, 1905ms elapsed

NuGet Config files used:
    C:\Users\ishisaka\AppData\Roaming\NuGet\NuGet.Config

Feeds used:
    https://www.nuget.org/api/v2/

次に.がいらなくなったdnxコマンドでアプリケーションを起動しますが、問題が起きます。

 dnx web
info    : [Microsoft.Framework.DependencyInjection.DataProtectionServices] User profile is available. Using 'C:\Users\ishisaka\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
info    : [Microsoft.Net.Http.Server.WebListener] Start
info    : [Microsoft.Net.Http.Server.WebListener] Listening on prefix: http://localhost:5000/
Application started. Press Ctrl+C to shut down.
error   : [Microsoft.AspNet.Diagnostics.ErrorHandlerMiddleware] An unhandled exception has occurred: One or more compilation failures occured:
Views\_ViewImports.cshtml(1,7): DNXCore,Version=v5.0 error CS0246: The type or namespace name 'WebApplication' could not be found (are you missing a using directive or an assembly reference?)
Views\_ViewImports.cshtml(2,7): DNXCore,Version=v5.0 error CS0246: The type or namespace name 'WebApplication' could not be found (are you missing a using directive or an assembly reference?)

一見問題無く起動するように見えますが、最初のアクセスで、_ViewImports.cshtmlがエラーを出します。

名前解決が出来ていないようです。ソースを見てみます。
views/_ViewImports.cshtmlが以下の内容です。

@using WebApplication
@using WebApplication.Models
@using WebApplication.ViewModels.Account
@using WebApplication.ViewModels.Manage
@using Microsoft.AspNet.Identity
@addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers"

usingで読み込もうとしている名前空間がテンプレートのままで、スキャフォールディング時にうまく変換されていないようです。

このため、上のWebApplicationと書かれている部分を全てアプリケーション名であるHelloWebに変更します。

@using HelloWeb
@using HelloWeb.Models
@using HelloWeb.ViewModels.Account
@using HelloWeb.ViewModels.Manage
@using Microsoft.AspNet.Identity
@addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers"

変更して保存したら、dnx webでアプリケーションを起動します。

SnapCrab_Home Page - HelloWeb - Google Chrome_2015-9-5_22-32-55_No-00

変更後は問題無く表示されます。

NancyはBeta 7で動きませんし、目玉のはずのテストプロジェクトもまだ問題があるようですが、Beta 7でもスキャフォールディングで開発していくための環境が整いつつあるので、ぜひお試し行きましょう。

追記:

大事な物を忘れていました。generator-aspnetが作成するproject.jsonです。ご鑑賞ください。Sqliteを使うようになっていたりですとか、EntityFrameworkのコマンドが用意されていたりとか、ライブラリ指定が変わっただけでも無いようです。

{
  "webroot": "wwwroot",
  "userSecretsId": "aspnet5-HelloWeb-2b7b93af-5ae5-4c48-9060-7826ee44e366",
  "version": "1.0.0-*",

  "dependencies": {
    "EntityFramework.SQLite": "7.0.0-beta7",
    "EntityFramework.Commands": "7.0.0-beta7",
    "Microsoft.AspNet.Mvc": "6.0.0-beta7",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta7",
    // 途中略
    "Microsoft.Framework.Logging": "1.0.0-beta7",
    "Microsoft.Framework.Logging.Console": "1.0.0-beta7",
    "Microsoft.Framework.Logging.Debug" : "1.0.0-beta7",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-beta7"
  },

  "commands": {
    "kestrel": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --config hosting.ini",
    "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --config hosting.ini",
    "ef": "EntityFramework.Commands"
  },

  "frameworks": {
    "dnx451": {},
    "dnxcore50": {}
  },

  "exclude": [
    "wwwroot",
    "node_modules",
    "bower_components"
  ],
  "publishExclude": [
    "node_modules",
    "bower_components",
    "**.xproj",
    "**.user",
    "**.vspscc"
  ],
  "scripts": {
    "prepublish": [
      "npm install",
      "bower install",
      "gulp clean",
      "gulp min"
    ]
  }
}

コメント

タイトルとURLをコピーしました