我已经阅读了有关将项目依赖项实际捆绑到 Nuget 包中所必须经历的不同解决方法,而不是让每个项目都被引用为自己的 nuget 依赖项。 This post约瑟夫·奥托森 (Josef Ottoson) 的文章是迄今为止最清晰、最简洁的。
我喜欢他编辑 .nuspec 文件而不是 .csproj 文件的方法。我正在尝试弄清楚这是否可以在 Azure Pipelines 中实现。
我像这样设置了一个新的 PipeLine:
在dotnet build
中,我设置了路径以包含我想要构建的所有项目文件CompanyName.Library.@(Core|Dep1|Dep2|Dep3)/*.csproj
。生成的 .dll 应该全部位于 $(build.artifactstagingdirectory)
中。
我尝试将以下内容添加到我的基础项目中的 .nuspec 文件中:
<files>
<file src=".\CompanyName.Library.*.dll" target="lib\net6.0" />
</files>
在 dotnet pack
任务中,我设置了“不构建”标志(因为我在上一步中构建了),并将 nuspec 文件的路径设置为 CompanyName.Library。核心/*.nuspec
.
除了设置用于发布包的目标 Azure Artifact 之外,我几乎保留了 NuGet Push
任务中的默认设置。
这不起作用——我生成的 .nupkg 不包含任何 dll。
是否有人以前做过此操作并使其正常工作,或者有人知道我可以做什么才能使其正常工作?
编辑 - 进一步澄清我所追求的内容
我的解决方案中的项目结构如下所示:
库.csproj
- ProjA.csproj(依赖项)
ProjA.csproj
- ProjB.csproj
- ProjC.csproj
ProjC.csproj
- ProjD.csproj
我需要将 Library、ProjA、ProjB、ProjC 和 ProjD 全部打包到一个 nuget 包中。
最佳答案
下面是我这边的一个示例,可能对您有帮助。在此示例中,我不使用 nuspec
文件来打包 NuGet 包。
这个示例在我这边已经运行良好很长时间了。您可以引用它并尝试设置或更新您的管道。
variables:
VerMajor: 2
VerMinor: $[counter(variables['VerMajor'], 0)]
VerPatch: $[counter('VP', 1)]
Package_Version: $(VerMajor).$(VerMinor).$(VerPatch)
jobs:
- job: buildAndPublish
displayName: 'Build and Publish NuGet Package'
steps:
# Build and pack the NuGet package with the auto-generated version number.
- task: DotNetCoreCLI@2
displayName: 'dotnet pack'
inputs:
command: pack
packagesToPack: MathCalc/MathCalc.csproj
packDirectory: '$(Build.ArtifactStagingDirectory)/MathCalc'
versioningScheme: byEnvVar
versionEnvVar: 'PACKAGE_VERSION'
# Publish the packed NuGet package (.nupkg) to Azure Artifacts feed.
- task: DotNetCoreCLI@2
displayName: 'dotnet push'
inputs:
command: push
packagesToPush: '$(Build.ArtifactStagingDirectory)/MathCalc/*.nupkg'
publishVstsFeed: 'MyFeed'
关于azure-devops - 如何创建 nuget 包并包含 Azure DevOps Pipelines 的项目依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77100298/