.net core 带有Azure Devops的.net core 3.1包dll
我正在尝试将我在.net core 3.1中制作的web api与Azure管道打包.net core 带有Azure Devops的.net core 3.1包dll,.net-core,azure-devops,.net Core,Azure Devops,我正在尝试将我在.net core 3.1中制作的web api与Azure管道打包 - task: DotNetCoreCLI@2 displayName: Package NuGet inputs: command: 'pack' projects: '**/*.csproj' arguments: '--configuration $(BuildConfiguration)' outputDir: '$(Build.ArtifactStagingDirectory)/
- task: DotNetCoreCLI@2
displayName: Package NuGet
inputs:
command: 'pack'
projects: '**/*.csproj'
arguments: '--configuration $(BuildConfiguration)'
outputDir: '$(Build.ArtifactStagingDirectory)/packages'
这就是我使用的任务,我在另一篇关于堆栈溢出的文章中找到了它
我唯一的问题是它提供了大量的.nupkg文件,而不是一个,而且web api包没有依赖项dll
我还创建了一个.nuspec文件,但我似乎无法在Azure管道中正确使用它
我已经试过这里的解释:
或者像管道的工具管道上解释的那样,只需将.nuspec文件作为目标
如果有人能让我走上正确的道路,我将不胜感激:)
编辑:
我想将所有内容打包到一个nupkg中,然后将其部署到IIS站点
这是我的nuspec文件:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>WebAPI</id>
<version>1.0.0</version>
<authors>Kevin Pinero</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>WebAPI</description>
</metadata>
<files>
<file src=".\bin\Release\*\*.dll" target="lib" />
<file src=".\bin\Release\*\*.exe" target="lib" />
<file src=".\bin\Release\*\*.json" target="lib" />
<!-- <file src=".\bin\Release\*\Properties\*.json" target="lib" /> -->
<file src=".\bin\Release\*\*.pdb" target="lib" />
<file src=".\bin\Release\*\*.config" target="lib" />
</files>
</package>
我知道在微软的网站上我也可以使用这个命令
dotnet pack ~/projects/app1/project.csproj -p:NuspecFile=~/projects/app1/project.nuspec -p:NuspecBasePath=~/projects/app1/nuget
但我不知道如何在AZ管道中翻译它
采用的编辑解决方案:
我决定通过以下方式解决我的问题:
- task: DotNetCoreCLI@2
displayName: Build at solution level
inputs:
command: 'build'
projects: $(solution)
arguments: '--no-restore --configuration $(buildConfiguration)'
- task: DotNetCoreCLI@2
displayName: Execute tests
inputs:
command: 'test'
projects: $(testProjects)
arguments: '--no-build --configuration $(buildConfiguration)'
- task: DotNetCoreCLI@2
displayName: Pack project
inputs:
command: publish
projects: '**/projectName.csproj'
publishWebProjects: False
arguments: '--no-build --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)
zipAfterPublish: False
- task: PublishBuildArtifacts@1
displayName: Publish
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'artefact name'
我建议使用Azure DevOps在线管道编辑器。它的使用和升级非常好(自动完成、语法检查、直接提交/推送) 您可以通过以下步骤实现您的目标:
- 网络构建
- dotnet pack->在此处指定要打包的正确项目
- 努吉推
netstandard2.1
.NETCore和Azure DevOps是一个很好的组合,如果您有任何问题,请随时发表评论
(就我而言,我打包库项目,但不打包Api,我在Api上进行dotnet发布,以将它们用作发布管道中的工件。)UPDATE
因为您正试图打包一个Web API项目以交付给IIS,所以应该停止尝试使用nuget作为该机制,而是使用dotnet publish
命令。如果要继续使用DotNetCoreCLI@2
task(与使用script
快捷方式直接调用dotnet
cli相反),然后我将向您指出要执行的文档
本文档不是专门为Web API项目编写的,而是一组用于使用.Net核心应用程序is Azure DevOps管道的通用指南。下面引用了一个例子(重点):
在您构建并测试了应用程序(不是专门的web api)后,您可以将构建输出上载到Azure Pipelines或TFS,创建并发布NuGet包,或将构建输出打包到.zip文件中,以部署到web应用程序
当您阅读包并交付代码时,发布到NuGet提要是交付代码的有效选项,它是。然而,这种交付方法应该用于库类型的交付。dotnet publish
命令用于将web api项目及其所有依赖项打包到.zip
(或文件夹,如果指定该选项),以准备针对IIS实例执行web部署命令
原始答案
不必详细说明为什么要从API项目创建.nupkg
你提到:
我唯一的问题是它提供了许多.nupkg文件,而不是一个,而且web api包没有依赖项dll
这是关于项目对项目(P2P
)参考的dotnet pack
文档说明了此行为
打包项目的NuGet依赖项被添加到.nuspec文件中,因此在安装包时可以正确解析这些依赖项项目到项目的引用未打包在项目内。当前,如果存在项目到项目的依赖关系,则每个项目必须有一个包
如果您想对.nupkg
中包含的文件有更多的控制权,那么您需要手动编写.nuspec
文件,并将其提供给dotnet pack
命令,如文档页面上最后一页所示
对dotnet core cli使用Azure DevOps任务DotNetCoreCLI@2
应该允许您将.nuspec
文件的路径简单地放在输入中。如果这对你不起作用,你的问题中需要更多的信息
我唯一的问题是它提供了许多.nupkg文件,
而不是一个,而且web api包没有
依赖项dll
我假设在同一个解决方案中有多个项目。让我们调用Web Api项目A,其他项目B,C和D
1.因此,如果您只想将A打包到nuget包中,而不是使用项目:'***.csproj'
,我们可以使用类似于项目:'***/A.csproj'
。那么它就不会再打包很多nuget包了
2.对于dependencies dll,我想您指的是上面提到的项目参考,如Josh Gust。对于这一点,它仍然是关于dotnetpack
命令的。如果有任何更新,您可以跟踪该问题以获取通知
目前,我们必须更改A.csproj
,以使用msbuild magics作为解决方案。你可以在那里尝试或变通。在我看来,它们都有助于解决你的问题
希望以上所有帮助:)
更新1:
对于您的编辑,如果您想在AZ管道中翻译它,您可以使用custom
命令调用包。大概是这样的:
- task: DotNetCoreCLI@2
displayName: 'dotnet custom'
inputs:
command: custom
projects: '**/ProjectName.csproj'
custom: pack
arguments: '-p:NuspecFile=~/projects/app1/project.nuspec -p:NuspecBasePath=~/projects/app1/nuget'
您可以检查日志以确认它是否实际运行了命令:“C:\Program Files\dotnet\dotnet.exe”pack D:\a\1\s\xxx\xxx.csproj-p:NuspecFile=~/projects/app1/project.nuspec-p:Nu
- task: DotNetCoreCLI@2
displayName: 'Create packed NuGet files'
inputs:
command: 'pack'
packagesToPack: '**/*Api.csproj;!**/*Tests.csproj'
versioningScheme: 'off'
- task: DotNetCoreCLI@2
displayName: 'dotnet custom'
inputs:
command: custom
projects: '**/ProjectName.csproj'
custom: pack
arguments: '-p:NuspecFile=~/projects/app1/project.nuspec -p:NuspecBasePath=~/projects/app1/nuget'