简体   繁体   English

从 Visual Studio 2017 升级到 2019 后项目无法编译

[英]Project doesn't compile after upgrading from Visual Studio 2017 to 2019

I can't understand the warnings and errors from Visual Studio 2019. It seems that all the references to the packages of the project are no longer working after the upgrade from Visual Studio 2017. There are the initial lines of the log when I compile the solution.我无法理解 Visual Studio 2019 的警告和错误。从 Visual Studio 2017 升级后,似乎所有对项目包的引用都不再有效。我编译时有日志的初始行解决方案。

1>------ Build started: Project: ClientServerUpload, Configuration: Debug Any CPU ------
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "System.Text.Encoding.CodePages". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3243: No way to resolve conflict between "System.Text.Encoding.CodePages, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Text.Encoding.CodePages". Choosing "System.Text.Encoding.CodePages, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" arbitrarily.
1>      No way to resolve conflict between "FSharp.Core, Version=4.4.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "FSharp.Core, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Choosing "FSharp.Core, Version=4.4.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" arbitrarily.
1>      No way to resolve conflict between "FSharp.Core, Version=4.4.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "FSharp.Core, Version=4.4.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Choosing "FSharp.Core, Version=4.4.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" arbitrarily.
1>      Consider app.config remapping of assembly "FSharp.Core, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" from Version "4.4.3.0" [] to Version "4.7.0.0" [\\mypath\packages\FSharp.Core.4.7.0\lib\net45\FSharp.Core.dll] to solve conflict and get rid of warning.

There are many other lines after the above, but anyway I can't see what is going wrong.上面还有很多其他的行,但无论如何我看不出哪里出了问题。 For example, I pick the first message, about "System.Text.Encoding.CodePages" .例如,我选择第一条消息,关于"System.Text.Encoding.CodePages" There a warning saying "Could not locate the assembly" and another about a conflict between Version=4.1.3.0 and a reference with no version.有一个警告说"Could not locate the assembly" ,另一个警告是Version=4.1.3.0和没有版本的参考之间的冲突。 But from where does it look at Version=4.1.3.0 ?但是它从哪里看Version=4.1.3.0 In the pacakge.config there is a line:在 pacakge.config 中有一行:

 <package id="System.Text.Encoding.CodePages" version="4.7.0" targetFramework="net461" />

and if I edit the .proj file I see:如果我编辑 .proj 文件,我会看到:

<Reference Include="System.Text.Encoding.CodePages">      <HintPath>..\packages\System.Text.Encoding.CodePages.4.7.0\lib\net461\System.Text.Encoding.CodePages.dll</HintPath>
</Reference>

and the HintPath is indeed there.并且HintPath确实存在。 Similar doubts for all the other messages and errors.对所有其他消息和错误也有类似的疑问。 Only another example, why is it searching FSharp.Core, Version=4.4.1.0 ?再举一个例子,为什么要搜索FSharp.Core, Version=4.4.1.0 Again I have再次我有

  <ItemGroup>
    <Reference Include="FSharp.Core">
      <HintPath>..\packages\FSharp.Core.4.7.0\lib\net45\FSharp.Core.dll</HintPath>
    </Reference>

in the proj file and in the packages.config在 proj 文件和 packages.config 中

  <package id="FSharp.Core" version="4.7.0" targetFramework="net461" />

All the configurations I'm aware of seem correct to me, and the whole solution was completely fine with Visual Studio 2017. The project was built with WebSharper template, I don't know if/how this is relevant, however I also reinstalled WebSharper VSIX, after upgrading to Visual Studio 2019, and I didn't receive any error.我知道的所有配置对我来说似乎都是正确的,整个解决方案在 Visual Studio 2017 中完全没问题。该项目是用 WebSharper 模板构建的,我不知道这是否/如何相关,但是我也重新安装了 WebSharper VSIX,升级到 Visual Studio 2019 后,我没有收到任何错误。 Aside from deleting and restoring all the packages, looking at the .proj file, cleaning and rebuilding the solution, what other options do I have?除了删除和恢复所有包、查看 .proj 文件、清理和重建解决方案之外,我还有什么其他选择? At what else should I look?我还应该看什么? I know I can add remapping to the Web.config, but I don't think it is the solution (not even a workaround).我知道我可以将重新映射添加到 Web.config,但我认为这不是解决方案(甚至不是解决方法)。 For your info, after many hours I managed to get a release with many (strange) lines of remapping and by manually (!) copying some files (including FSharp.Core ) from the packages to the bin folder, that is clearly not an acceptable way to proceed.对于您的信息,几个小时后,我设法通过许多(奇怪的)重新映射行并通过手动(!)将一些文件(包括FSharp.Core )从包复制到 bin 文件夹,这显然是不可接受的方式进行。

I seem to recall something similar when I upgraded an F# project from VS2015 to 2017.当我将一个 F# 项目从 VS2015 升级到 2017 时,我似乎记得类似的事情。

The solution was to update the version of the F# runtime ( FSharp.Core.dll ) in the project properties.解决方案是在项目属性中更新 F# 运行时 ( FSharp.Core.dll ) 的版本。

Looking at the .fsproj for a .NET Core 3.0 F# project: the F# runtime is not actually listed, so must be an implicit dependency: maybe removing it would also work.查看.fsproj以获取 .NET Core 3.0 F# 项目:实际上并未列出 F# 运行时,因此必须是隐式依赖项:也许删除它也可以。

Step 0步骤 0

I've restored an old commit of my project to better describe the original situation and to track all the steps to resolve it.我已经恢复了我的项目的旧提交,以更好地描述原始情况并跟踪解决它的所有步骤。 Before the following 2 operations, I had to nuget upgrade from FSharp.Core 4.6 to 4.7, for a problem specific to WebSharper: the Scripts were not produced.在以下 2 个操作之前,我不得不从 FSharp.Core 4.6 nuget 升级到 4.7,针对特定于 WebSharper 的问题:未生成脚本。

Step 1第1步

I had to edit the .proj file to delete some reference lines, sort of duplicated.我不得不编辑 .proj 文件以删除一些参考线,有点重复。 Here is an example for FSharp.Core , but I did the same for many others (I don't know what exactly originated this problem but removing those lines seems to have done the trick for me)这是FSharp.Core一个示例,但我对许多其他人也做了同样的事情(我不知道这个问题的FSharp.Core是什么,但删除这些行似乎对我FSharp.Core

<Reference Include="FSharp.Core">
  <HintPath>..\packages\FSharp.Core.4.7.0\lib\net45\FSharp.Core.dll</HintPath>
</Reference>
<Reference Include="FSharp.Core" />

In the above case I deleted the last line (and all the other similar lines without a version reference under a tag containing the version of the same package)在上面的例子中,我删除了最后一行(以及在包含相同包版本的标签下没有版本引用的所有其他类似行)

Step 2第2步

Then I copied and pasted all the <dependentAssembly> from the Visual Studio output to the Web.config.然后我将所有<dependentAssembly>从 Visual Studio 输出复制并粘贴到 Web.config。 Again I don't understand wht they are many more than the ones needed for Visual Studio 2017, but these 2 operations apparently solved my issue.我再次不明白它们比 Visual Studio 2017 所需的要多得多,但这两个操作显然解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM