0
  • I created a project that is automatically packed into a NuGet package and added to Azure Artifacts through a pipeline
  • My NuGet package uses a library from nuget.org called "TextFieldParserStandard"
  • I install my NuGet by adding the Artifacts Feed package source in Visual Studio
  • I import classes and use functions, but I receive the error:
System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not load file or assembly 'TextFieldParserStandard, Version=1.0.0.0,
 Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. 

If I manually search and add this library in my projects where I use the NuGet, my NuGet works. But they should come automatically. When I install other packages I don't need to manually install their libraries. So the problem is "TextFieldParserStandard" is not installed automatically at once with my NuGet installation.

In Artifacts Feed, I have only my package "MyNuGet version 1.0.0.11538". I don't know if I should have "TextFieldParserStandard" in my Feed. In Visual Studio, Manage NuGetPackages, my NuGet does not have any dependencies.

My NuGet SDK: .NET Standard 2.0 (note: compatible with imported projects since it works if I manually add TextFieldParserStandard).

If needed I can give the yaml pipeline. This targets somehow the problem. Build NuGet Package automatically including referenced dependencies

But adding IncludeReferencedProjects to yaml did not solve.

Mihai Socaciu
  • 155
  • 2
  • 12

1 Answers1

0

Azure custom Nuget package external libraries

That because you are not add the reference package TextFieldParserStandard to your custom package MyNuGet as dependency.

In this case, it will not automatically install the reference package TextFieldParserStandard to your project when you install the package MyNuGet.

To resolve this issue, you could add the property <PrivateAssets>all</PrivateAssets> for the package TextFieldParserStandard in your project MyNuGet file MyNuGet.csproj:

  <ItemGroup>
    <PackageReference Include="TextFieldParserStandard" Version="1.0.0">
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>

Submit this change to the repo, then generate the new package for your custom package, it will have the TextFieldParserStandard package as dependecy:

enter image description here

Update:

Since TextFieldParser cannot be referenced in unit tests.

You could try to create your .nupsec file with Dependencies element, like:

<dependencies>             
  <dependency id="another-package" version="3.0.0" />             
  <dependency id="yet-another-package" version="1.0.0" />        
</dependencies>

You can refer this document for some more details.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • 1
    After that action, my unit tests in MyNuget no longer run because the error `Could not load file or assembly`. TextFieldParser cannot be referenced in unit tests. In Build solution the pipeline also fails. It seems PrivateAssets is doing the opposite and telling that the package is development-only. – Mihai Socaciu Sep 01 '21 at 16:39
  • @MihaiSocaciu, Got it. Since TextFieldParser cannot be referenced in unit tests. You could try to create your `.nupsec` file with Dependencies element, like: ` ` https://learn.microsoft.com/en-us/nuget/reference/nuspec#example-nuspec-files – Leo Liu Sep 02 '21 at 02:59
  • Dependency now appears, but `MyNuGet 1.0.0 does not support any target frameworks` `MyNuGet 1.0.0 is not compatible with uap10.0.16299` . I tried this in .nuspec, but its of no help: ``` ``` I need to use the package in a UWP app and a .NET Core 3.1 app. I checked compatibility chart and even before it was working. It only seems the .nuspec is missing something. – Mihai Socaciu Sep 02 '21 at 14:08
  • The .nuspec file solves the problem of dependency. If you edit your answer I can mark it as the solution and I will create another question about Target framework comaptibility. It seems MyNuget cannot be used, not even in .Net Standard 2.0 projects. The same SDK as the library. – Mihai Socaciu Sep 03 '21 at 13:08
  • @MihaiSocaciu, I have updated the answer. Welcome to post another question. – Leo Liu Sep 06 '21 at 01:50
  • Update: this solution solved all the previous problems above https://stackoverflow.com/a/60618939/9442199 – Mihai Socaciu Sep 07 '21 at 08:06