PageSourceSearch

https://iliabedian.com/_next/static/chunks/770.af720e98524c60d8.js

js iliabedian.com collected 2026-09-30 17:42:31 UTC 9,589 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[770],{26133:function(e,n,o){o.d(n,{a:function(){return r}});function r(e){return e}},10007:function(e,n,o){o.d(n,{j:function(){return t}});var r=o(5862);function t(e){let{children:n,type:o="info"}=e;return(0,r.jsx)("div",{className:"my-8 flex items-center justify-start gap-2 rounded-md border-l-8 p-4 ".concat("info"===o?"border-l-blue-300":"warning"===o?"border-l-yellow-300":"border-l-red-300"," ").concat("info"===o?"bg-blue-100":"warning"===o?"bg-yellow-50":"bg-red-100"),children:(0,r.jsx)("div",{className:"w-full break-words text-gray-800",children:n})})}o(67058)},55770:function(e,n,o){o.r(n),o.d(n,{default:function(){return a}});var r=o(5862),t=o(26133),i=o(10007);function l(e){let n=Object.assign({p:"p",a:"a",h2:"h2",ul:"ul",li:"li",pre:"pre",code:"code",ol:"ol"},(0,t.a)(),e.components);return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(n.p,{children:["In this tutorial, we will be deploying a .NET 7 app on ",(0,r.jsx)(n.a,{href:"https://railway.app/",children:"Railway"})," using the Railway CLI and a Dockerfile. We will be using\nthe .NET 7 SDK to build a minimal API app and then deploy it on Railway."]}),"\n",(0,r.jsx)(n.h2,{children:"Before starting, make sure you have:"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:["Installed ",(0,r.jsx)(n.a,{href:"https://dotnet.microsoft.com/en-us/download/dotnet/7.0",children:".NET 7 SDK"}),"."]}),"\n",(0,r.jsxs)(n.li,{children:["Installed Docker and ran its service. I recommend using ",(0,r.jsx)(n.a,{href:"https://www.docker.com/products/docker-desktop",children:"Docker Desktop"})," to get started with Docker quickly."]}),"\n",(0,r.jsxs)(n.li,{children:["Installed ",(0,r.jsx)(n.a,{href:"https://docs.railway.app/develop/cli",children:"Railway CLI"})]}),"\n",(0,r.jsxs)(n.li,{children:["(Optional but recommended) Installing and using ",(0,r.jsx)(n.a,{href:"https://www.jetbrains.com/rider/",children:"Rider"})," (a Fast & powerful cross-platform .NET IDE by JetBrains) to\nuse in this tutorial."]}),"\n"]}),"\n",(0,r.jsx)(n.p,{children:"Imagining this is our app's source code:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"/MySolution\n--/MyAppProject\n----/[*Your MyAppProject project source code*]\n--/MySolution.sln\n"})}),"\n",(0,r.jsx)(n.p,{children:"Here's our Dockerfile:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-dockerfile",children:'FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base\nWORKDIR /app\nEXPOSE 80\nEXPOSE 443\n\nFROM mcr.microsoft.com/dotnet/sdk:7.0 AS build\nWORKDIR /src\nCOPY ["MyAppProject/MyAppProject.csproj", "MyAppProject/"]\nRUN dotnet restore "MyAppProject/MyAppProject.csproj"\nCOPY . .\nWORKDIR "/src/MyAppProject"\nRUN dotnet build "MyAppProject.csproj" -c Release -o /app/build\n\nFROM build AS publish\nRUN dotnet publish "MyAppProject.csproj" -c Release -o /app/publish\n\nFROM base AS final\nWORKDIR /app\nCOPY --from=publish /app/publish .\nENTRYPOINT ["dotnet", "MyAppProject.dll"]\n'})}),"\n",(0,r.jsx)(i.j,{type:"warning",children:(0,r.jsx)(n.p,{children:"If you are having your solution and project in the same folder, here's how your Dockerfile should almost look like \uD83D\uDC47:"})}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-dockerfile",children:'FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base\nWORKDIR /app\nEXPOSE 80\nEXPOSE 443\n\nFROM mcr.microsoft.com/dotnet/sdk:7.0 AS build\nWORKDIR /src\nCOPY ["BallApp.csproj", "./"]\nRUN dotnet restore "BallApp.csproj"\nCOPY . .\nWORKDIR "/src/"\nRUN dotnet build "BallApp.csproj" -c Release -o /app/build\n\nFROM build AS publish\nRUN dotnet publish "BallApp.csproj" -c Release -o /app/publish\n\nFROM base AS final\nWORKDIR /app\nCOPY --from=publish /app/publish .\nENTRYPOINT ["dotnet", "BallApp.dll"]\n'})}),"\n",(0,r.jsxs)(n.p,{children:["Now, in order for Railway CLI to be aware of our dockerfile and the start command, we need to make a ",(0,r.jsx)(n.code,{children:"railway.toml"})," file with this content\nunder our ",(0,r.jsx)(n.code,{children:"/MySolution"})," folder:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-toml",children:'[build]\nbuilder = "dockerfile"\ndockerfilePath = "./MyAppProject/Dockerfile"\n\n[deploy]\nstartCommand = "dotnet MyAppProject.dll"\nrestartPolicyType = "never"\n'})}),"\n",(0,r.jsxs)(n.p,{children:["Go to your ",(0,r.jsx)(n.code,{children:"Program.cs"})," and add these two lines before ",(0,r.jsx)(n.code,{children:"var app = builder.Build();"})," line."]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-csharp",children:'var port = Environment.GetEnvironmentVariable("PORT") ?? "8081";\nbuilder.WebHost.UseUrls($"http://*:{port}");\n'})}),"\n",(0,r.jsxs)(n.p,{children:["This will allow Railway to\ninject the port value from the environment variable ",(0,r.jsx)(n.code,{children:"PORT"})," to your app. (Railway will set the ",(0,r.jsx)(n.code,{children:"PORT"})," environment variable for you.)"]}),"\n",(0,r.jsxs)(n.p,{children:["You can now access your app on ",(0,r.jsx)(n.code,{children:"http://localhost:8081"})," if you haven't set any ",(0,r.jsx)(n.code,{children:"PORT"}
1)," Environment Variable."]}),"\n",(0,r.jsxs)(i.j,{type:"warning",children:[(0,r.jsxs)(n.p,{children:["For development purpose, comment out the line that forces HTTPS redirection in your ",(0,r.jsx)(n.code,{children:"Program.cs"}),"."]}),(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-csharp",children:"// app.UseHttpsRedirection();\n"})})]}),"\n",(0,r.jsx)(n.h2,{children:"Playing with Railway and its CLI"}),"\n",(0,r.jsxs)(n.ol,{start:"0",children:["\n",(0,r.jsxs)(n.li,{children:["Navigate to ",(0,r.jsx)(n.code,{children:"/MySolution"})," folder in your command line shell."]}),"\n",(0,r.jsxs)(n.li,{children:["Run ",(0,r.jsx)(n.code,{children:"railway login"})," and follow the instructions to login on your railway account."]}),"\n",(0,r.jsxs)(n.li,{children:["(optional) run ",(0,r.jsx)(n.code,{children:"railway run dotnet run --project ./MyAppProject"})," and make sure that your app is running (this is on your local machine)"]}),"\n",(0,r.jsx)(n.li,{children:'On your railway, "Start a New Project" and then choose the "Empty project" from the dropdown menu.'}),"\n"]}),"\n",(0,r.jsx)("img",{src:"/_next/static/media/railway-new-project.eb57b545.png",width:400,height:100,alt:"Railway new Project"}),"\n",(0,r.jsxs)(n.ol,{start:"4",children:["\n",(0,r.jsx)(n.li,{children:'Add a Service. and choose "Empty Service".'}),"\n"]}),"\n",(0,r.jsx)("img",{src:"/_next/static/media/railway-add-a-service.76d5ed0b.png",width:400,height:100,alt:"Railway add Service"}),"\n",(0,r.jsxs)(n.ol,{start:"5",children:["\n",(0,r.jsxs)(n.li,{children:["On you terminal, (staying in the ",(0,r.jsx)(n.code,{children:"/MySolution"})," working directory), run ",(0,r.jsx)(n.code,{children:"railway link"})," and then choose your project that you want to link your .NET app to. (There will be a list of your railway projects by their names.)"]}),"\n",(0,r.jsxs)(n.li,{children:["Finally, run ",(0,r.jsx)(n.code,{children:"railway up"})," and wait until your deployment builds, and deploys on railway. You can checkout the deployment starting on your Railway project (service) deployment page."]}),"\n",(0,r.jsx)(n.li,{children:"And maybe generate a new domain so that you can access your app via that domain."}),"\n"]}),"\n",(0,r.jsx)(n.h2,{children:"Conclusion"}),"\n",(0,r.jsx)(n.p,{children:"Although there are many other platform that allow you to deploy a .NET app, Railway is one of the few that simplifies the deployment process\nand makes it easy for a developer to instantly host their app so that they can share it with others and get feedback on it as quick as possible."}),"\n",(0,r.jsx)(n.p,{children:"No more headaches with configuring complex deployment pipelines such as AWS, Azure, GCP, etc. \uD83E\uDD26"}),"\n",(0,r.jsxs)(n.p,{children:["I hope you found this tutorial helpful. If you have any questions, feel free to DM me on ",(0,r.jsx)("a",{target:"_blank",href:"https://twitter.com/iliaaamiri",children:"Twitter"}),".\nI'll be happy to help. Or just come and say hi. \uD83D\uDE0A"]}),"\n",(0,r.jsx)(n.h2,{children:"References"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"https://rendle.dev/posts/deploying-to-railway-with-dotnet/",children:"https://rendle.dev/posts/deploying-to-railway-with-dotnet/"})}),"\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"https://docs.railway.app/develop/cli",children:"https://docs.railway.app/develop/cli"})}),"\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"https://stackoverflow.com/questions/70502758/how-do-i-inject-herokus-port-value-into-a-dotnet-core-6-0-web-api",children:"https://stackoverflow.com/questions/70502758/how-do-i-inject-herokus-port-value-into-a-dotnet-core-6-0-web-api"})}),"\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"https://stackoverflow.com/questions/38755516/how-to-change-the-port-number-for-asp-net-core-app",children:"https://stackoverflow.com/questions/38755516/how-to-change-the-port-number-for-asp-net-core-app"})}),"\n",(0,r.jsx)(n.li,{children:(0,r.jsx)(n.a,{href:"https://docs.railway.app/deploy/config-as-code",children:"https://docs.railway.app/deploy/config-as-code"})}),"\n"]})]})}o(16850);var a=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{wrapper:n}=Object.assign({},(0,t.a)(),e.components);return n?(0,r.jsx)(n,Object.assign({},e,{children:(0,r.jsx)(l,e)})):l(e)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.