ASP.NET 5(vNext)web项目:从beta4升级到beta6的库冲突

本文关键字:beta4 beta6 冲突 NET vNext 项目 web ASP | 更新日期: 2023-09-27 17:59:54

我用dnvm upgrade -Unstable升级了DNVM。运行dnvm list显示它是活动的:1.0.0-beta6-12120。

我使用ASP.NET 5网站预览模板创建了一个新项目,并验证了它是否会生成。

我将project.json改为参考beta6:

"dependencies": {
  "EntityFramework.SqlServer": "7.0.0-beta6",
  "EntityFramework.Commands": "7.0.0-beta6",
  "Microsoft.AspNet.Mvc": "6.0.0-beta6",
  "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta6",
  "Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta6",
  "Microsoft.AspNet.Authentication.Facebook": "1.0.0-beta6",
  "Microsoft.AspNet.Authentication.Google": "1.0.0-beta6",
  "Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta6",
  "Microsoft.AspNet.Authentication.Twitter": "1.0.0-beta6",
  "Microsoft.AspNet.Diagnostics": "1.0.0-beta6",
  "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta6",
  "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta6",
  "Microsoft.AspNet.Server.IIS": "1.0.0-beta6",
  "Microsoft.AspNet.Server.WebListener": "1.0.0-beta6",
  "Microsoft.AspNet.StaticFiles": "1.0.0-beta6",
  "Microsoft.AspNet.Tooling.Razor": "1.0.0-beta6",
  "Microsoft.Framework.Configuration.Json": "1.0.0-beta6",
  "Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta6",
  "Microsoft.Framework.CodeGenerators.Mvc": "1.0.0-beta6",
  "Microsoft.Framework.Logging": "1.0.0-beta6",
  "Microsoft.Framework.Logging.Console": "1.0.0-beta6"
}

但由于运行库冲突,构建失败:

1>MSBUILD : DNX 4.5.1 error CS0433: The type 'AssemblyFileVersionAttribute' exists in both 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' and 'System.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 1>MSBUILD : DNX 4.5.1 error CS0433: The type 'AssemblyVersionAttribute' exists in both 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' and 'System.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 1>MSBUILD : DNX 4.5.1 error CS0433: The type 'AssemblyInformationalVersionAttribute' exists in both 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' and 'System.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 1>MSBUILD : DNX 4.5.1 error CS0518: Predefined type 'System.String' is not defined or imported 1>MSBUILD : DNX 4.5.1 error CS0518: Predefined type 'System.String' is not defined or imported 1>MSBUILD : DNX 4.5.1 error CS0518: Predefined type 'System.String' is not defined or imported 1>MSBUILD : DNX 4.5.1 error CS0518: Predefined type 'System.Void' is not defined or imported 1>MSBUILD : DNX 4.5.1 error CS0518: Predefined type 'System.Void' is not defined or imported 1>MSBUILD : DNX 4.5.1 error CS0518: Predefined type 'System.Boolean' is not defined or imported

如何解决这一问题?

ASP.NET 5(vNext)web项目:从beta4升级到beta6的库冲突

beta6-*

在project.json文件中,尝试使用beta6-*而不是仅使用beta6。这意味着它将参考它的最新版本

~.dnx''运行时

检查C:'Users'MyUser'.dnx'runtimes中的运行时目录。我的包括以下内容:

dnx-clr-win-x86.1.0.0-beta6          <-- I made this one via a rename.
dnx-clr-win-x86.1.0.0-beta6-12085
dnx-clr-win-x86.1.0.0-beta6-12120

在我的global.json文件中,它与*.sln位于同一目录中,我确保引用这样的运行时之一:

{
    "projects": [ "src", "test" ],
    "sdk": {
        "version": "1.0.0-beta6-12120"
    }
}

如果从命令行构建:

从命令行执行dnu restore。这将强制更新依赖项解析。几乎每当您更改运行时,无论是升级到新运行时还是切换活动运行时,我都会进行恢复。

如果从visual studio构建:

Visual studio使用sdk属性来确定在构建和恢复时要使用哪个运行时。这可能不同于dnvm激活的运行时集。在dnvm中设置活动运行时不会更改IDE使用的运行时。在VS中设置目标不会更改命令行上的活动运行时。

要更改Visual Studio使用的运行时,请执行以下操作之一:

为整个解决方案设置最低dnx版本

手动编辑global.json(解决方案级别文件)。设置或改变";sdk";到所需的运行时版本。这设置了所有项目的默认值,并且可以在下面的项目级别覆盖它。

为项目设置所需的运行时

右键单击项目>属性>应用

检查Use specific DNX version。设置为所需的版本、平台和体系结构