aspnet vnext でHello MVC


c:\oss\aspnet\Home\samples\HelloMvcWeb>kpm resore
c:\oss\aspnet\Home\samples\HelloMvcWeb>dir ..\..\packages /B
Common.1.0.0
K.Roslyn.0.1-alpha-build-0137
Microsoft.AspNet.Diagnostics.0.1-alpha-build-0682
Microsoft.AspNet.FeatureModel.0.1-alpha-build-0444
Microsoft.AspNet.FileSystems.0.1-alpha-build-0162
Microsoft.AspNet.Hosting.0.1-alpha-build-0572
Microsoft.AspNet.Http.0.1-alpha-build-0444
Microsoft.AspNet.HttpFeature.0.1-alpha-build-0444
Microsoft.AspNet.Mvc.0.1-alpha-build-1268
Microsoft.AspNet.Mvc.Core.0.1-alpha-build-1268
Microsoft.AspNet.Mvc.ModelBinding.0.1-alpha-build-1268
Microsoft.AspNet.Mvc.Razor.0.1-alpha-build-1268
Microsoft.AspNet.Mvc.Razor.Host.0.1-alpha-build-1268
Microsoft.AspNet.PipelineCore.0.1-alpha-build-0444
Microsoft.AspNet.Razor.0.1-alpha-build-0197
Microsoft.AspNet.RequestContainer.0.1-alpha-build-0572
Microsoft.AspNet.Routing.0.1-alpha-build-0577
Microsoft.AspNet.Security.0.1-alpha-build-0506
Microsoft.AspNet.Security.DataProtection.0.1-alpha-build-0153
Microsoft.AspNet.Server.WebListener.0.1-alpha-build-0520
Microsoft.Bcl.Immutable.1.1.20-beta
Microsoft.Bcl.Metadata.1.0.11-alpha
Microsoft.CodeAnalysis.Common.0.7.4051916-beta
Microsoft.CodeAnalysis.CSharp.0.7.4051916-beta
Microsoft.CSharp.4.0.0.0
Microsoft.DataAnnotations.0.1-alpha-build-0100
Microsoft.DataAnnotations.Core.0.1-alpha-build-0100
Microsoft.DataAnnotations.Supplemental.0.1-alpha-build-0100
Microsoft.Framework.ConfigurationModel.0.1-alpha-build-0233
Microsoft.Framework.DependencyInjection.0.1-alpha-build-0389
Microsoft.Framework.Logging.0.1-alpha-build-0172
Microsoft.Framework.Runtime.Interfaces.0.1-alpha-build-0446
Microsoft.Net.Server.0.1-alpha-build-0520
Microsoft.Win32.Primitives.4.0.0.0
Newtonsoft.Json.5.0.8
System.ApplicationContext.4.0.0.0
System.Collections.4.0.0.0
System.Collections.Concurrent.4.0.0.0
System.ComponentModel.4.0.0.0
System.Console.4.0.0.0
System.Diagnostics.Contracts.4.0.0.0
System.Diagnostics.Debug.4.0.10.0
System.Diagnostics.Tools.4.0.0.0
System.Dynamic.Runtime.4.0.0.0
System.Globalization.4.0.10.0
System.Globalization.Extensions.4.0.0.0
System.IO.4.0.0.0
System.IO.Compression.4.0.0.0
System.IO.FileSystem.4.0.10.0
System.IO.FileSystem.Primitives.4.0.20.0
System.Linq.4.0.0.0
System.Linq.Expressions.4.0.0.0
System.Net.Primitives.4.0.10.0
System.ObjectModel.4.0.0.0
System.Reflection.4.0.10.0
System.Reflection.Emit.ILGeneration.4.0.0.0
System.Reflection.Emit.Lightweight.4.0.0.0
System.Reflection.Extensions.4.0.0.0
System.Reflection.Primitives.4.0.0.0
System.Reflection.TypeExtensions.4.0.0.0
System.Resources.ResourceManager.4.0.0.0
System.Runtime.4.0.20.0
System.Runtime.Extensions.4.0.10.0
System.Runtime.Handles.4.0.0.0
System.Runtime.InteropServices.4.0.20.0
System.Runtime.Serialization.Primitives.4.0.0.0
System.Security.Claims.0.1-alpha-build-0286
System.Security.Cryptography.4.0.0.0
System.Security.Cryptography.Encoding.4.0.0.0
System.Security.Cryptography.HashAlgorithms.SHA2.4.0.0.0
System.Security.Cryptography.RandomNumberGenerator.4.0.0.0
System.Security.Cryptography.X509Certificates.4.0.0.0
System.Security.Principal.4.0.0.0
System.Security.SecureString.4.0.0.0
System.Text.Encoding.4.0.10.0
System.Text.Encoding.4.0.20.0
System.Text.Encoding.Extensions.4.0.10.0
System.Text.RegularExpressions.4.0.0.0
System.Threading.4.0.0.0
System.Threading.Overlapped.4.0.0.0
System.Threading.Tasks.4.0.0.0
System.Threading.Tasks.4.0.10.0
System.Threading.Thread.4.0.0.0
System.Threading.ThreadPool.4.0.10.0

大量だ。。。


c:\oss\aspnet\Home\samples\HelloMvcWeb>k run
'HelloMvc' does not contain a static 'Main' method suitable for an entry point

c:\oss\aspnet\Home\samples\HelloMvcWeb>k web
Started

http://localhost:5001/ でいつもの ASP.NET MVC のシンプルな奴が表示されるはずだがエラー。
バージョン番号はきちんとメンテされていないので最新を取ってくるように変更して


c:\oss\aspnet\Home\samples\HelloMvcWeb>git diff Project.json
diff --git a/samples/HelloMvc/project.json b/samples/HelloMvc/project.json
index ead5eca..23b0450 100644
--- a/samples/HelloMvc/project.json
+++ b/samples/HelloMvc/project.json
@@ -1,10 +1,10 @@
{
"version": "0.1-alpha-*",
"dependencies": {
- "Microsoft.AspNet.Diagnostics": "0.1-alpha-build-0682",
- "Microsoft.AspNet.Hosting": "0.1-alpha-build-0572",
- "Microsoft.AspNet.Mvc": "0.1-alpha-build-1268",
- "Microsoft.AspNet.Server.WebListener": "0.1-alpha-build-0520"
+ "Microsoft.AspNet.Diagnostics": "0.1-alpha-build-*",
+ "Microsoft.AspNet.Hosting": "0.1-alpha-build-*",
+ "Microsoft.AspNet.Mvc": "0.1-alpha-build-*",
+ "Microsoft.AspNet.Server.WebListener": "0.1-alpha-build-*"
},
"commands": {
"web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001"

c:\oss\aspnet\Home\samples\HelloMvcWeb>kpm restore
c:\oss\aspnet\Home\samples\HelloMvcWeb>k web
Started

http://localhost:5001/ でいつもの ASP.NET MVC のシンプルな奴が表示された。


c:\oss\aspnet\Home\samples\HelloMvc>dir /S /B /A-D
c:\oss\aspnet\Home\samples\HelloMvc\project.json
c:\oss\aspnet\Home\samples\HelloMvc\Startup.cs
c:\oss\aspnet\Home\samples\HelloMvc\Controllers\HomeController.cs
c:\oss\aspnet\Home\samples\HelloMvc\Models\User.cs
c:\oss\aspnet\Home\samples\HelloMvc\Views\Home\Index.cshtml
c:\oss\aspnet\Home\samples\HelloMvc\Views\Shared\_Layout.cshtml
c:\oss\aspnet\Home\samples\HelloMvc>type project.json
{
"version": "0.1-alpha-*",
"dependencies": {
"Microsoft.AspNet.Diagnostics": "0.1-alpha-build-*",
"Microsoft.AspNet.Hosting": "0.1-alpha-build-*",
"Microsoft.AspNet.Mvc": "0.1-alpha-build-*",
"Microsoft.AspNet.Server.WebListener": "0.1-alpha-build-*"
},
"commands": {
"web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001"
},
"configurations": {
"net45": {
"dependencies": {
"System.Runtime": "",
"System.ComponentModel.DataAnnotations": ""
}
},
"k10": {}
}
}
c:\oss\aspnet\Home\samples\HelloMvc>type Startup.cs
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Builder;
using Microsoft.Framework.DependencyInjection;

namespace KWebStartup
{
public class Startup
{
public void Configure(IBuilder app)
{
app.UseErrorPage();

app.UseServices(services =>
{
services.AddMvc();
});

app.UseMvc();

app.UseWelcomePage();
}
}
}
c:\oss\aspnet\Home\samples\HelloMvc>type Controllers\HomeController.cs
using Microsoft.AspNet.Mvc;
using MvcSample.Web.Models;

namespace MvcSample.Web
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View(User());
}

public User User()
{
User user = new User()
{
Name = "My name",
Address = "My address"
};

return user;
}
}
}

相変わらずファイルはBOMつきだな。。。。
Startup で DependencyInjection がいる。AddMvc でAsp.NET MVC で必要なクラスや Controller もコンテナに登録にいってる。
ActionResultからIActionResultに変更。
ViewBagは健在。Razor の構文はかわりなしな感じ。

Global.asax、Web.Conig がいない。
実際には https://github.com/aspnet/MusicStore/tree/dev/src/MusicStore をみると Web.Conig はいる。IISでうごかすためにもこれは残るのだろう。Razor も async/await している。。。