使用 dnxcore50 使用 Kestrel 执行 dnu 恢复时出现 ArgumentOutOfRangeException

ArgumentOutOfRangeException when doing dnu restore with Kestrel using dnxcore50

我在尝试使用 dnx 核心和 Visual Studio Windows 7 上的代码为 Asp.NET Core 1.0 构建 Web 应用程序时遇到问题。我使用 Yeoman 生成了一个空应用程序,并且然后 运行 dnu restore。这给出了以下输出:

Microsoft .NET Development Utility CoreClr-x64-1.0.0-rc1-16609

  CACHE https://api.nuget.org/v3/index.json
Restoring packages for d:\development\asp.net core\yeoman_test\EmptyApplication\
project.json
Writing lock file d:\development\asp.net core\yeoman_test\EmptyApplication\proje
ct.lock.json
----------
System.ArgumentOutOfRangeException: Specified argument was out of the range of v
alid values.
Parameter name: supportedFrameworks
   at NuGet.NetPortableProfile..ctor(String frameworkDirectory, String name, IEn
umerable`1 supportedFrameworks)
   at NuGet.NetPortableProfileTable.LoadPortableProfile(String versionDirectory,
 String profileDirectory)
   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at NuGet.NetPortableProfileTable.BuildPortableProfileCollection()
   at NuGet.NetPortableProfileTable.GetProfileData()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at NuGet.NetPortableProfileTable.GetProfile(String profileName)
   at NuGet.NetPortableProfile.Parse(String profileValue)
   at NuGet.VersionUtility.IsPortableLibraryCompatible(FrameworkName frameworkNa
me, FrameworkName targetFrameworkName)
   at NuGet.VersionUtility.IsCompatible(FrameworkName frameworkName, FrameworkNa
me targetFrameworkName)
   at NuGet.ContentModel.ContentItemCollection.FindBestItemGroup(SelectionCriter
ia criteria, ContentPatternDefinition[] definitions)
   at Microsoft.Dnx.Tooling.Utils.LockFileUtils.CreateLockFileTargetLibrary(Lock
FilePackageLibrary library, IPackage package, RestoreContext context, String cor
rectedPackageName)
   at Microsoft.Dnx.Tooling.RestoreCommand.WriteLockFile(LockFile previousLockFi
le, String projectLockFilePath, Project project, List`1 graphItems, PackageRepos
itory repository, IProjectResolver projectResolver, IEnumerable`1 contexts)
   at Microsoft.Dnx.Tooling.RestoreCommand.<RestoreForProject>d__69.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(Task task)
   at Microsoft.Dnx.Tooling.RestoreCommand.<>c__DisplayClass68_0.<<Execute>b__2>
d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot
ification(Task task)
   at Microsoft.Dnx.Tooling.RestoreCommand.<Execute>d__68.MoveNext()
----------
Restore failed
Specified argument was out of the range of valid values.
Parameter name: supportedFrameworks

NuGet Config files used:
    C:\Users\<user>\AppData\Roaming\NuGet\nuget.config

Feeds used:
    https://api.nuget.org/v3-flatcontainer/

当前运行时我的 dnvm 输出:

*    1.0.0-rc1-update2 coreclr x64          win             default

和 project.json:

{
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": true
  },
  "tooling": {
    "defaultNamespace": "EmptyApplication"
  },

  "dependencies": {
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final"
  },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel"
  },

  "frameworks": {
    "dnx451": { },
    "dnxcore50": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules"
  ],
  "publishExclude": [
    "**.user",
    "**.vspscc"
  ]
}

我可以使用以下 project.json(目录中没有其他文件)以最小形式复制问题:

{
    "dependencies": {
        "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final"
    },

    "frameworks": {
        "dnxcore50": {}
    }
}

我深入研究了 Kestrel 的 nuget 包及其依赖项(对于 DNXCore5.0)是:

  <group targetFramework="DNXCore5.0">
    <dependency id="Microsoft.AspNet.Hosting" version="1.0.0-rc1-final" />
    <dependency id="Microsoft.Extensions.Logging.Abstractions" version="1.0.0-rc1-final" />
    <dependency id="System.Numerics.Vectors" version="4.1.1-beta-23516" />
    <dependency id="System.Collections" version="4.0.11-beta-23516" />
    <dependency id="System.Diagnostics.Debug" version="4.0.11-beta-23516" />
    <dependency id="System.Diagnostics.TraceSource" version="4.0.0-beta-23516" />
    <dependency id="System.Diagnostics.Tracing" version="4.0.21-beta-23516" />
    <dependency id="System.Globalization" version="4.0.11-beta-23516" />
    <dependency id="System.IO" version="4.0.11-beta-23516" />
    <dependency id="System.Linq" version="4.0.1-beta-23516" />
    <dependency id="System.Net.Primitives" version="4.0.11-beta-23516" />
    <dependency id="System.Runtime.Extensions" version="4.0.11-beta-23516" />
    <dependency id="System.Runtime.InteropServices" version="4.0.21-beta-23516" />
    <dependency id="System.Text.Encoding" version="4.0.11-beta-23516" />
    <dependency id="System.Threading" version="4.0.11-beta-23516" />
    <dependency id="System.Threading.Tasks" version="4.0.11-beta-23516" />
    <dependency id="System.Threading.Thread" version="4.0.0-beta-23516" />
    <dependency id="System.Threading.ThreadPool" version="4.0.10-beta-23516" />
    <dependency id="System.Threading.Timer" version="4.0.1-beta-23516" />
  </group>

我研究了这些并发现将我的 project.json 依赖项更改为仅包含 Microsoft.AspNet.HostingSystem.Numerics.Vectors 会导致与 supportedFrameworks 相同的错误。可能还有其他人,但在 Microsoft.Extensions.Logging.AbstractionsSystem.CollectionsSystem.Diagnostics.Debug 工作之后,我决定在继续之前先在这里问一下。

当然,我假设我在做一些愚蠢的事情,但似乎无法弄清楚到底是什么。

删除(或重命名)Reference Assemblies\Microsoft\Framework\.NETPortable 文件夹。

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable

另请参阅:NuGet Fails to Install FluentValidation