【发布时间】:2020-02-24 15:02:07
【问题描述】:
我正在尝试使用 Azure Pipeline 打包我在 .net core 3.1 中制作的 web api。
- task: DotNetCoreCLI@2
displayName: Package NuGet
inputs:
command: 'pack'
projects: '**/*.csproj'
arguments: '--configuration $(BuildConfiguration)'
outputDir: '$(Build.ArtifactStagingDirectory)/packages'
这就是我使用的任务,我从另一个关于堆栈溢出的帖子中找到的。
我唯一的问题是它提供了许多 .nupkg 文件,而不是一个,并且 web api 包没有依赖 dll。
我还创建了一个 .nuspec 文件,但我似乎无法在 Azure Pipeline 中正确使用它 我已经尝试过这里解释的内容:https://docs.microsoft.com/fr-fr/nuget/reference/msbuild-targets#packing-using-a-nuspec
或者只是像管道工具提示中解释的那样定位 .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>
这是我在管道上遇到的错误:
错误 MSB4068:该元素无法识别或不受支持 在这种情况下。
使用这个任务:
- task: DotNetCoreCLI@2
inputs:
command: 'pack'
packagesToPack: '**/*API.nuspec'
nobuild: true
versioningScheme: 'off'
我知道在微软网站上我也可以使用这个命令
dotnet pack ~/projects/app1/project.csproj -p:NuspecFile=~/projects/app1/project.nuspec -p:NuspecBasePath=~/projects/app1/nuget
但我不确定如何在 AZ 管道中翻译它...
采用的EDIT解决方案:
我决定以这种方式解决我的问题:
- 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'
【问题讨论】:
-
您想通过将 API 项目打包到
.nupkg中来完成什么? -
您在尝试使用
.nuspec文件时遇到了什么问题?请编辑您的问题,向"not manage to use it correctly"提供有关这对您意味着什么的详细信息,以便您在这方面的问题得到解决。 -
您可能需要在 WebApi.csproj 文件中进行一些编辑作为解决方法。这样 dotnet pack 将拾取依赖程序集并将它们一起打包到包中。您可以尝试我答案末尾的两个链接,如果您对如何做到这一点感到困惑并需要更多详细信息,请随时告诉我。
-
你好朋友,这个问题有更新吗?只需检查一下您是否需要任何进一步的帮助:)