我正在使用GitLab,我需要创建一个.gitlab-ci.yml脚本来为一个生成nuGet包的项目运行持续集成管道。
我很难找到可靠的文件来回答这个问题:
我应该使用dotnet pack还是nuget pack?
nuget.exe不能作为命令使用,除非我的CI脚本下载它(我正在使用GitLab,因此必须在.gitlab-ci.yml上添加一些内容才能这样做)。我的理解是,dotnet隐式地使用nuget,所以不需要直接使用nuget。
dotnet命令的问题是我不能引用nuspec文件,它只是被忽略了。
我试过了
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包。
更新:另一种选择是:
nuget pack ./*NuGet/*.nuspec -Version $VERSION -OutputDirectory pepe -Prop Configuration=Release -NoDefaultExcludes -Verbosity detailed发布于 2018-10-17 15:31:00
我现在成功地从GitLab的CI/CD为我的dotnet核心应用程序构建了GitLab包。
需要考虑的事情:
\窗口样式的路径。我需要将它们转换为linux风格的/。确保您的文件src部分引用了存在于指定路径上的dll和pdb,否则在创建nuget时会得到异常,因为它不会找到任何东西。所以我的nuspec看起来是这样的:<?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)。示例:#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因此,这些是构建具有如下结构的项目所需的所有命令:
myApp
-ToolBelt.Application.Nuget
--ToolBelt.Application.Nuget.nuspec
-ToolBelt.Application.Contracts
-ToolBelt.Application.Model
-ToolBelt.Application.Model.UnitTests其中,包含nuspec (例如:ToolBelt.Application.Nuget)的项目必须对包中需要包含的每个项目(例如:ToolBelt.Application.Contracts和ToolBelt.Application.Model)具有依赖关系。
发布于 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
发布于 2018-09-11 12:21:15
必须检查生成日志中是否有错误。也许有一些礼物。我尝试创建包,并使用以下方法: 1.目录结构
solution \
interfaces
bin
debug
netcore2.1
interfaces.dll
common.dll
configuration.dll
interfaces.nuspec
interfaces.csproj
IService.cs
models
configuration<?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>dotnet pack interfaces.csproj /p:NuspecFile="bin\debug\interfaces.nuspec"一切都很好,nupkg包含所有的*.dll。但是如果有什么错误(例如路径),我就会出错。
https://stackoverflow.com/questions/52271134
复制相似问题