Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dependencies not getting added when Nuget package deployed through Azure Devops

I have created .net standard library. After creating, I tried to created nuget package from my visual studio by choosing the pack option present in project file. Then tried to use the locally created .nupkg file in another console app, it worked fine. Its shows the dependencies as expected

enter image description here

Then I deployed the same libray through Azure devops by creating pipeline. Now in same console app, if I choose the nuget from my Azure devops source, its not showing any dependency. The console app won't work after installing, it asks to install the dependencies again in console app.

enter image description here

Here is my project file.

<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>

I tried adding the below in project file as suggested here, but no help.

<PackageReference Include="NuGet.Build.Tasks.Pack" Version="5.4.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

Note : There is no .nuspec file in my project

What am I missing here.

like image 903
Pரதீப் Avatar asked Mar 06 '20 05:03

Pரதீப்


People also ask

How do I update NuGet dependencies?

By Command-line: You can download nuget.exe,and add the path where it exists to Path system environment variables. Then you could simply reference the nuget.exe directly. After that you can use command like nuget update YourSolution. sln in Package Manager Console to update the dependencies for solution.

Can I use NuGet task in Azure DevOps to pack packagereference projects?

So basically, nuget.exe pack doesn't support PackageReference, and all .NET Core projects are PackageReference. So, you shouldn't use the NuGet task in Azure DevOps to pack PackageReference projects, either use the .NET Core task (which uses the dotnet cli), or MSBuild with the -t:pack argument. You're genius man!

Is it possible to create NuGet package from Visual Studio?

I have created .net standard library. After creating, I tried to created nuget package from my visual studio by choosing the pack option present in project file. Then tried to use the locally created .nupkg file in another console app, it worked fine. Its shows the dependencies as expected

Why does NuGet fail to resolve dependencies?

As shown below, if Package A requires exactly Package B 1.0 and Package C requires Package B >=2.0, then NuGet cannot resolve the dependencies and gives an error. In these situations, the top-level consumer (the application or package) should add its own direct dependency on Package B so that the Nearest Wins rule applies.

How to consume NuGet packages from an azure artifacts feed?

To consume NuGet packages from a feed, add the feed's NuGet endpoint as a package source in Visual Studio. Azure Artifacts feeds work seamlessly with the NuGet Package Manager for Visual Studio 2015 extension as of Visual Studio 2015 Update 1.


1 Answers

It could be clearer (in fact, 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 it says:

Uses NuGet.exe and works with .NET Framework apps. For .NET Core and .NET Standard apps, use the .NET Core task.

Looking at nuget'exe pack docs, it says:

Use dotnet pack or msbuild -t:pack for PackageReference based projects.

So basically, nuget.exe pack doesn't support PackageReference, and all .NET Core projects are PackageReference. So, you shouldn't use the NuGet task in Azure DevOps to pack PackageReference projects, either use the .NET Core task (which uses the dotnet cli), or MSBuild with the -t:pack argument.

like image 190
zivkan Avatar answered Oct 05 '22 10:10

zivkan