Habrã®é·ã
ç¥èãš
ç¥èã®ãã人ã
ãæ°ãã
ASP.Net Coreãè©ŠããŠã¿ãããã«ä¿ããã®ã§ãæè¿ãå°ããªASP.Net MVCã¢ããªã±ãŒã·ã§ã³ãæžãããšã«ããŸãããããã©ãŒãã³ã¹ã
Macã®åæ§ã®èšäºãåºç€ãšããŠåãäžããŸããããããã§ã¯ã
ç§ã«ã€ã³ã¹ãã¬ãŒã·ã§ã³ã
äžãã
èšäºãšã¯ç°ãªããããã»ã¹ã1ãæã§æ®µéçã«èª¬æããããšæããŸãã ããã»ã¹ã®ãã®ãããªè©³çŽ°ãªèª¬æã¯ãããããå€ãã®äººãç§ãçŽé¢ããªããã°ãªããªãã£ãã¬ãŒããé¿ããã®ã«åœ¹ç«ã€ã§ãããã Macã®èšäºããä¿®æ£ããã³ä¿®æ£ãå ããããã©ãããã©ãŒã ã®åãéšåã«ããããã€ãã®ãã¬ãŒãºãšå³ã
.Net CoreãšVisual Studio Codeãã€ã³ã¹ããŒã«ãã
ããã«èšèŒãããŠããã€ã³ã¹ããŒã«ã³ãã³ãã¯ãUbuntu 16.04 / Mint 18.xãã£ã¹ããªãã¥ãŒã·ã§ã³ã«é©ããŠã
ãŸã ãæ®ãã®éšåã«ã€ããŠã¯ã
ãã¡ããåç
§ããŠ
ãã ãã ã
.Net Coreã®ã€ã³ã¹ããŒã«ïŒ
ææ°ã®
aspnetãããžã§ã¯ã
ãžã§ãã¬ãŒã¿ãŒãšã®äºææ§ã®ããã«ãçŸæç¹ã§ææ°ã®RC4ãã€ã³ã¹ããŒã«ããŸãã
sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ xenial main" > /etc/apt/sources.list.d/dotnetdev.list' sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893 sudo apt-get update sudo apt install dotnet-dev-1.0.0-rc4-004771
Visual Studioã³ãŒããã€ã³ã¹ããŒã«ãã
ãã®ãªã³ã¯ãæ°åã¯ãªãã¯ããã ãã§ç°¡åã«ã€ã³ã¹ããŒã«ã§ããŸãã
CïŒæ¡åŒµæ©èœãã€ã³ã¹ããŒã«ãã
Visual Studio Codeãå®è¡ããCtrl-PãæŒããŠãã³ãã³ããå
¥åããŸãã
ext install csharp
å·ŠåŽã«è¡šç€ºãããããã«ã§ã察å¿ããæ¡åŒµæ©èœã®å察åŽã«ãããã€ã³ã¹ããŒã«ããã¯ãªãã¯ããŸãïŒãããèªåçã«è¡ãããªãå ŽåïŒã Visual Studio Codeã¯ä»ã®ãšããéããããšãã§ããŸãã
éçºç°å¢ã®æºåãšã¢ããªã±ãŒã·ã§ã³ãã³ãã¬ãŒãã®äœæ
ãªãªãžãã«ã®ãµã€ãïŒãã£ã¹ããªãã¥ãŒã·ã§ã³ã«ä»å±ããŠãããã®ã¯é©åããŸããïŒããææ°ã®node.jsãã€ã³ã¹ããŒã«ããŸããä»å±ã®
npmããã±ãŒãžãããŒãžã£ãŒã®ããã«å¿
èŠã§ãã
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash - sudo apt-get install -y nodejs sudo apt-get install -y build-essential
ä»ã®ãã£ã¹ããªãã¥ãŒã·ã§ã³ã«ã€ããŠã¯ã
ãã¡ãã®æé ã
ã芧ãã ãã ã
ãããžã§ã¯ãã®åæå
åæåã«ã¯ã
Yeoman scaffolderã䜿çšãããŸããããã¯ããã¡ã€ã«æ§é ã®å±éãšãããžã§ã¯ããã³ãã¬ãŒãã®çæãå«ããããžã§ã¯ãåæååã§ãã ã¢ããªã±ãŒã·ã§ã³ã®ãœãŒã¹ã³ãŒãã scaffolder YoãBowerããã±ãŒãžãããŒãžã£ãŒãGruntã¿ã¹ã¯ãããŒãžã£ãŒãå«ãŸããŠããŸãã Yoãã€ã³ã¹ããŒã«ãããšãBower and Gruntãã€ã³ã¹ããŒã«ãããŸãã ããã§ãproject.jsonã®ä»£ããã«msbuildãã«ãã·ã¹ãã ãè¿ããã端æ«ã«ææ°ã®
aspnetãžã§ãã¬ãŒã¿ãŒãã€ã³ã¹ããŒã«ããŸãã
sudo npm install -g yo bower generator-aspnet
Project Generatorã®èµ·å
Yeomanãžã§ãã¬ãŒã¿ãŒã¯ããããžã§ã¯ãã®åæåãèšè¿°ããYoã®æ瀺ãšãã³ãã¬ãŒããå«ãnpmããã±ãŒãžã§ããäœæãããã£ã¬ã¯ããªããã¡ã€ã«ãšã³ããŒããå Žæããã³ãã¬ãŒããåŠçããæ¹æ³ãåŠçåŸã«é
眮ããå Žæã ãããžã§ã¯ããé
眮ãããã©ã«ããŒã«ç§»åããASP.NET Coreãããžã§ã¯ããžã§ãã¬ãŒã¿ãŒãå®è¡ããŸãã
yo aspnet
- ã¢ã€ãã Web Application Basic [Membership and Authorizationãªã]ãéžæããEnterãæŒããŸã
- UIãã¬ãŒã ã¯ãŒã¯ãšããŠBootstrapïŒ3.3.6ïŒãéžæããEnterãæŒããŸã
- ãWebApplicationBasicããšããååãã¢ããªã±ãŒã·ã§ã³ã®ååãšããŠæ®ããEnterããŒãæŒããŸã
æ³šïŒ WebApplicationãéžæãããšãã¯ã©ã€ã¢ã³ãèªèšŒã§ã¢ããªã±ãŒã·ã§ã³ãã³ãã¬ãŒããäœæãããSQLiteãããŒã¿ããŒã¹ãšããŠäœ¿çšã§ããŸãïŒãžã§ãã¬ãŒã¿ãŒããããè¡ãæ¹æ³ã«ã€ããŠé©åãªæ瀺ãåºããŸãïŒã äœããããŒã¹ãšããŠçªç¶äœ¿çšãããå Žåã¯ãPostgreSQLãµããŒããè¿œå ã§ããŸãã- ã€ã³ã¹ããŒã«ïŒ
npm install -g generator-aspnetpostgresql
- ãã³ãã¬ãŒãã®çæïŒ
yo aspnetpostgresql
ãã®ãžã§ãã¬ãŒã¿ãŒã¯ãåãOmniSharp / generator-aspnetã«åºã¥ããŠããŸãã ããŒãžã§ã³ã¯ããå€ããªã£ãŠãããããéå§ããã«ã¯ããŸãdotnet migrate
ãšdotnet restore
ããã®é åºã§å®è¡ããå¿
èŠããããŸãã
ãžã§ãã¬ãŒã¿ãŒããã¡ã€ã«ã®äœæãå®äºãããšãã¢ããªã±ãŒã·ã§ã³ã埩å
ããã«ããããã³å®è¡ããæ¹æ³ãæ瀺ãããŸãã
ããã§ãããžã§ã¯ããäœæãããŸããã次ã®ã³ãã³ãã䜿çšããŠäœæ¥ãéå§ã§ããŸã
cd "WebApplicationBasic"
ãããããã埩å
dotnet buildïŒãªãã·ã§ã³ãå®è¡ãããšãã«ããè¡ãããŸãïŒ
ããããããã©ã³
埩å
ããŠçµã¿ç«ãŠãããšã¯ã§ããŸãããéå§ããã«ã¯ææå°æ©ã§ããä»ã®äœããããå¿
èŠããããŸãã
Visual Studio Codeã䜿çšããLinuxã§ã®ASP.NET Core MVCã¢ããªã±ãŒã·ã§ã³ã®éçº
Visual Studio Codeãå®è¡ããŸãã
â
ã
â
ãéžæããyoã䜿çšããŠASP.NET Core MVCã¢ããªã±ãŒã·ã§ã³ãã³ãã¬ãŒããäœæãã
â
ãéžæããŸãã
Visual Studio CodeãåããŠèµ·åãããšããã«ããšãããã°ã«å¿
èŠãªããŒã«ããªãããšãèŠåããŸãã [
Yes
ãã¯ãªãã¯ããŠè¿œå ããŸãã ããããªããšãVisual Studio CodeããŒã«ã䜿çšããèªåãããã°ãšãã«ãã¯äœ¿çšã§ããŸãããã
dotnet build
ããã³
dotnet run
䜿çšããŠã¿ãŒããã«ãä»ããŠã®ã¿äœ¿çšã§ã
dotnet run
ã
Visual Studioã³ãŒãã¿ãŒããã«ïŒCtrl-`ïŒã§ã
dotnet restore
ã³ãã³ããå®è¡ããŠãããžã§ã¯ãã®äŸåé¢ä¿ã埩å
ããŸãïŒããããŸã è¡ã£ãŠããªãå ŽåïŒã å¥ã®æ¹æ³ã¯ãVisual Studio Codeã§Ctrl-Shift-Pã³ãã³ããå®è¡ãã次ã«ç€ºãããã«ããããå
¥åããããšã§ãïŒäœããã®çç±ã§æ©èœããŸããã§ããïŒã
Visual Studio CodeïŒãŸãã¯ç°¡æœã«ããããã«CodeïŒã䜿çšãå§ããã°ããã®å Žåããã®è£œåã«ã¯ãã¡ã€ã«ããã°ããåŠçãã䟿å©ã§ã·ã³ãã«ã§å¿çæ§ã®é«ãã€ã³ã¿ãŒãã§ã€ã¹ãããã ãã§ãªããæãå¹ççãªæžã蟌ã¿ã®ããã®ããŒã«ããããŸãã³ãŒãã
å·ŠåŽã®ããã²ãŒã·ã§ã³ããŒã«ã¯ã4ã€ã®ãã¥ãŒã¬ãããè¡šã5ã€ã®ã¢ã€ã³ã³ããããŸãã
- æ¢æ€ãã
- æ€çŽ¢ãã
- Git
- ãããã°ãã
- æ¡åŒµæ©èœ
Exploreãã¥ãŒã¬ããã䜿çšãããšããã£ã¬ã¯ããªã·ã¹ãã å
ããã°ãã移åã§ããäœæ¥äžã®ãã¡ã€ã«ãç°¡åã«åç
§ã§ããŸãã ãã¡ã€ã«ã«ä¿åãããŠããªãå€æŽãããå Žåãç»é¢äžã®ç¹å¥ãªã¢ã€ã³ã³ããããéç¥ããŸãã æ°ãããã¡ã€ã«ãšãã©ã«ããŒãäœæããããã»ã¹ãç°¡çŽ åãããŸãïŒãã®ããã«æ°ãããŠã£ã³ããŠãéãå¿
èŠã¯ãããŸããïŒã ããŠã¹ã«ã«ãŒãœã«ãåããããšè¡šç€ºãããã¡ãã¥ãŒã«ãã[ãã¹ãŠä¿å]ã³ãã³ãã䜿çšãããšäŸ¿å©ã§ãã
ã³ã³ãã¥ãŒã¿ãŒã«ã€ã³ã¹ããŒã«ãããŠããå Žåãã³ãŒãã¯Gitãšçµ±åãããŸãã Gitãã¥ãŒã¬ããã䜿çšããŠãæ°ãããªããžããªãäœæããã³ãŒãã®å€æŽã確èªããå€æŽãéä¿¡ã§ããŸãã
ãããã°ãã¥ãŒã¬ããã¯ãã¢ããªã±ãŒã·ã§ã³ã®å¯Ÿè©±åãããã°ããµããŒãããŸãã
ããã«ãã³ãŒããšãã£ã¿ãŒã«ã¯å€ãã®åªããæ©èœããããŸãã æªäœ¿çšã®usingã¹ããŒãã¡ã³ãã«ã¯äžç·ãåŒããã
trl-.
èªåçã«åé€ã§ããããšãããã
trl-.
é»çã¢ã€ã³ã³ãç»é¢ã«è¡šç€ºãããŠããå Žåã ãŸãããããžã§ã¯ãå
ã®ã¯ã©ã¹ãšã¡ãœãããžã®åç
§ã®æ°ã確èªããããšãã§ããŸãã Visual Studioããåãæ¿ããå Žåãã³ãŒãã®ãããã¯ãã³ã¡ã³ãã¢ãŠããã
trl-K+C
ãã³ã¡ã³ãã解é€ãã
Ctrl-KU
ãªã©ã䜿ãæ
£ããå€ãã®ããŒããŒãã·ã§ãŒãã«ããã䜿çšã§ããŸãã
Kestrelã䜿çšããã¢ããªã±ãŒã·ã§ã³ã®èµ·å
Kestrelã¯ãéåæI / Oã©ã€ãã©ãªã§ããlibuvã«åºã¥ããã¯ãã¹ãã©ãããã©ãŒã HTTPãµãŒããŒã§ãã ãããã€ã³ã¹ããŒã«ããã«ã¯ãé©åãªNuGetããã±ãŒãž
Microsoft.AspNetCore.Server.Kestrelãã€ã³ã¹ããŒã«ããå¿
èŠããã
ãŸã ã ãã
ãè¡ãã«ã¯
2ã€ã®æ¹æ³ããããŸãã
- ãã¥ãŒã¬ããæ¡åŒµæ©èœã䜿çšããŠ.Net Core Project ManagerïŒNugetïŒãã€ã³ã¹ããŒã«ããåŸïŒ
Ctrl-Shift-P
ã Nuget
ãâµã Kestrel
ããŠMicrosoft.AspNetCore.Server.Kestrel
éžæãMicrosoft.AspNetCore.Server.Kestrel
- ãšãã£ã¿ãŒã¿ãŒããã«ãšã³ãŒããšãã£ã¿ãŒã®ã³ãã³ãã©ã€ã³çµç±ïŒ
dotnet add package Microsoft.AspNetCore.Server.Kestrel
ããã§ãå®è¡ã§ããããã«ãªããŸãã
dotnet run
ããŒãæŒããã
dotnet run
ã¿ãŒããã«ã§ãã©ãŠã¶ãèµ·åãããšããã©ãŠã¶ã
localhost:5000
ã¢ããªã±ãŒã·ã§ã³ã§èªåçã«èµ·åããŸãã WebãµãŒããŒãåæ¢ããã«ã¯ãCtrl + CãæŒããŸãã 以äžã§ãæåã®ASP.Net Coreã¢ããªã±ãŒã·ã§ã³ãã楜ãã¿ããã ããŸãã
å®æããã¢ããªã±ãŒã·ã§ã³ãããã«ã€ã³ã¹ããŒã«ããããã®æçšãªæ
å ±æº
ãããLinuxå®çšŒåç°å¢ãžã®å
¬é -ãLinuxã§åäœããå Žåã®ASP.Net MVCã¢ããªã±ãŒã·ã§ã³ã®å±éããšããèšäºã«èšåã§ããŸãã
ASP.Net Core MVCãåŠç¿ããããã®åªãããœãŒã¹ãæšå¥šããããšãã§ããŸãã
ãã®ãããã¯ãå§ããããã«å
±æãããããšã¯ãå®éã«ã¯ããã ãã§ãã ããªããäœããèŠéããå Žå-ç§ã«èšã£ãŠããããä¿®æ£ããŠãã ããã