Sunteți pe pagina 1din 20

25/10/2016

DevelopandDeployASP.NET5AppsonLinux|TonySneed'sBlog

TonySneed'sBlog
AglimpseintothelivesofTony&
ZuzanaSneed

DevelopandDeployASP.NET5AppsonLinux
PostedonMay25,2015

NOTE:Thispostispart2ofaseriesondevelopinganddeployingcrossplatformwebappswithASP.NET5:
1.DevelopandDeployASP.NET5AppsonMacOSX
2.DevelopandDeployASP.NET5AppsonLinux(thispost)
3.DeployASP.NET5AppstoDockeronLinux
4.DeployASP.NET5AppstoDockeronAzure
Downloadinstructionsandcodeforthisposthere:https://github.com/tonysneed/VsCodeAspNet5Linux.
ItisnowpossibletodevelopanddeployanASP.NETapplicationonLinux.Incaseyouhaventheard,
MicrosoftsCEO,SatyaNadella,hasproclaimed,MicrosoftlovesLinux.

https://blog.tonysneed.com/2015/05/25/developanddeployaspnet5appsonlinux/

1/20

25/10/2016

DevelopandDeployASP.NET5AppsonLinux|TonySneed'sBlog

Thereasonissimple:LinuxisvitaltoMicrosoftscloudservice,Azure.Butmoreimportant,inembracingcross
platforminitiatives,suchasCoreCLR,thereisanacknowledgementthatwenolongerliveinaworldwithasingle
dominantplatform,andthatdevelopersnotonlyneedtowritecodethatrunsonmultipleplatforms,butthatthey
shouldbecomfortablewritingappswithanIDEthatwillrunonmultipleplatforms.Formostofus,thatIDEwill
beVisualStudioCode.
InthisblogpostIllshowyouhowtosetupaLinuxvirtualmachinetorunVSCode,sothatyoucanbothdevelop
anddeployASP.NET5applications.IfyoureonaMacwithParallels,creatingavirtualmachinerunning
UbuntuLinuxisjustafewclicksaway.

https://blog.tonysneed.com/2015/05/25/developanddeployaspnet5appsonlinux/

2/20

25/10/2016

DevelopandDeployASP.NET5AppsonLinux|TonySneed'sBlog

OnceyouvestoodupyourshinynewLinuxVM,followtheseinstructionstoinstallVSCode.Ifounditconvenient
tocreateaVSCodefolderunderHomeandextractthecontentsofVSCodelinuxx64.zipthere.Thenyou
cancreatealinkthatwilllaunchVSCodefromtheTerminal,sothatyoucantypecode .tostarteditingfilesin
VSCodeatthatlocation.
sudolns/home/parallels/VSCode/Code/usr/local/bin/code

NextyoullneedtofollowtheseinstructionstoinstallASP.NET5onLinux.ThefirststepistoinstallMono.
sudoaptkeyadvkeyserverkeyserver.ubuntu.comrecvkeys3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "debhttp://download.monoproject.com/repo/debianwheezymain"

|sudotee/etc/apt/sources.list.d/monoxamarin.list

sudoaptgetupdate
sudoaptgetinstallMonoComplete

https://blog.tonysneed.com/2015/05/25/developanddeployaspnet5appsonlinux/

3/20

25/10/2016

DevelopandDeployASP.NET5AppsonLinux|TonySneed'sBlog

Second,youllneedtoinstalllibuv,whichisusedbyKestrelforhostingASP.NET5appsonLinux.
sudoaptgetinstallautomakelibtoolcurl
curlsSLhttps: //github.com/libuv/libuv/archive/v1.4.2.tar.gz|sudotarzxfvC/usr/local/src
cd/usr/local/src/libuv1.4.2
sudoshautogen.sh
sudo./configure
sudomake
sudomakeinstall
sudormrf/usr/local/src/libuv1.4.2&&cd~/
sudoldconfig

Lastly,youllneedtoinstalltheDotNetVersionManager,whichisusedtoselectandconfigureversionsofthe
.NETruntimeforhostingASP.NET5apps.
curlsSLhttps: //raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh|DNX_BRANCH=devsh&&source~/.dnx/dnvm/dnvm.s
source/home/parallels/.dnx/dnvm/dnvm.sh
dnvm
dnvmupgrade

Enteringdnvmwillthenbringuptheversionmanager,whichallowsyoutoselectandconfiguredifferentversions
oftheASP.NET5runtime.

https://blog.tonysneed.com/2015/05/25/developanddeployaspnet5appsonlinux/

4/20

25/10/2016

DevelopandDeployASP.NET5AppsonLinux|TonySneed'sBlog

Toseewhichversionsareinstalled,enter:dnvm list .

Next,youllcreateadirectoryandfireupVSCodetocreateyourfirstASP.NET5app.WellstartwithaHello
Worldconsoleapp!ThequickestapproachistograbtwofilesfromtheConsoleAppfolderfortheAspNetSamples
Repo:project.jsonandprogram.cs.
https://blog.tonysneed.com/2015/05/25/developanddeployaspnet5appsonlinux/

5/20

25/10/2016

DevelopandDeployASP.NET5AppsonLinux|TonySneed'sBlog

Hereisproject.jsonfortheconsoleapp,whichliststhedependenciesyoullbringin.
{
"dependencies" :{
},
"commands" :{
"ConsoleApp" : "ConsoleApp"
},
"frameworks" :{
"dnx451" :{},
"dnxcore50" :{
"dependencies" :{
"System.Console" : "4.0.0beta*"
}

Andhereisprogram.cs,whichsimplyprintsHelloWorldtotheconsole.
using System
public class Program
{
public static void Main()
{
Console.WriteLine(

"HelloWorld" )

}
}

Editingprogram.csinVisualStudioCodelookslikethis:

https://blog.tonysneed.com/2015/05/25/developanddeployaspnet5appsonlinux/

6/20

25/10/2016

DevelopandDeployASP.NET5AppsonLinux|TonySneed'sBlog

Tolaunchtheapp,openaTerminalattheConsoleAppdirectory,thenrestorethedependenciesandexecutethe
program.
dnurestore
dnx.run

YoushouldseeHelloWorldprintedtotheTerminalwindow.

https://blog.tonysneed.com/2015/05/25/developanddeployaspnet5appsonlinux/

7/20

25/10/2016

DevelopandDeployASP.NET5AppsonLinux|TonySneed'sBlog

Consoleappsarewellsuitedforrunningtasksonaserver,butmoreoftenyoulluseASP.NET5torunwebapps.
TheAspNetrepoonGitHubhasaHelloWebsample,whereyoucangrabtwofiles:project.jsonandstartup.cs.
Hereistheproject.jsonfileforthewebapp.NoticethekestrelcommandforstartinganHTTPlisteneron
MacOSXandLinux.
{
"version" : "1.0.0*" ,
"dependencies" :{
"Kestrel" : "1.0.0*" ,
"Microsoft.AspNet.Diagnostics"

: "1.0.0*" ,

},
"commands" :{
"kestrel" : "Microsoft.AspNet.HostingserverKestrelserver.urlshttp://localhost:5004"
},
"frameworks" :{
"dnx451" :{},
"dnxcore50" :{}
}

Hereisthestartup.csfile,whichconfiguresthepipelinewithanendpointfordisplayingawelcomepage.
using Microsoft.AspNet.Builder
namespace HelloWeb
{
public class Startup
{
public void Configure(IApplicationBuilderapp)
{
app.UseWelcomePage()
}
}
}

Tostartthewebserver,restoredependenciesandthenenterthekestrelcommand.VSCodealsoallowsyouto
executecommandsfromthecommandpalette,butthisdoesntyetworkonLinux.
https://blog.tonysneed.com/2015/05/25/developanddeployaspnet5appsonlinux/

8/20

25/10/2016

DevelopandDeployASP.NET5AppsonLinux|TonySneed'sBlog

dnurestore
dnx.kestrel

Thenopenabrowserandentertheaddress:http://localhost:5004.YoullseeamessageintheTerminal
statingthewebserverhasstarted.Toendit,pressEnter.

AsidefromrunningtheconsoleandwebHelloWorldsamples,youregoingtowanttodevelopyourown
applicationsbasedontemplatesyoudfindinVisualStudioonWindows.Togetasimilarexperience,youcan
installYeoman,whichscaffoldsvariouskindsofASP.NET5apps,suchasMVC6orWebAPI(whichis
technicallynowpartofMVC6).ToinstallYeomanyoullneedtheNodePackageManager,whichyoucan
downloadandinstallusingtheaptgetcommand.
sudoaptgetinstallnodejslegacynpm

OnceyouhaveNodeinstalled,youcanuseittoinstallYeoman,theasp.netgenerator,gruntandbowerallin
onefellswoop.
sudonpminstallgyogruntcligeneratoraspnetbower

https://blog.tonysneed.com/2015/05/25/developanddeployaspnet5appsonlinux/

9/20

25/10/2016

DevelopandDeployASP.NET5AppsonLinux|TonySneed'sBlog

HavinginstalledYeoman,youcanthennavigatetoadirectoryinTerminalwhereyoudliketocreateyournew
app.Thenexecute:
yoaspnet

Thisbringsupanumberofchoices.Forexample,youcanselectWebAPIApplication,whichthenscaffolds
thestandardWebAPIappwithaValuesController.Ifyourundnu restore anddnx . kestrel ,asyoudid
withthesamplewebapp,youcanbrowsetothefollowingURLtogetbackJSONvalues:
http://localhost:5001/api/values .
AndthatishowyoucanbothdevelopanddeployASP.NET5appsonLinux.Forthenextpartofthisseries,Ill
showyouhowtodeployanASP.NET5apptoaDockercontaineronLinux.

Sharethis:

Print

Email

Facebook 12

Twitter

Like
Bethefirsttolikethis.

Related

DeployASP.NET5AppstoDockeronAzure
In"Technical"

DeployASP.NET5AppstoDockeronLinux
In"Technical"

https://blog.tonysneed.com/2015/05/25/developanddeployaspnet5appsonlinux/

DevelopandDeployASP.NET5AppsonMac
OSX
In"Technical"

10/20

25/10/2016

DevelopandDeployASP.NET5AppsonLinux|TonySneed'sBlog

AboutTonySneed
Marriedwiththreechildren.
ViewallpostsbyTonySneed

ThisentrywaspostedinTechnicalandtaggedASP.NETMVC,Linux,VisualStudio,WebAPI.Bookmarkthepermalink.

31ResponsestoDevelopandDeployASP.NET5AppsonLinux
Chrissays:
June5,2015at2:14pm

sudoshautogen.shashouldbesudoshautogen.sh
Reply

TonySneedsays:
June23,2015at5:01am

Fixedit,thanks!
Reply

AlainSergeiKhumalovsays:
June23,2015at2:34am

Haveyoutesttodeployitononlineserver?Thisisgoodnewsifasp.netcanruninLinux.Itwillbecheapertohostasp.net.At
thistime,Imstillusingwindowshostingathostforlife.eu.But,ifitisrunningperfectlyonLinuxserver,Iwilltestittoo.
Reply
https://blog.tonysneed.com/2015/05/25/developanddeployaspnet5appsonlinux/

11/20

25/10/2016

DevelopandDeployASP.NET5AppsonLinux|TonySneed'sBlog

TonySneedsays:
June23,2015at2:36am

Yes!ASP.NET5runsperfectlyfineonLinuxandinDockercontainersintheCloud.IhaveithostedinaLinuxVM
onAzure.
Reply

AlainSergeiKhumalovsays:
June23,2015at11:05pm

Wow.Greatnews..So,howaboutinLinuxsharedhosting?Haveyoutestit?OritonlyworksonVPSor
cloud?
Thankyou

TonySneedsays:
June24,2015at5:34am

ItworksonLinuxUbuntu14.04.IveruntheappbothonLinuxinalocalVMaswellasanAzureVM,both
inaDockercontainer.Sotheresnoreasonitwouldnotworkwithsharedhosting,VPSorcloud.

Dalesays:
June28,2015at10:33am

Second,youllneedtoinstalllibuv,whichisusedbyKestrelforhostingASP.NET5appsonLinux.

https://blog.tonysneed.com/2015/05/25/developanddeployaspnet5appsonlinux/

12/20

25/10/2016

DevelopandDeployASP.NET5AppsonLinux|TonySneed'sBlog

SowhatsKestrel?Ifyouretalkingabouthttp://twitter.github.io/kestrel/,thathasntbeenactivesince2012.Iveseen
referencestoKestrelonafewDockerpagesbutnoneIreadhaveanydescriptionofwhatitisorwhatitsfor.
Reply

TonySneedsays:
June28,2015at11:47am

KestreliscurrentlyadevwebserverfromMicrosoftusedforhostingASP.NET5appsonbothOSXandLinux:
https://github.com/aspnet/KestrelHttpServer.LikeNode,itsbuiltontopoflibuv.ThereareplansforMSto
makeitproductionready,andyoullwanttouseitwithsomethinglikenginxforSSL,virtualhost,etc.
Reply

srikanthsays:
July15,2015at8:33pm

YouarerunningthiswithMono.Canthisdonewithcoreclrx64build?
Reply

TonySneedsays:
July16,2015at2:10am

ThecurrentASPNET5bitsdependonMonoforcrossplat,butCoreCLRwillreplacethatrequirementprobably
beforewegettoRC.Sostaytuned.CurrentlyyoucanincludeadependencyonCoreCLRinyourproject.jsonfile,
sotherewontbeaneedtochangeyourcode.
Reply

https://blog.tonysneed.com/2015/05/25/developanddeployaspnet5appsonlinux/

13/20

25/10/2016

DevelopandDeployASP.NET5AppsonLinux|TonySneed'sBlog

Ravisays:
July16,2015at1:57am

Hi,
Thisarticlewashelpfultomeinsettingupmyfirst.NetappsinUbuntu.Thanks!
Now,itwouldbegreattoknowofthelimitationsofwhatwecan/cantdowith.Netappsintermsofcrossplatform.Isthere
anylimitationsonthetypeoftheapplicationsthatwecandeployinLinux?Imean,wouldwebeabletodeployaWeb
Service[SOAP/REST]orWindowsServerApporatraditionalAsp.NetApp?
Regards,
Ravi
Reply

TonySneedsays:
July16,2015at2:16am

SoonLinuxyourepresentlylimitedtousingtheKestrelwebserver.However,thiswillbeproductionreadybythe
timewegettoRC.IISandWindowsServicesarespecifictoWindows,andthereisnotyetsupportforApachefor
hostingASPNET5apps.
YoucandeployRESTwebserviceswithASPNET5.SOAPisimplementedbyWCF,whichisnotsupportedby
ASPNET5.SoyoudneedtouseMonoforthat,butIwouldrecommendagainstSOAP/WCFgoingforward,asitis
nowconsidereddeprecated.LikewisetraditionalASP.NETapps,forexampleMVC5orWebForms,isonly
supportedonWindowswiththefull.NET4.xframework.
Reply

Pingback:MakingthejumptoLinux|CyteDesign

Sushy(@SushyTM)says:
https://blog.tonysneed.com/2015/05/25/developanddeployaspnet5appsonlinux/

14/20

25/10/2016

DevelopandDeployASP.NET5AppsonLinux|TonySneed'sBlog

December8,2015at5:14pm

ThislookslikeexactlywhatIneeded.However,Ihaveonequestion:Isthereawaytodevelopasp.netwebappsfrom
windows,andpublishthemfromwindowsintothelinuxhost?WillthisbejustliketypingtheIP/Hostnameanduser
credentials?Thanks!
Reply

TonySneedsays:
December9,2015at5:54am

ThereareafewwaystopublishanASPNET5apptoaLinuxVM,anditdoesntmatterwhereyoudeveloptheapp.
YoucanauthoritonWindowsusingeitherVisualStudioCodeorfullVisualStudio2015.Onewayistocopythe
sourcecodefilestotheLinuxmachine,whereyouhaveinstalledDNX,asshowninthisblogpost.Anotherwayis
touseDocker,whichcanbedoneeitheronalocalLinuxVMoronacloudservicesuchasAzure.Thismyother
blogpostforinstructionsondeployingtoDockeronaLinuxVM.
Reply

Aaronsays:
January15,2016at5:15am

HiTony,greatguidehoweverImhavinganissue.Imanagedtogetthebasicpagetodisplayetc,sucessfullyinstalledasp5
etcalthoughwhenitcomestoactuallyloadingupafullprojectcreatedfromYoitjustseemstohangonloadingthepage,no
errorswhenrestoringorrunning
Wouldyouhaveanyadvice?
Reply

TonySneedsays:
https://blog.tonysneed.com/2015/05/25/developanddeployaspnet5appsonlinux/

15/20

25/10/2016

DevelopandDeployASP.NET5AppsonLinux|TonySneed'sBlog

January15,2016at6:25am

InsteadofusingYo,Iwouldinsteadrecommendstartingfromasamplefromtheaspnethomerepoongithub.
ASPNET5hasbeenevolvingalotandtheYogeneratormaybeoutdated.
Reply

Aaronsays:
January15,2016at7:00am

Iwasalreadyusingthosewhichseemedtoworkfine.ThatswhenIwantedtogetaprojectsetupwithMVChoweverasstated
IseemtoberunningintoissueswhereeverythingseemstorestoreandrunfinebutIjustcannotactuallyloadthepage.
Also,bearinmindthisisallrunninglocallysothereshouldnotbeanyportissues.Anyhelpisgreatlyappreciated!
Cheers
Reply

TonySneedsays:
January15,2016at8:04am

Justaguess,butchecktheorderofyourstatementsinStartup.Configure.Theverylaststatementneedstobethe
onewhichusesMVC.Alsomakesureyourroutesaresetupproperly.Forfurthersupportonthis,Isuggest
postingaquestiontoStackOverflow,whereyoucanpasteincodeandgetresponsesfromothersaswell.
Reply

VireshNY(@veerasamrat)says:
February6,2016at4:00am
https://blog.tonysneed.com/2015/05/25/developanddeployaspnet5appsonlinux/

16/20

25/10/2016

DevelopandDeployASP.NET5AppsonLinux|TonySneed'sBlog

Firstly,thankyouforthistutorial..!!!!
Canwehostouraspnet5webapponubuntu,SothatwecanaccessfromoutsidelikehostinginIIS.?
Ifyes,canyoupleaseexplainmeiambeginnerforbothaspnet5andvisualcodeinubuntu.
Reply

TonySneedsays:
February6,2016at7:23am

Hiandthanks!OnUbuntuyouwouldruninKestrelonWindows,eitherKestrelorIIS.Formoreinfocheckthis
out:https://github.com/aspnet/home
Reply

Ignassays:
February12,2016at8:37am

Nowitsnotworking.Monolatestversionisntcompatiblewiththisexample.
Reply

TonySneedsays:
February12,2016at9:22am

Theexamplesfromthispostareindeedoutdated.InsteadofMono,youshouldbeusing.NETCore.Youcanfind
currentexamplesontheASPNETGitHubrepo,atthehomerepositoryinthesamplesfolder.Justdownloador
clonethehomerepotogetthelatestsamples,whichincludecorrectDockerfiles.Ihopethishelps.
Reply

https://blog.tonysneed.com/2015/05/25/developanddeployaspnet5appsonlinux/

17/20

25/10/2016

DevelopandDeployASP.NET5AppsonLinux|TonySneed'sBlog

bluEEilsays:
March6,2016at5:18am

Thanksalotforthispost!
IampuzzledthoughabouthowatthepresentIcandevelopandwebapiapponwindowsandthendeployitonanoffline
linuxpc(ThislinuxpccanbeconnectedtowwwandIcanonlyputfilesonitusinganusbflashdrive)
AnyideasonhowIcanachievethat?
Reply

TonySneedsays:
March6,2016at8:13am

@bluEEil:HaveyouthoughtaboutusingDocker(whichIdiscussinthispost)?YoucanthensavetheDocker
imageasatarfileandcopyitmanuallytoanofflineLinuxPC,asthisSOanswerdescribes.
Reply

Ramasays:
May16,2016at5:06am

Canwedevelopasp.netapplicationusingVS2015onWindowsenvironment,buildapackageforLinuxanddeployiton
linux.?
Reply

TonySneedsays:
May16,2016at5:14am

IthinkyouwillbeabletodothiswiththepublishcommandfordotnetcliwhenRC2isreleasedthisweek.
https://blog.tonysneed.com/2015/05/25/developanddeployaspnet5appsonlinux/

18/20

25/10/2016

DevelopandDeployASP.NET5AppsonLinux|TonySneed'sBlog

Reply

Monicasays:
August2,2016at12:04am

HiTony
Thanksforthepost.Ihavefewqueries.Monoisnotsupportingallfeaturesof.netlikeWPF,WWF,async.AlsoWCFisnot
fullysupported.ForSilverLight,moonlightwasintroducedwhichisnotsupportedanymoreasihaveheard(pleasecorrectif
iamwronganywheresofar).
Soifitalkfromgeneralprospective,canwerelyonASP.NetcoretoprovidefullcompatibilityinLinux.Forprojectswithnew
versionandforexistingprojectforoldversions?RC2isalreadyoutanditssupportingASP.Net.Iamnotfamiliarwithallthe
detailsofRC2butmyworryiscanirunallmyexisting.netprojectsonlinuxusingcore(providingnecessarilychanges,asit
requiresproject.jsonfileforcompilation).
Reply

TonySneedsays:
August2,2016at12:20am

.NETCoreisasubsetofthefull.NETFramework,andASP.NETCoreisanentirelynewwebplatform.Soreally
yourexistingprojectswontrunon.NETCorewithoutbeingrewritten.Thatsonereasonitisav1.0project(it
wasreleasedattheendofJune).Soitshouldbeconsideredmorefornewdevelopmentratherthanportinglegacy
apps,whichrequiresagreatdealmoreeffort.
Reply

Monicasays:
August3,2016at2:50am

https://blog.tonysneed.com/2015/05/25/developanddeployaspnet5appsonlinux/

19/20

25/10/2016

DevelopandDeployASP.NET5AppsonLinux|TonySneed'sBlog

Thanksforinput.ItclearedthecloudbutIlandedmyselfinanotherquestion.Iamsureyoumustbeaware
aboutNuGetpackageforMSBuildwhichcarriesdifferentversionsforwindowsandUnix.CanIuseUnixs
MSBuildforprojectcompilationafterdeployingprojectwithNuGetPackagesinunixenabledenvironment?
Isthatfullycompatible(UnixsMSBuildinNugetpackagetocompile.netprojects)?
Pleasesuggest

TonySneedsays:
August8,2016at9:14am

Imnotabletoaddressthisquestionpresently.ButIsuggestyoupostittoStackOverflow,whereyoull
likelyreceiveananswer.

TonySneed'sBlog
BlogatWordPress.com.

https://blog.tonysneed.com/2015/05/25/developanddeployaspnet5appsonlinux/

20/20

S-ar putea să vă placă și