Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

dependencies - Multiple level nuget dependency c#

We're facing dificulties trying to make nuget install dependencies of dependencies. We publish custom nugets to an Azure Artifacts with more than one level of dependencies and nuget only installs the first level of these depencencies. As an example:

  • Nuget A has a dependency on Nuget B.
  • Nuget B has a dependency on Nuget C.

A, B and C are all nugets published in our azure artifacts.

Under this scenario, when we install nuget A in a solution it also installs nuget B (listed as a dependency), but nuget C is not installed (although it is necessary for B to work). Is there a way to accomplish this dependency hierarchy when installing a nuget?

All these nugets were published throughout a pipeline like this one:

parameters:
  vmImage: 'windows-latest'
  nugetFeed: '[Our_GUID_Feed]'
  solution: ''
  project: ''
  BuildConfiguration: ''


jobs:
  - job: Job
    pool:
      vmImage: '${{ parameters.vmImage }}'
    steps:
    - task: DotNetCoreCLI@2
      displayName: 'Restore packages'
      inputs:
        command: 'restore'
        projects: '${{ parameters.solution }}'
        vstsFeed: '${{ parameters.nugetFeed }}'
      env:
          System_AccessToken: $(System.AccessToken)

        
    - task: DotNetCoreCLI@2
      displayName: 'Dotnet Build Project'
      inputs:
        arguments: '--configuration ${{ parameters.BuildConfiguration }} /p:Version=$(Build.BuildNumber) /p:Optimize=false --no-restore' 
        projects: '${{ parameters.project }}'
        versioningScheme: byBuildNumber

    - task: DotNetCoreCLI@2
      displayName: 'Dotnet Package Project' 
      inputs: 
        command: pack
        packagesToPack: '${{ parameters.project }}'
        buildProperties: Version=$(Build.BuildNumber)

    - task: DotNetCoreCLI@2 
      displayName: 'Dotnet Push Project' 
      inputs: 
        command: push 
        nuGetFeedType: 'internal'
        publishVstsFeed: '${{ parameters.nugetFeed }}'

Edit: Further info of the problem with an actual example:

This is the csproj of nuget C:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="FluentValidation" Version="9.3.0" />
    <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
    <PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.10" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.10" />
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
  </ItemGroup>
</Project>

Dependencies of C shown in vs

This is the csproj of the nuget B:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="NugetC" Version="1.0.20" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.10" />
  </ItemGroup>
  <Target Name="CopyProjectReferencesToPackage" DependsOnTargets="ResolveReferences">
    <ItemGroup>
      <BuildOutputInPackage Include="@(ReferenceCopyLocalPaths-&gt;WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))" />
    </ItemGroup>
  </Target>
</Project>

Dependencies of B shown in vs

This is the csproj of nuget A:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
      <OutputType>Library</OutputType>
      <TargetFramework>netcoreapp3.1</TargetFramework>
    <TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Dapper" Version="2.0.78" />
    <PackageReference Include="NugetB" Version="1.0.20" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.10" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.10" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.10" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.10" />
    <PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="3.1.10" />
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.10" />
    <PackageReference Include="Moq" Version="4.15.2" />
    <PackageReference Include="NEST" Version="7.9.0" />
  </ItemGroup>
  <Target Name="CopyProjectReferencesToPackage" DependsOnTargets="ResolveReferences">
    <ItemGroup>
      <BuildOutputInPackage Include="@(ReferenceCopyLocalPaths-&gt;WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))" />
    </ItemGroup>
  </Target>
</Project>

Dependencies of A shown in vs

As you can see in this last screenshot, C is not listed as a dependency of A when i try to install it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...