J'ai des problèmes avec un projet référençant 2 packages qui font ensuite référence à Newtonsoft.Json mais à des versions différentes. J'utilise le paquet de nuget de Refit
et Microsoft.NET.Sdk.Functions
. Lorsque j'essaie de générer la solution, l'erreur suivante apparaît:
C:\dev\noddy\noddy-api\src\noddy.Api>dotnet build
C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj : error NU1607: Version conflict detected for Newtonsoft.Json. Reference the package directly from the project to resolve this issue. \r
C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj : error NU1607: noddy.Api (>= 1.0.0) -> Refit (>= 4.0.1) -> Newtonsoft.Json (>= 10.0.3) \r
C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj : error NU1607: noddy.Api (>= 1.0.0) -> Microsoft.NET.Sdk.Functions (>= 1.0.2) -> Newtonsoft.Json (>= 9.0.1).
Maintenant, si je fais ce qui est dit et référence le paquet directement à partir de mon projet, une autre erreur se produit lors de la construction:
C:\dev\noddy\noddy-api\src\noddy.Api>dotnet add package Newtonsoft.Json
Writing C:\Users\joebloggs\AppData\Local\Temp\tmp7250.tmp
info : Adding PackageReference for package 'Newtonsoft.Json' into project 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'.
log : Restoring packages for C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj...
info : CACHE http://www.myget.org/F/Azure-appservice/api/v2/FindPackagesById()?id='Newtonsoft.Json'
info : CACHE https://www.nuget.org/api/v2/FindPackagesById()?id='Newtonsoft.Json'
info : Package 'Newtonsoft.Json' is compatible with all the specified frameworks in project 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'.
info : PackageReference for package 'Newtonsoft.Json' version '10.0.3' added to file 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'.
C:\dev\noddy\noddy-api\src\noddy.Api>dotnet build
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
noddy.Api -> C:\dev\noddy\noddy-api\src\noddy.Api\bin\Debug\net461\bin\noddy.Api.dll
C:\Users\joebloggs\.nuget\packages\Microsoft.net.sdk.functions\1.0.2\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(31,5): error : Could not load file or Assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified. [C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj]
Build FAILED.
C:\Users\joebloggs\.nuget\packages\Microsoft.net.sdk.functions\1.0.2\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(31,5): error : Could not load file or Assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified. [C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:03.05
C:\dev\noddy\noddy-api\src\noddy.Api>
J'ai essayé d'ajouter des redirections d'assemblage, mais il semble que celles-ci soient ignorées.
J'ai aussi essayé de supprimer tous les paquets et de les rajouter un par un et toujours pas de joie:
C:\dev\noddy\noddy-api\src\noddy.Api>dotnet remove package refit
info : Removing PackageReference for package 'refit' from project 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'.
C:\dev\noddy\noddy-api\src\noddy.Api>dotnet remove package Microsoft.NET.Sdk.Functions
info : Removing PackageReference for package 'Microsoft.NET.Sdk.Functions' from project 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'.
C:\dev\noddy\noddy-api\src\noddy.Api>dotnet remove package Newtonsoft.Json
info : Removing PackageReference for package 'Newtonsoft.Json' from project 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'.
C:\dev\noddy\noddy-api\src\noddy.Api>dotnet add package Microsoft.NET.Sdk.Functions
Writing C:\Users\joebloggs\AppData\Local\Temp\tmp1F1B.tmp
info : Adding PackageReference for package 'Microsoft.NET.Sdk.Functions' into project 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'.
log : Restoring packages for C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj...
info : CACHE http://www.myget.org/F/Azure-appservice/api/v2/FindPackagesById()?id='Microsoft.NET.Sdk.Functions'
info : CACHE https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.NET.Sdk.Functions'
info : Package 'Microsoft.NET.Sdk.Functions' is compatible with all the specified frameworks in project 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'.
info : PackageReference for package 'Microsoft.NET.Sdk.Functions' version '1.0.2' added to file 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'.
C:\dev\noddy\noddy-api\src\noddy.Api>dotnet add package refit
Writing C:\Users\joebloggs\AppData\Local\Temp\tmp39D7.tmp
info : Adding PackageReference for package 'refit' into project 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'.
log : Restoring packages for C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj...
info : CACHE http://www.myget.org/F/Azure-appservice/api/v2/FindPackagesById()?id='refit'
info : CACHE https://www.nuget.org/api/v2/FindPackagesById()?id='refit'
error: Version conflict detected for Newtonsoft.Json. Reference the package directly from the project to resolve this issue.
error: noddy.Api (>= 1.0.0) -> Refit (>= 4.0.1) -> Newtonsoft.Json (>= 10.0.3)
error: noddy.Api (>= 1.0.0) -> Microsoft.NET.Sdk.Functions (>= 1.0.2) -> Newtonsoft.Json (>= 9.0.1).
info : Package 'refit' is compatible with all the specified frameworks in project 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'.
info : PackageReference for package 'refit' version '4.0.1' added to file 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'.
C:\dev\noddy\noddy-api\src\noddy.Api>dotnet build
C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj : error NU1607: Version conflict detected for Newtonsoft.Json. Reference the package directly from the project to resolve this issue. \r
C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj : error NU1607: noddy.Api (>= 1.0.0) -> Refit (>= 4.0.1) -> Newtonsoft.Json (>= 10.0.3) \r
C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj : error NU1607: noddy.Api (>= 1.0.0) -> Microsoft.NET.Sdk.Functions (>= 1.0.2) -> Newtonsoft.Json (>= 9.0.1).
C:\dev\noddy\noddy-api\src\noddy.Api>dotnet add package Newtonsoft.Json
Writing C:\Users\joebloggs\AppData\Local\Temp\tmp8B13.tmp
info : Adding PackageReference for package 'Newtonsoft.Json' into project 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'.
log : Restoring packages for C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj...
info : CACHE http://www.myget.org/F/Azure-appservice/api/v2/FindPackagesById()?id='Newtonsoft.Json'
info : CACHE https://www.nuget.org/api/v2/FindPackagesById()?id='Newtonsoft.Json'
info : Package 'Newtonsoft.Json' is compatible with all the specified frameworks in project 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'.
info : PackageReference for package 'Newtonsoft.Json' version '10.0.3' added to file 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'.
C:\dev\noddy\noddy-api\src\noddy.Api>dotnet build
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
noddy.Api -> C:\dev\noddy\noddy-api\src\noddy.Api\bin\Debug\net461\bin\noddy.Api.dll
C:\Users\joebloggs\.nuget\packages\Microsoft.net.sdk.functions\1.0.2\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(31,5): error : Could not load file or Assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified. [C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj]
Build FAILED.
C:\Users\joebloggs\.nuget\packages\Microsoft.net.sdk.functions\1.0.2\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(31,5): error : Could not load file or Assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified. [C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:03.05
C:\dev\noddy\noddy-api\src\noddy.Api>
De plus, il n’ya rien de magique dans mon csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="refit" Version="4.0.1" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Configuration" />
</ItemGroup>
<ItemGroup>
<None Update="Host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="proxies.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Quelqu'un a-t-il une idée sur la façon de résoudre ce problème?
J'ai réussi à faire fonctionner mon projet avec Newtonsoft.Json 11.0.2 en passant à la version v2 de Azure Functions avec .net core:
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
En cours de problème lié, impossible d'installer le package Mirosoft.NET.Sdk. Nous avons corrigé ce problème en créant un nouveau projet de fonctions de cloud - Azure utilisant vs2017. Ce projet est fourni avec le package Mirosoft.NET.Sdk version 1.0.6. Mettre à jour cela en 1.0.7 fonctionne réellement. Puis installé Newton 9.0.1. A partir de là, pas de problèmes.