首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >gitlab CI上的dotnet pack或nuget pack

gitlab CI上的dotnet pack或nuget pack
EN

Stack Overflow用户
提问于 2018-09-11 07:49:35
回答 3查看 11.9K关注 0票数 8

我正在使用GitLab,我需要创建一个.gitlab-ci.yml脚本来为一个生成nuGet包的项目运行持续集成管道。

我很难找到可靠的文件来回答这个问题:

我应该使用dotnet pack还是nuget pack

nuget.exe不能作为命令使用,除非我的CI脚本下载它(我正在使用GitLab,因此必须在.gitlab-ci.yml上添加一些内容才能这样做)。我的理解是,dotnet隐式地使用nuget,所以不需要直接使用nuget。

dotnet命令的问题是我不能引用nuspec文件,它只是被忽略了。

我试过了

代码语言:javascript
复制
dotnet pack 'MyProject.Nuget/MyProject.Nuget.csproj' /p:NuspecFile='MyProject.Nuget/MyProject.NuGet.nuspec' /p:PackageVersion=$VERSION --output nupkgs

对于最新版本的正确方法(dotnet --version为2.1.401),任何可靠的文档都将不胜感激,因为我无法创建包含多个dll的有效nuGet包。

更新:另一种选择是:

代码语言:javascript
复制
nuget pack ./*NuGet/*.nuspec -Version $VERSION -OutputDirectory pepe -Prop Configuration=Release -NoDefaultExcludes -Verbosity detailed
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2018-10-17 15:31:00

我现在成功地从GitLab的CI/CD为我的dotnet核心应用程序构建了GitLab包。

需要考虑的事情:

  • 路径很重要:我的nuspec有带有\窗口样式的路径。我需要将它们转换为linux风格的/。确保您的文件src部分引用了存在于指定路径上的dll和pdb,否则在创建nuget时会得到异常,因为它不会找到任何东西。所以我的nuspec看起来是这样的:
代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8" ?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    <id>ToolBelt.Application</id>
    <version>1.0.0</version>
    <authors>TUI</authors>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Shared Contracts and Model for the Application layer</description>
    <projectUrl>https://gitlab.tuiwestern.eu/SalesDistribution/_common-packages/ToolBelt.Application</projectUrl>
  </metadata>
  <files>
    <file src="bin/*/netstandard2.0/ToolBelt.Application.Model.dll" target="lib/netstandard2.0" />
    <file src="bin/*/netstandard2.0/ToolBelt.Application.Model.pdb" target="lib/netstandard2.0" />
    <file src="bin/*/netstandard2.0/ToolBelt.Application.Contracts.dll" target="lib/netstandard2.0" />
    <file src="bin/*/netstandard2.0/ToolBelt.Application.Contracts.pdb" target="lib/netstandard2.0" />
  </files>
</package>
  • 该项目必须有一个.gitlab-ci.yml,其中包含构建、运行generate并将其推送到nuget存储库的所有步骤(在我的例子中是Artifactory)。示例:
代码语言:javascript
复制
#Stages
stages:
  - ci
  - codequality
  - build
  - publish

#Global variables
variables:
  GIT_STRATEGY: $STRATEGY
  BUILD_NUMBER: $CI_PIPELINE_ID

#Jobs
ci:
  image: ocp-golden-images.artifactory.mycompany.eu/gitlab-runner-nuget-dotnet-core:latest
  stage: ci
  script:
    - export VERSION=$(echo $(date +"%Y.%-m%d").$CI_PIPELINE_ID)
    - export NUGET_PACKAGE_FOLDER=nupkgs
    - dotnet build --configuration Release
    - dotnet vstest ./*Tests/bin/Release/**/*Tests.dll
    - mkdir $NUGET_PACKAGE_FOLDER
    - nuget pack ./*NuGet/*.nuspec -Version $VERSION -OutputDirectory $NUGET_PACKAGE_FOLDER -Prop Configuration=Release -NoDefaultExcludes -Verbosity detailed
    - cd $NUGET_PACKAGE_FOLDER
    - dotnet nuget push *.$VERSION.nupkg -s https://artifactory.mycompany.eu/artifactory/api/nuget/MyRepo

因此,这些是构建具有如下结构的项目所需的所有命令:

代码语言:javascript
复制
myApp
-ToolBelt.Application.Nuget
--ToolBelt.Application.Nuget.nuspec
-ToolBelt.Application.Contracts
-ToolBelt.Application.Model
-ToolBelt.Application.Model.UnitTests

其中,包含nuspec (例如:ToolBelt.Application.Nuget)的项目必须对包中需要包含的每个项目(例如:ToolBelt.Application.ContractsToolBelt.Application.Model)具有依赖关系。

票数 4
EN

Stack Overflow用户

发布于 2020-09-10 10:46:44

dotnet命令的问题是我不能引用nuspec文件,它只是被忽略了。

对于dotnet pack,您应该在***.csproj中定义<NuspecFile>***.nuspec</NuspecFile>属性。

https://learn.microsoft.com/en-us/dotnet/core/tools/csproj#nuspecfile https://github.com/NuGet/Home/issues/9788#issuecomment-689151144

票数 2
EN

Stack Overflow用户

发布于 2018-09-11 12:21:15

必须检查生成日志中是否有错误。也许有一些礼物。我尝试创建包,并使用以下方法: 1.目录结构

代码语言:javascript
复制
solution \
   interfaces
       bin
           debug
               netcore2.1
                   interfaces.dll
                   common.dll
                   configuration.dll
           interfaces.nuspec
       interfaces.csproj
       IService.cs
   models
   configuration
  1. Nuspec内容:
代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
    <metadata>
        <id>Interfaces</id>
        <version>1.0.0</version>
        <authors>Interfaces</authors>
        <owners>Interfaces</owners>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>Package Description</description>
    </metadata>
    <files>
        <file src="netstandard2.0\Common.dll" target="lib\netstandard2.0\Common.dll" />
        <file src="netstandard2.0\Configuration.dll" target="lib\netstandard2.0\Configuration.dll" />
        <file src="netstandard2.0\Interfaces.dll" target="lib\netstandard2.0\Interfaces.dll" />
        <file src="netstandard2.0\Models.dll" target="lib\netstandard2.0\Models.dll" />
    </files>
</package>
  1. 在“解决方案\接口”文件夹中运行:
代码语言:javascript
复制
dotnet pack interfaces.csproj /p:NuspecFile="bin\debug\interfaces.nuspec"

一切都很好,nupkg包含所有的*.dll。但是如果有什么错误(例如路径),我就会出错。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52271134

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档