2016-07-07 45 views
1

如何以编程方式确定当前活动的dotnet版本?我可以运行dnvm列表,但不能为我的生活得到它将输出转移到一个变量,文件,字符串......没有任何工作,我无法理解为什么。如何解析dnvm列表

dnvm list > currentList.txt 

导致输出仍在控制台上显示,没有任何重定向到文件。

它似乎并没有被写入标准错误 - 2> & 1不会改变任何东西......

如果还有人甚至可以提供一些见解,为什么这是行不通的,这将是更赞赏。 有没有PowerShell的方式来正确查询这个,我错过了?

+0

只是为了澄清:你想[检索.Net'可用的'版本(http://stackoverflow.com/a/3495491/2486496),或做你想得到'dnvm list'的输出正确,而不是通过控制台显示? – gravity

+0

嗯,我需要能够以编程方式确定构建版本的目标版本是否已安装并且当前已设置为活动版本,如果没有,请自动创建它。所以......发生这种事情对我来说是非常不重要的,只是发生了。如果在Powershell中有更合适的方法,我很乐意采用这种方式。 – BenAlabaster

回答

1

在您的$ env:UserProfile \ .dnx \ bin文件夹中,您将找到一个dnvm.ps1脚本。通过分析这个,你可以看到控制台帮助中不明显的东西 - 它只是一个委托给这个ps1脚本的命令文件 - 任何函数参数都可以从命令行传递,命令会将它们传递给电源外壳。所以,你可以做这样的事情:

#This is the version we're looking to run against 
$required = @{ 
    Version = "1.0.0-rc1-update2"; 
    Architecture = "x64"; 
    Runtime = "clr"; 
    OperatingSystem = "win" 
} 

#Check to see if the version we need is installed... 
$installed = (dnvm list -PassThru | ? { 
    $_.Version -eq $required.Version -and 
    $_.Architecture -eq $required.Architecture -and 
    $_.Runtime -eq $required.Runtime -and 
    $_.OperatingSystem -eq $required.OperatingSystem 
}) 

if ($installed -eq $null) { 
    # The version we require isn't installed... 
    # ...installing it will set it as active 
    dnvm install -VersionNuPkgOrAlias $required.Version ` 
       -Architecture $required.Architecture ` 
       -Runtime $required.Runtime ` 
       -OS $required.OperatingSystem 
} 
elseif (!$installed.Active) { 
    # The version we require is already installed... 
    # ...just set it active 
    dnvm use -VersionOrAlias $required.Version ` 
      -Architecture $required.Architecture ` 
      -Runtime $required.Runtime ` 
      -OS $required.OperatingSystem 
} 
-1

dnx和dnvm消失,dotnet使用不同的模型。没有'活跃'的运行时间了。现在编译应用程序的运行时将用于运行应用程序。

+0

由于各种原因,这并没有回答我的问题,因为我们需要的其他第三方软件的驱动程序尚未针对dotnet内核进行更新,所以我们暂时用dnx和dnvm卡住。 – BenAlabaster

+0

如果你可以在dnx上使用第三方库,你应该可以在.NET Core中使用它们。如果问题在于他们针对的是dnxcore50,那么您只需要'imports'。如果他们的目标是dnx451,那么您也可以在.NET Core项目中使用目标完整的.NET Framework。如果这是不同的,我会有兴趣知道。 – Pawel