我在项目中遇到问题,引用了2个软件包,然后引用了Newtonsoft.Json但两个版本都不同。我正在使用Refit
和Microsoft.NET.Sdk.Functions
的nuget包。当我尝试构建解决方案时,我收到以下错误:
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\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>
我尝试添加程序集重定向但似乎忽略了这些。
我还尝试删除所有软件包并将它们逐个添加回来,但仍然没有任何乐趣:
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>
在我的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>
有人对如何解决这个问题有任何想法吗?
答案 0 :(得分:35)
不幸的是,这是a known bug项目的Azure Functions MSBuild。所有发行版本都对Json.NET 9.0.1具有硬编码依赖性。报告的唯一解决方法是降级到1.0.0-alpha6
版本。
缺少软件包摘要和描述,以及Github project中缺少文档,这清楚地表明这是一项正在进行的工作。
假设你做需要它,你可以尝试克隆.csproj
中的仓库change the dependency并重建包。
与此同时,您应该向issue添加评论,并解释您也会受到影响。
要解决此问题,Line 39 of csproj应更改为:
<PackageReference Include="Newtonsoft.Json" Version="[9.0.1]" />
到
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
对Microsoft.Azure.WebJobs
个套件的测试版
2018年11月更新
repo的自述文件已更新on March 31 2018,其中包含解释为何锁定Json.NET版本以及如何处理此问题的常见问题解答:
问:我需要一个不同的Newtonsoft.Json版本。我该怎么办?答:将您需要的版本添加到csproj中。例如,使用11.0.2将其添加到csproj
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
问:为什么Newtonsoft.Json首先被锁定?
答:Newtonsoft.Json的版本被锁定以匹配函数运行时使用的版本
对(现已锁定)问题进行了长时间的讨论,该问题解释了解锁版本只会在部署之前延迟问题
答案 1 :(得分:0)
遇到相关问题,无法安装Mirosoft.NET.Sdk软件包。通过使用vs2017创建新的Cloud-Azure功能项目来解决这个问题。该项目附带Mirosoft.NET.Sdk软件包版本1.0.6。将其更新到1.0.7实际上有效。然后安装牛顿9.0.1。从那以后,没有问题。
答案 2 :(得分:0)
通过使用具有.net核心的Azure Functions v2,我能够使我的项目与Netwonsoft.Json 11.0.2一起工作:
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
答案 3 :(得分:0)
在Azure中,函数运行时会加载特定版本的牛顿软件(当前在v2中为11.0.1,在v1中为9.0.1).Json 之前通过队列绑定加载函数库
如果您使用与[11.0.1]二进制不兼容的任何函数(例如,v12中使用的任何新属性),则用于使其编译的任何变通办法都将导致诊断运行时失败。