1

I've read the following post about this problem, but with my solution and nuget file are located in the same folder, the task dotnet build fails, while the previous dotnet restore succeed.

I have no HintPath in my project, just direct references to Packages.

What is confusing to me is that somehow, the restore task is trying to look at .net core 5 assemblies in my private nuget feed (Azure Artifacts). For instance:

   GET https://pkgs.dev.azure.com/mycompany/_packaging/58afa52a-c2d4-4346-bfd2-1bf77f29075e/nuget/v3/flat2/system.servicemodel.security/index.json
   Unauthorized https://pkgs.dev.azure.com/mycompany/_packaging/58afa52a-c2d4-4346-bfd2-1bf77f29075e/nuget/v3/flat2/system.servicemodel.duplex/index.json 52ms

It seems that nuget.org is simply ignored.

Following is the content of my nuget.config and project file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear/>
    <add key="nuget" value="https://api.nuget.org/v3/index.json" />
    <add key="Dev" value="https://pkgs.dev.azure.com/rtetech/_packaging/Dev/nuget/v3/index.json" />
  </packageSources>
</configuration>

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <AssemblyVersion>0.0.4</AssemblyVersion>
    <FileVersion>0.0.4</FileVersion>
    <RootNamespace>MyCompany.Common</RootNamespace>
    <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
    <Version>0.0.4-pre</Version>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="CommonDatabase.EFCore" Version="1.4.10" />
    <PackageReference Include="CryptographyTools.Portable" Version="2.0.4" />
    <PackageReference Include="Dapper.StrongName" Version="1.50.5" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
    <PackageReference Include="MyCompanyLog.Standard" Version="1.3.3" />
    <PackageReference Include="System.ServiceModel.Duplex" Version="4.8.*" />
    <PackageReference Include="System.ServiceModel.Federation" Version="4.8.*" />
    <PackageReference Include="System.ServiceModel.Http" Version="4.8.*" />
    <PackageReference Include="System.ServiceModel.NetTcp" Version="4.8.*" />
    <PackageReference Include="System.ServiceModel.Security" Version="4.8.*" />
  </ItemGroup>

</Project>

2 Answers2

0

My solution to this problem is to still use dotnet restore in conjunction with dotnet build with the --no-restore option on the command line for the latter. Now this works like a charm...

0

If you are able to use the .NET 6 SDK to build your project (you really should upgrade the taget framework as well, .NET 5 is end of life since May 2022) you can use something called "package source mapping" to say which packages should be retrieved from which source.

In your case it would look something like this.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <packageSources>
        <clear />
        <add key="nuget" value="https://api.nuget.org/v3/index.json" />
        <add key="Dev" value="https://pkgs.dev.azure.com/rtetech/_packaging/Dev/nuget/v3/index.json" />
    </packageSources>
    <packageSourceMapping>
        <packageSource key="Dev">
            <package pattern="MyCompanyLog.*" />
        </packageSource>
        <packageSource key="nuget">
            <package pattern="*" />
        </packageSource>
    </packageSourceMapping>
</configuration>

This might also speed up the restore process since it isn't checking every source for every package.

It should work to use this with your .NET 5 project as long as you use the .NET 6 SDK.

https://learn.microsoft.com/en-us/nuget/consume-packages/package-source-mapping

Karl-Johan Sjögren
  • 16,544
  • 7
  • 59
  • 68