Как разрешить конфликты версий пакета .NET Core - PullRequest
15 голосов
/ 16 июня 2019

Я выполняю миграцию из веб-приложения .NET MVC 5 в проект веб-API .NET Core 2.2 вместе с пятью проектами .NET Standard 2.0, размещенными в одном решении.

Сейчас я получаю 28 предупреждений (MSB3277) о конфликтах пакетов, которые находятся в пространстве имен System. Например, для System.Collections.Concurrent существует конфликт версий между Version=4.0.11.0 и Version=4.0.14.0 (см. Блок ошибок ниже).

Попытка устранения неисправности:

  1. Я попытался удалить все .NET Core SDK, которые я не использую, и в настоящее время установлен 2.2.300. Это не сработало.
  2. Я попытался зайти в NuGet на уровне решения, чтобы установить недостающую сборку, но 4.0.14 даже недоступен в списке выбора. Я могу выбрать одну из следующих версий: 4.3, 4.0.12, 4.0.10 и 4.0.0. Я попытался установить 4.3 во всех проектах, но это не сработало.
  3. Другие решения в Интернете, похоже, либо рекомендуют перейти на версию из SDK, либо жестко запрограммировать ссылку в файле * .csproj, чего я не предпочитаю делать, если в этом нет необходимости. Мне не нравится первый, потому что кажется нелогичным движение назад, и мне не нравится последний, потому что это жестко кодирует исправление для постоянного использования старого пакета, что кажется действительно плохой идеей, потому что кажется маловероятным, что оно будет обновить до новых версий, которые будут выпущены.

Кто-нибудь знает, как разрешить эти предупреждения? Любая помощь с благодарностью.

Подробный вывод при сборке для одного из предупреждений:

Line 5419: 3>    Dependency "System.Collections.Concurrent, Version=4.0.14.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
Line 5420: 3>        Could not resolve this reference. Could not locate the assembly "System.Collections.Concurrent, Version=4.0.14.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
Line 5675: 3>    There was a conflict between "System.Collections.Concurrent, Version=4.0.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Collections.Concurrent, Version=4.0.14.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
Line 5675: 3>    There was a conflict between "System.Collections.Concurrent, Version=4.0.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Collections.Concurrent, Version=4.0.14.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
Line 5676: 3>        "System.Collections.Concurrent, Version=4.0.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was chosen because it was primary and "System.Collections.Concurrent, Version=4.0.14.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was not.
Line 5676: 3>        "System.Collections.Concurrent, Version=4.0.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was chosen because it was primary and "System.Collections.Concurrent, Version=4.0.14.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was not.
Line 5677: 3>        References which depend on "System.Collections.Concurrent, Version=4.0.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\Program Files\dotnet\sdk\NuGetFallbackFolder\netstandard.library\2.0.3\build\netstandard2.0\ref\System.Collections.Concurrent.dll].
Line 5677: 3>        References which depend on "System.Collections.Concurrent, Version=4.0.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\Program Files\dotnet\sdk\NuGetFallbackFolder\netstandard.library\2.0.3\build\netstandard2.0\ref\System.Collections.Concurrent.dll].

Обновление

Больше ошибок:

https://github.com/dotnet/standard/issues/731

https://github.com/dotnet/corefx/issues/32561

Это ошибка Microsoft?

Минимальный вывод при сборке с перечислением всех 28 предупреждений:

3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Collections.Concurrent" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Collections" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Collections.NonGeneric" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.ComponentModel" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Diagnostics.Debug" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Diagnostics.Process" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Diagnostics.Tracing" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.IO.FileSystem" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Linq" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Net.Primitives" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Net.Security" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Resources.ResourceManager" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Runtime" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Runtime.Extensions" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Runtime.InteropServices.RuntimeInformation" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Security.Cryptography.Algorithms" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Security.Cryptography.Csp" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Security.Cryptography.Encoding" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Security.Cryptography.Primitives" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Security.Cryptography.X509Certificates" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Text.Encoding.Extensions" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Text.RegularExpressions" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Threading" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Threading.Tasks" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Threading.ThreadPool" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Threading.Timer" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Memory" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.

Ответы [ 3 ]

8 голосов
/ 21 июня 2019

Проблема здесь в сильных именах и версиях со смешанной сборкой как минимум для "System.Collections.Concurrent", но, вероятно, для всех 28 предупреждений.

Я попытался зайти в NuGet на уровне решения, чтобы установить недостающую сборку, но 4.0.14 даже не доступен в списке выбора.

Версии, которые вы видите, являются версиями NuGet, и они не совпадают с версиями сборки. например NuGet версии 4.3.0-preview1-24530-04 имеет версию сборки 4.0.13.0 для стандарта .NET 1.3:

Обратите внимание, что в том же пакете версия сборки для netcore50 - 4.0.10.0!

Это ошибка Microsoft?

Нет, это особенность. Если сборка имеет строгое имя ., Тогда полная версия должна совпадать. Если нет, то это даст предупреждение. Если GAC не используется, тогда может быть опубликована только одна версия сборки - так что, если используется несколько версий? Примечание. Все сборки Microsoft имеют строгое имя.

Проблема здесь:

  • Вы включаете сборку (со строгим именем), которая встроена в System.Collections.Concurrent сборка версии 4.0.14.0
  • Вы (косвенно) используете в сборке приложения версию 4.0.11.0 для сборки System.Collections.Concurrent.

Итак, две версии для одной сборки!

* Решения 1034 * Существует несколько возможных решений: Используйте везде одну и ту же версию сборки для System.Collections.Concurrent (вам необходимо выяснить, какой пакет NuGet является версией сборки 4.0.14.0). Это в большинстве случаев неосуществимо. Установите версии 4.0.11.0 и 4.0.14.0 в GAC - это не очень популярный вариант в наши дни -> Невозможно для .NET Core, поскольку GAC для .NET отсутствует. ядро. См. Есть ли эквивалент GAC для .NET Core? Используйте <bindingRedirect> в вашем .config. См. Версии перенаправления сборки | Документы Microsoft например. для "System.Collections.Concurrent": <dependentAssembly> <assemblyIdentity name="System.Collections.Concurrent" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="4.0.0.0-4.0.14.0" newVersion="4.0.11.0" /> </dependentAssembly> Финальные заметки

Существует 28 проблем с версиями, но есть большое изменение, которое позволяет решить несколько проблем с помощью одного bindingRedirect. Таким образом, лучший способ - начать с одного (предпочтительно самого верхнего уровня), перестроить и повторять, пока все не будут решены.

Также обратите внимание, что понижение сборки немного сложно, например, сборка, построенная на 4.0.13.0, может использовать функцию, которая была введена / изменена в 4.0.11.0+. Таким образом, вы также можете обновить свою версию и использовать эту версию в атрибуте "newVersion"

0 голосов
/ 25 июня 2019

Краткий ответ: при переходе с одного фреймворка на другой, ВЫ МОЖЕТЕ КОПИРОВАТЬ И ВСТАВИТЬ СВОЙ КОД, НО НЕ КОПИРОВАТЬ И ВСТАВИТЬ USING ЗАЯВЛЕНИЯ НА ВЕРХ КЛАССОВ Компилятор хмурится на последний. Это имеет смысл, потому что рассматриваемые фреймворки (от .NET Framework до .NET Core и .NET Standard) различны, и, не вдаваясь в подробности, Microsoft изменила положение вещей.

Ответ Джулиана указал на обходной путь при копировании и вставке операторов using. Но я решил продолжить и перенастроить проект без операторов using, а затем вручную включить их с помощью Intellisense. Все предупреждения ушли.

Вздох, это то, что я получаю за копирование и вставку моего кода. Похоже, что усилия Microsoft по переносу .NET Framework в реализацию .NET Core и .NET Standard убедили компилятор выпить пятую часть текилы и начать говорить по-испански с разработчиками. В моем случае он сказал «¿que es eso?»

Мой ответ: Вы компилятор, вы должны знать.

0 голосов
/ 24 июня 2019

Переадресация привязки (bindingRedirect) для каждой сборки вы можете сделать это вручную в конфигурации или есть опция в свойствах файла проекта.Проверьте это и обновите.

...