Hello All,
In this article we will learn how to deploy the ASP.NET Core web API to local windows folder or IIS.
Below are the things we are going to learn
1. Create the Web API Project
2. Creating the repository in Git and Code check in
3. Setting up the Deployment
Lets Start now....
1.Create the Web API Project
Open visual studio
· Create a new project
Select template ASP.NET Core Web API
· Enter the project name and location click à Next
Select the framework, in my case I will choose .NET 6.0 then click on à Create
Great! We have created the API, it’s time to run and test the API
We use open API, which is available in our application i.e. Swagger
https://localhost:7160/WeatherForecast
[
{
"date": "2022-05-17T15:51:33.8672531+05:30",
"temperatureC": 21,
"temperatureF": 69,
"summary": "Balmy"
},
{
"date": "2022-05-18T15:51:33.8691463+05:30",
"temperatureC": 10,
"temperatureF": 49,
"summary": "Cool"
},
{
"date": "2022-05-19T15:51:33.8691654+05:30",
"temperatureC": -18,
"temperatureF": 0,
"summary": "Sweltering"
},
{
"date": "2022-05-20T15:51:33.8691658+05:30",
"temperatureC": -16,
"temperatureF": 4,
"summary": "Warm"
},
{
"date": "2022-05-21T15:51:33.8691661+05:30",
"temperatureC": 37,
"temperatureF": 98,
"summary": "Bracing"
}
]
Application is running without any issues.
2. Creating the repository in Git and Code check inHere we will learn how to create the repository and check in the application which we have created in step 1
If you do not have github account, please visit github.com and create the account with your google email id, it’s very simple and easy process.
Below are steps to create the repository and code check-in to that
Create Repository, Click + icon and Click à Next Repository
//GITHUB URL String githubUrl = "https://github.com/SourceLastBenchCoder/SampleNetCoreAPIForJenkinsDeployment" //Project Name in GITHUB String projectName = "APIForCICDDeployment" //JENKINS WORKSPACE CODE PUBLISHED PATH String publishedPath = "APIForCICDDeployment\\bin\\Release\\net6.0\\publish" //IIS APPLICATION OR WEBSITE NAME String iisApplicationName = "apiforjenkins" //IIS WEBSITE PATH String iisApplicationPath = "D:\\Deployment\\appforjenkins" node () { stage('Checkout') { checkout([ $class: 'GitSCM', branches: [[name: 'main']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: """ "${githubUrl}" """]]]) } stage('Build') { bat """ cd ${projectName} dotnet build -c Release /p:Version=${BUILD_NUMBER} dotnet publish -c Release --no-build """ } stage('Publish') { bat """ cd ${projectName} dotnet publish -c Release --no-build """ } stage('Deploy-DEV'){ bat """ "C:\\Program Files (x86)\\IIS\\Microsoft Web Deploy V3\\msdeploy.exe" -verb:sync -source:iisApp="${WORKSPACE}\\${publishedPath}" -enableRule:AppOffline -dest:iisApp="${iisApplicationName} """ } }
Created project will be displayed on dashboard