gitHub action workflow to deploy .net application

0

Here is the CICD pipeline and the IIS server is not getting start and stop. Can someone help me with this ?

name: Publish and Deploy to IIS

on: push: branches: - master

jobs: deploy: runs-on: self-hosted

steps:

- name: Checkout Repository
  uses: actions/checkout@v2
  
- name: Setup .NET
  uses: actions/setup-dotnet@v1
  with:
    dotnet-version: '7.0.*'
  
- name: Setup Node.js environment
  uses: actions/setup-node@v4.0.2
  with:
    node-version: '20.0.*'

- name: Setup NuGet
  uses: NuGet/setup-nuget@v1.0.5

- name: Set up dependency caching for faster builds
  uses: actions/cache@v3
  with:
    path: ~/.nuget/packages
    key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
    restore-keys: |
        ${{ runner.os }}-nuget.

- name: Restore NuGet packages
  run: 
    |
      dotnet nuget locals all --clear
      nuget restore 

- name: Build with dotnet
  run: dotnet build --configuration Release

- name: Stop IIS
  run: |
    Start-Process -FilePath "iisreset" -ArgumentList "/stop" -Verb RunAs
  shell: powershell
  

- name: dotnet publish
  run: dotnet publish -c Release -o C:\inetpub\atarifujiq\publish

- name: Start IIS
  run: |
    Start-Process -FilePath "iisreset" -ArgumentList "/start" -Verb RunAs
  shell: powershell
2 Answers
1

Hello Viikas,

In the PowerShell script sections, such as starting and stopping IIS, it's good to check and set the execution policy if needed

- name: Stop IIS
  run: |
    Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
    Start-Process -FilePath "iisreset" -ArgumentList "/stop" -Verb RunAs

Let me know if this solves your issue.

Thanks

answered a month ago
  • Hello Abhinav,

    Thanks for the response. but still I'm facing the issue pwsh command is getting executed but IIS server is not getting stop/start.

    gitHub Action response : Run Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass Start-Process -FilePath "iisreset" -ArgumentList "/stop" -Verb RunAs shell: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.EXE -command ". '{0}'" env: DOTNET_ROOT: C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Microsoft\dotnet NUGET: C:\actions-runner_work_tool\nuget.exe\6.9.1\x64/nuget.exe

    Error : C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Microsoft\dotnet\sdk\7.0.406\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(267,5): error MSB3021: Unable to copy file "obj\Release\net7.0\Fujiq.Api.dll" to "C:\inetpub\atarifujiq\publish\Fujiq.Api.dll". The process cannot access the file 'C:\inetpub\atarifujiq\publish\Fujiq.Api.dll' because it is being used by another process. [C:\actions-runner_work\AtariFusionRepo\AtariFusionRepo\AtariScraper\Fujiq.Api.csproj] Error: Process completed with exit code 1.

0

Hello Abhinav,

Thanks for the response. but still I'm facing the issue pwsh command is getting executed but IIS server is not getting stop/start.

gitHub Action response :

Run Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass Start-Process -FilePath "iisreset" -ArgumentList "/stop" -Verb RunAs shell: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.EXE -command ". '{0}'" env: DOTNET_ROOT: C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Microsoft\dotnet NUGET: C:\actions-runner_work_tool\nuget.exe\6.9.1\x64/nuget.exe

Error :

C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Microsoft\dotnet\sdk\7.0.406\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(267,5): error MSB3021: Unable to copy file "obj\Release\net7.0\Fujiq.Api.dll" to "C:\inetpub\atarifujiq\publish\Fujiq.Api.dll". The process cannot access the file 'C:\inetpub\atarifujiq\publish\Fujiq.Api.dll' because it is being used by another process. [C:\actions-runner_work\AtariFusionRepo\AtariFusionRepo\AtariScraper\Fujiq.Api.csproj] Error: Process completed with exit code 1.

vikash
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions