如何让 Azure DevOps 为 .net 标准 2.0 项目创建正确的 nuspec? [英] How do I get Azure DevOps to create a correct nuspec for a .net standard 2.0 project?
问题描述
我可以通过在 VS2019 中右键单击项目并选择包来为我的 .net 标准 2.0 库创建合适的 nuget 包.
I can create a proper nuget package for my .net standard 2.0 library by right clicking the project in VS2019 and selecting pack.
.nuspec 包含
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>SBD.Standard</id>
<version>1.0.0</version>
<authors>SBD.Standard</authors>
<owners>SBD.Standard</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Package Description</description>
<dependencies>
<group targetFramework=".NETStandard2.0">
<dependency id="Microsoft.Data.SqlClient" version="1.1.0" exclude="Build,Analyzers" />
<dependency id="Microsoft.EntityFrameworkCore" version="3.1.1" exclude="Build,Analyzers" />
<dependency id="Microsoft.EntityFrameworkCore.SqlServer" version="3.1.1" exclude="Build,Analyzers" />
<dependency id="Newtonsoft.Json.Schema" version="2.0.7" exclude="Build,Analyzers" />
<dependency id="RestSharp" version="106.10.0" exclude="Build,Analyzers" />
<dependency id="System.Data.SqlClient" version="4.6.1" exclude="Build,Analyzers" />
</group>
</dependencies>
</metadata>
</package>
但是,如果我在 azure-pipelines.yml 中使用以下命令在 Azure Devops 中创建 nuget
However if I create the nuget in Azure Devops using the following command in azure-pipelines.yml
- task: DotNetCoreCLI@2
inputs:
command: 'pack'
packagesToPack: '**/SBDSTD.*.csproj'
然后我查看它所包含的包的 .nuspec 文件
Then I look at the .nuspec file for the package created it contains
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
<metadata>
<id>SBD.Standard</id>
<version>2.0.0-CI-20200212-174043</version>
<title>SBD.Standard</title>
<authors>SBD.Standard</authors>
<owners>SBD.Standard</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Description</description>
<dependencies />
</metadata>
</package>
如何让 Devops 创建正确的 .nuspec 文件?
How do I get Devops to create the correct .nuspec file?
推荐答案
如何让 Azure DevOps 为 .net 标准 2.0 项目创建正确的 nuspec?
How do I get Azure DevOps to create a correct nuspec for a .net standard 2.0 project?
在与 Kirsten Greed 进行了长时间的故障排除后,我们想通了.
After a long troubleshooting with Kirsten Greed, we figured it out.
我们解决了以下 YAML 问题以重新生成 .net 标准 2.0 项目的 nuget 包:
We resolve this following YAML to regenerate the nuget package for a .net standard 2.0 project:
trigger: none
pool:
vmImage: vs2017-win2016
steps:
- task: DotNetCoreCLI@2
displayName: 'dotnet restore'
inputs:
command: restore
projects: xxxx/xxx.csproj
vstsFeed: 'XXXXXXX'
- task: DotNetCoreCLI@2
displayName: 'dotnet build'
inputs:
projects: xxx/xxx.csproj
arguments: '/p:Configuration=Release'
- task: DotNetCoreCLI@2
displayName: 'dotnet pack'
inputs:
command: pack
packagesToPack: xxx/xxx.csproj
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'
然后我们可以在解压生成的包后检查.nuspec
文件.
Then we could check the .nuspec
file after unzipping the generated package.
此外,我们可以使用 nuget push 任务将生成的包发布到我们的提要,例如:
In addition, we could use nuget push task to publish the generated package to our feed, like:
- task: DotNetCoreCLI@2
displayName: 'dotnet push'
inputs:
command: push
publishVstsFeed: 'XXXX'
希望这会有所帮助.
这篇关于如何让 Azure DevOps 为 .net 标准 2.0 项目创建正确的 nuspec?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!