Visual Studio新项目缺少文件/文件夹

时间:2018-01-01 14:31:35

标签: asp.net visual-studio asp.net-core visual-studio-2017

我使用Visual Studio 2017创建新的ASP.NET核心应用程序,但由于缺少依赖项而创建的项目无法编译。根据用户的其他建议,我运行了dotnet restore。这导致应用程序能够编译和运行,但现在我得到了一堆版本冲突,我想摆脱它们

以下是我如何创建项目的截图。

enter image description here

enter image description here

请注意下面项目中缺少的依赖项。

enter image description here

现在我运行dotnet restore

enter image description here

现在应用程序已编译,但我遇到了很多版本冲突

1>  Encountered conflict between 'Reference:C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.netcore.app\2.0.0\ref\netcoreapp2.0\System.AppContext.dll' and 'Reference:C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.appcontext\4.3.0\ref\netstandard1.6\System.AppContext.dll'.  Choosing 'Reference:C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.netcore.app\2.0.0\ref\netcoreapp2.0\System.AppContext.dll' because AssemblyVersion '4.2.0.0' is greater than '4.1.0.0'.
1>  Encountered conflict between 'Reference:C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.netcore.app\2.0.0\ref\netcoreapp2.0\System.Collections.dll' and 'Reference:C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.collections\4.3.0\ref\netstandard1.3\System.Collections.dll'.  Choosing 'Reference:C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.netcore.app\2.0.0\ref\netcoreapp2.0\System.Collections.dll' because AssemblyVersion '4.1.0.0' is greater than '4.0.10.0'.
1>  Encountered conflict between 'Reference:C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.netcore.app\2.0.0\ref\netcoreapp2.0\System.Collections.Concurrent.dll' and 'Reference:C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.collections.concurrent\4.3.0\ref\netstandard1.3\System.Collections.Concurrent.dll'.  Choosing 'Reference:C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.netcore.app\2.0.0\ref\netcoreapp2.0\System.Collections.Concurrent.dll' because AssemblyVersion '4.0.14.0' is greater than '4.0.10.0'.
1>  Encountered conflict between 'Reference:C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.netcore.app\2.0.0\ref\netcoreapp2.0\System.Collections.NonGeneric.dll' and 'Reference:C:\Program Files\dotnet\sdk\NuGetFallbackFolder\system.collections.nongeneric\4.3.0\ref\netstandard1.3\System.Collections.NonGeneric.dll'.  Choosing 'Reference:C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.netcore.app\2.0.0\ref\netcoreapp2.0\System.Collections.NonGeneric.dll' because AssemblyVersion '4.1.0.0' is greater than '4.0.1.0'.
... and so on

我的两个问题是

  1. 创建新的ASP核心项目后,必须立即运行dotnet restore是否正常?如果没有,是什么导致了这个问题呢?
  2. 如何摆脱版本冲突?
  3. 更新

    如果其他人遇到同样的问题而且在这个问题上遇到了麻烦,我发现由于某些原因,我的恢复了丢失的软件包"选项未启用。启用后,我能够成功构建项目,而无需先dotnet restore

    enter image description here

1 个答案:

答案 0 :(得分:1)

  1. 没什么可担心的。绝对正常。当您在命令行中调用dotnet build时,将隐式调用dotnet restore。这是.NET SDK 2.0的变化。如果您被迫手动运行dotnet restore,那将成为另一个问题,这意味着您的.NET Core SDK无法生效。您需要了解global.json并在项目中创建此类文件,以强制使用此计算机上的最新SDK,例如Scott Hanselman wrote
  2.   

    Visual Studio 2017可能要求您使用“还原NuGet包”菜单项。   Visual Studio for Mac或JetBrains Rider会自动恢复软件包。

    1. 没有人试图摆脱这种情况。 MSBuild在计算时有内部逻辑,清楚this issue has been known and harmless (except your eyes) so far
    2. 请充分利用Google和GitHub,您可以找到微软公布的所有官方信息。

      project.assets.json的存在表明package.json的遗留问题仍然存在于构建过程中。