如何在 Visual Studio 2015 中修复 DNX/DNVM?

How to fix DNX/DNVM in Visual Studio 2015?

今天我在 Windows 7 x64 上安装了 VS 2015。主要是为了测试新的 .Net Core 功能等。为了测试,我创建了新的 C# "Console Application (Package)" 解决方案并收到了这条消息:

DNX SDK version 'dnx-clr-win-x86.1.0.0-beta5' failed to install. The solution will use DNX SDK version ‘dnx-clr-win-x86.1.0.0-beta5’ for this session.

我无法编译和调试项目。另外,当我在项目属性中打开调试选项卡时,VS 崩溃了。

打开解决方案时的 DNVM 输出:

Invoke-Command : The term 'x86' is not recognized as the name of a cmdlet, func
tion, script file, or operable program. Check the spelling of the name, or if a
 path was included, verify that the path is correct and try again.
C:\Program Files\Microsoft DNX\Dnvm\dnvm.ps1:1451 ????:27
+             Invoke-Command <<<<  ([ScriptBlock]::Create("dnvm-$cmd $cmdargs")
)
    + CategoryInfo          : ObjectNotFound: (x86:String) [Invoke-Command], C 
   ommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Co 
   mmands.InvokeCommandCommand

Invoke-Command : The term 'x86' is not recognized as the name of a cmdlet, func
tion, script file, or operable program. Check the spelling of the name, or if a
 path was included, verify that the path is correct and try again.
C:\Program Files\Microsoft DNX\Dnvm\dnvm.ps1:1451 ????:27
+             Invoke-Command <<<<  ([ScriptBlock]::Create("dnvm-$cmd $cmdargs")
)
    + CategoryInfo          : ObjectNotFound: (x86:String) [Invoke-Command], C 
   ommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Co 
   mmands.InvokeCommandCommand

Invoke-Command : The term 'x86' is not recognized as the name of a cmdlet, func
tion, script file, or operable program. Check the spelling of the name, or if a
 path was included, verify that the path is correct and try again.
C:\Program Files\Microsoft DNX\Dnvm\dnvm.ps1:1451 ????:27
+             Invoke-Command <<<<  ([ScriptBlock]::Create("dnvm-$cmd $cmdargs")
)
    + CategoryInfo          : ObjectNotFound: (x86:String) [Invoke-Command], C 
   ommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Co 
   mmands.InvokeCommandCommand

有什么解决办法吗?

此外,我之前已经分别安装了 VS 2015 Preview 和 DNX/DNVM。但我认为,我在安装 VS 2015 之前将其完全删除。这会以某种方式影响当前的 VS 安装吗?

这是一个known issue

ASP.NET 5: On Windows 7 SP1, DNX SDK cannot be installed without Powershell 3.0.

症状

创建 ASP.NET 5 项目时,收到以下错误消息:

DNX SDK version 'dnx-clr-win-x86.1.0.0-beta5' failed to install. The solution will use DNX SDK version 'dnx-clr-win-x86-1.0.0-beta5' for this session

解决方法

要解决此问题,请安装 Windows Powershell 3.0(或更高版本)并再次尝试创建项目。要查看您当前的 PS 版本,运行 $PsVersionTable 命令 (details).

链接:

我也遇到了这个问题。它似乎与 dnvm.ps1 脚本未引用安装路径的问题有关。来自 Visual Studio 的命令 dnvm install "C:\Program Files (x86)\Microsoft Web Tools\DNX\dnx-clr-win-x86.1.0.0-beta5.nupkg" 被召回为 dnvm-install C:\Program Files (x86)\Microsoft Web Tools\DNX\dnx-clr-win-x86.1.0.0-beta5.nupkg,因为应该引用路径而中断。有关我在以下位置打开的拉取请求的更多信息:

https://github.com/aspnet/dnvm/pull/357

作为解决方法,我的解决方案是更改 "C:\Program Files\Microsoft DNX\Dnvm\dnvm.ps1" 中的以下内容。这将循环遍历参数,确保引用任何包含空格或括号的内容。

替换以下行:

$cmdargs = @($args[1..($args.Length-1)])

与:

# Combine arguments, ensuring any containing whitespace or parenthesis are correctly quoted 
ForEach ($arg In $args[1..($args.Length-1)]) {
    if ($arg -match "[\s\(\)]") {
        $cmdargs += """$arg"""
    } else {
        $cmdargs += $arg
    }
    $cmdargs += " "
}

如果进行此更改后仍有问题,请删除 C:\Users\username\.dnx 并重新打开 Visual Studio 让 Visual Studio 重新创建文件夹。

Install the latest version 通过打开控制台和 运行:

dnvm upgrade

如果你重新打开 VS,你应该可以编译。

如果这不起作用,请尝试删除 C:\Users\username\.dnx 文件夹。重新打开 VS,它将在同一位置重新创建 .dnx 文件夹,只有 2 个脚本:bin\dnvm.cmd 和 bin\dnvm.ps1 注意:这将删除所有已经安装的运行时

重新运行 dnvm upgrade 并在项目属性下检查 Solution DNX SDK 版本 是否与已安装的相匹配。

我的powershell版本是3.0,然后我:

  1. 从以下位置安装 powershell v.4:

https://www.microsoft.com/en-us/download/details.aspx?id=40855

  1. 重启windows

这解决了我的问题。

我可以通过这种方式修复它: 在 2015 年的 Developer Command 提示符中输入此命令

dnvm install 1.0.0-beta5

确定这种方式可以解决您的问题!

今天早些时候我遇到了类似的问题,阅读本页中的评论后我设法解决它的方法非常简单。

首先,我必须说我已经安装了 PowerShell 3.0(对大多数人来说,没有安装似乎是这个问题的主要原因),但我仍然遇到同样的问题。

因此,我不必编辑和修改所涉及的 powershell 脚本以使它们按照建议的方式处理带有空格等的路径,我只是简单地执行以下操作(更简单):

1.- 转到 Windows 资源管理器中的 "C:\Program Files (x86)\Microsoft Web Tools\DNX" 并 "copy" 它的所有内容(基本上是所有包及其子文件夹)

2.- "Paste" 将所有内容放入没有空格的路径中。我用了 "C:\Temp\"

3.- 运行 在命令行上执行以下命令(注意在指示的路径位置中现在没有空格)

dnvm update-self
dnvm install "C:\Temp\dnx-clr-win-x64.1.0.0-beta5.nupkg"
dnvm install "C:\Temp\dnx-coreclr-win-x64.1.0.0-beta5.nupkg"
dnvm list

4.- 现在打开您的 Visual Studio 解决方案,在您的项目 -> 属性 -> 应用程序选项卡上,您现在可以在其中指定要使用的 DNX SDK 版本您现在有空

5.- 重新构建您的解决方案,现在应该一切正常

不错!

尝试

dnvm update-self
dnvm install -u  -r clr  -OS win  -a x86  beta5 -ngen 

重要的是 -u 参数(不稳定)和 beta5 版本字符串。

如果有人在观看一些有点过时的教程(比如我)时遇到 Visual Studio 2015 年不可用的 dnx 问题,请查看下方 link

The RC2 release of .NET Core and ASP.NET Core 1.0 moved from DNX to the .NET Core CLI.

在链接页面的 table 中,您将看到 DNX/DNU 命令与其对应的 CLI 命令之间的映射。 例如:

dnx run 变为 dotnet run