通过 Azure Devops 部署 Nuget 包时未添加依赖项
Dependencies not getting added when Nuget package deployed through Azure Devops
我已经创建了 .net 标准库。创建后,我尝试通过选择项目文件中的 pack 选项从我的 visual studio 创建 nuget 包。
然后尝试在另一个控制台应用程序中使用本地创建的 .nupkg 文件,它工作正常。它显示了预期的依赖关系
然后我通过创建管道通过 Azure devops 部署了相同的库。现在在同一个控制台应用程序中,如果我从我的 Azure devops 源中选择 nuget,它不会显示任何依赖性。
console app 安装后无法使用,它会要求在console app 中再次安装依赖项。
这是我的项目文件。
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Company>MyCompany</Company>
<Authors>Me</Authors>
<Version>1.0.0</Version>
<Description>Library for managing Azure KeyVault</Description>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.5" />
<PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="5.2.7" />
</ItemGroup>
</Project>
我尝试按照建议在项目文件中添加以下内容,但没有帮助。
<PackageReference Include="NuGet.Build.Tasks.Pack" Version="5.4.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
注意:我的项目中没有.nuspec
文件
我在这里错过了什么。
它可能更清楚(事实上,I just created a PR to do so), but hidden at the end of the comment in the YAML snippet for the docs on the Azure DevOps NuGet Task它说:
Uses NuGet.exe and works with .NET Framework apps. For .NET Core and .NET Standard apps, use the .NET Core task.
查看 nuget'exe pack
docs,上面写着:
Use dotnet pack or msbuild -t:pack for PackageReference based projects.
所以基本上,nuget.exe pack
不支持 PackageReference,所有 .NET Core 项目都是 PackageReference。因此,您不应使用 Azure DevOps 中的 NuGet 任务来打包 PackageReference 项目,而是使用 .NET Core 任务(使用 dotnet cli)或带有 -t:pack
参数的 MSBuild。
我已经创建了 .net 标准库。创建后,我尝试通过选择项目文件中的 pack 选项从我的 visual studio 创建 nuget 包。 然后尝试在另一个控制台应用程序中使用本地创建的 .nupkg 文件,它工作正常。它显示了预期的依赖关系
然后我通过创建管道通过 Azure devops 部署了相同的库。现在在同一个控制台应用程序中,如果我从我的 Azure devops 源中选择 nuget,它不会显示任何依赖性。 console app 安装后无法使用,它会要求在console app 中再次安装依赖项。
这是我的项目文件。
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Company>MyCompany</Company>
<Authors>Me</Authors>
<Version>1.0.0</Version>
<Description>Library for managing Azure KeyVault</Description>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.5" />
<PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="5.2.7" />
</ItemGroup>
</Project>
我尝试按照建议在项目文件中添加以下内容
<PackageReference Include="NuGet.Build.Tasks.Pack" Version="5.4.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
注意:我的项目中没有.nuspec
文件
我在这里错过了什么。
它可能更清楚(事实上,I just created a PR to do so), but hidden at the end of the comment in the YAML snippet for the docs on the Azure DevOps NuGet Task它说:
Uses NuGet.exe and works with .NET Framework apps. For .NET Core and .NET Standard apps, use the .NET Core task.
查看 nuget'exe pack
docs,上面写着:
Use dotnet pack or msbuild -t:pack for PackageReference based projects.
所以基本上,nuget.exe pack
不支持 PackageReference,所有 .NET Core 项目都是 PackageReference。因此,您不应使用 Azure DevOps 中的 NuGet 任务来打包 PackageReference 项目,而是使用 .NET Core 任务(使用 dotnet cli)或带有 -t:pack
参数的 MSBuild。