Nuget restore myapp.sln is not being recognized as a command in Gitlab CI/CD for ASP.NET Web forms app

132 Views Asked by At

I'm trying to setup CI/CD for my ASP.NET Web forms application. I need to do it in Gitlab. So I researched a lot and used the templates for dotnet CI on Gitlab. These are some of the sources I used the script from.

https://stackoverflow.com/a/38211190

https://medium.com/@gabriel.faraday.barros/gitlab-ci-cd-with-net-framework-39220808b18f

https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/dotNET.gitlab-ci.yml

Following is the script I have in my gitlab-ci.yml

variables:
    GIT_STRATEGY: none
    NUGET_PATH: 'C:\Nuget\nuget.exe'
    MSBUILD_PATH: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe'
    
stages:
  - build
  - deploy

# before_script:
#   - $NUGET_PATH restore ..MyApp\MyApp.sln

build-job:
  stage: build
  tags:
    - myapp-dev
  script:
    - cd c:\dharani\git\MyApp
    - '& "$NUGET_PATH" restore ..\MyApp\MyApp.sln'
    - '& "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe" /p:Configuration=Debug /clp:ErrorsOnly ..\MyApp\MyApp.sln'
  artifacts:
    expire_in: 2 days
    paths:
      - '.\bin\Release\Publish\'

However I'm not able to run the nuget restore command. It gives the following error-

$ & "C:\Nuget\nuget.exe" restore "..\MyApp\MyApp.sln"
& : The term 'C:\Nuget\nuget.exe' is not recognized as the name of a cmdlet, function, script file, or operable 
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Windows\TEMP\build_script2722061214\script.ps1:235 char:3

I have downloaded the latest nuget executable to my local and am using the local nuget and MSbuild paths following according to the sources. I'm new to CI/CD and I'm not even sure how to debug the issue. I directly used the path in the command instead of variable, removed/added quotes and all other syntaxes, still couldn't get it to work. Without the restore command and running just the MS build on sln file, I'm getting

C:\dharani\git\MyApp\MyApp\Services\Service.cs(13,7): error CS0246: The type or namespace name 'AuthorizeNet' could not be found (are you missing a using directive or an assembly reference?)

SO I assumed restoring nuget packages should solve the issue. I've ran it multiple times with different syntaxes and also added nuget path to environment variables(not sure that's even a solution to this)

Basically I'm just trying to setup CI/CD for my ASP.NET 4.5 Web Forms application, build the app, publish the files onto a folder and copy those files to IIS server folder. I'm stuck at build stage only. If someone could please guide me where I'm going wrong, would highly appreciate it. Also any good sources to help me with the whole CI/CD for ASP.NET Web forms app please.

0

There are 0 best solutions below