Nuget restore myapp.sln 未被识别为 Gitlab CI/CD 中用于 Web 窗体应用的命令 ASP.NET

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

提问人:dharani kumar 提问时间:11/18/2023 更新时间:11/18/2023 访问量:36

问:

我正在尝试为我的 ASP.NET Web 窗体应用程序设置 CI/CD。我需要在Gitlab中完成。所以我做了很多研究,并在 Gitlab 上使用了 dotnet CI 的模板。 这些是我使用脚本的一些来源。

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

以下是我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\'

但是,我无法运行 nuget restore 命令。它给出以下错误-

$ & "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

我已将最新的 nuget 可执行文件下载到我的本地,并根据来源使用本地 nuget 和 MSbuild 路径。我是 CI/CD 的新手,我什至不确定如何调试问题。我直接在命令中使用了路径而不是变量,删除/添加了引号和所有其他语法,但仍然无法让它工作。没有 restore 命令并且只在 sln 文件上运行 MS 构建,我得到

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?)

所以我认为恢复nuget包应该可以解决这个问题。我已经用不同的语法运行了多次,并且还为环境变量添加了 nuget 路径(不确定这是否是解决方案)

基本上,我只是尝试为我的 ASP.NET 4.5 Web 窗体应用程序设置 CI/CD,构建应用程序,将文件发布到文件夹并将这些文件复制到 IIS 服务器文件夹。我只停留在构建阶段。如果有人能指导我哪里出错了,我将不胜感激。此外,请任何好的资源来帮助我处理 ASP.NET Web 表单应用程序的整个 CI/CD。

WebForms 持续集成 NuGet GitLab-CI gitlab-ci.yml

评论

0赞 andy meissner 11/18/2023
我没有你的问题的答案,只有 2 个一般建议:1.尝试直接在运行器上复制命令。2.我认为你不需要周围的''。你应该能够写入 - C:\Nuget\nuget.exe 还原 ..\MyApp\MyApp.sln
0赞 andy meissner 11/18/2023
还可以直接在 Gitlab Pipeline 编辑器中编辑您的gitlab-ci.yml,这样它就会被实时 linted
0赞 dharani kumar 11/18/2023
@andymeissner我使用的是管道编辑器,我什至不知道其他方法。脚本中是否需要 Dotnet 映像?我目前正在我的公司存储库中使用共享运行器(Windows)。您能否告诉我如何直接在运行器上运行这些命令的高级步骤。谢谢!
0赞 andy meissner 11/18/2023
运行器应该是某人连接到您的 Gitlab 实例的计算机或 VM。应尝试找出此运行器上是否存在 C:\Nuget\nuget.exe。访问此运行器类似于远程桌面连接
0赞 zivkan 11/18/2023
为什么不使用或?NuGet.exe 是一种用于还原包的旧方法,具有额外的复杂性和故障模式,因此直接使用 MSBuild 只会提高管道的可靠性。dotnet restoremsbuild -t:restore

答: 暂无答案