在.NET核心无法编译Environment.Exit [英] Can't compile Environment.Exit in .NET Core

查看:325
本文介绍了在.NET核心无法编译Environment.Exit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相关报道:统环境在.NET核心



我试图编译它使用 Environment.Exit 在.NET中的核心程序。我使用哟ASPNET 以创建默认的控制台应用程序,安装 System.Runtime.Extensions ,然后加入通话到 Environment.Exit(1)(全样本的在github )。在运行时 DNU建立我得到这个错误:



C:\git\ environmentexit\ConsoleApplication\Program.cs(13,25):DNXCore,版本V5.0 =错误CS0117:环境不包含退出
定义



据我所知,这corefx拉申请应该意味着 Environment.Exit 暴露出来,所以我想不通我错过了什么。



任何想法


解决方案

所有我想要确认问题DNX当前稳定版本存在第一: 1.0.0-RC1-UPDATE1 与Visual Studio一起安装2015更新1问题是的已经固定的当前不稳定的版本 1.0.0-rc2-16343



我尝试下面的描述非常详细的每个人都可以如何重现该问题一步一步来。在下一步我将演示如何安装最新的 DNX(这是 1.0.0-rc2-16343 今天)和编译的不稳定的构建您的演示成功。最后,我展示了如何卸载的不稳定的DNX的构建回去 1.0.0-RC1-UPDATE1



都明白,一个可以安装DNX的多个版本是很重要的首先。在另一边的所有包通过使用解决了该项目的上下文菜单或通过使用还原包DNU恢复命令将在常见文件夹 <$ C保存(缓存) $ C>%USERPROFILE%\.dnx\packages 。依赖从的NuGet得到解决。为了准确地还有其中包含的NuGet与用于依赖解析URL中的配置文件%APPDAT%\NuGet\NuGet.Config 。因此,人们可以玩不同的NuGet配置后,并与不同版本的DNX有错误的结果。我觉得这种行为DNX今天的大型设计问题。我希望它会尽快修复。



在任何方式,我严格推荐的删除所有从%USERPROFILE文件 %\.dnx\packages 有确定的结果。另外一个人应该核实的NuGet配置文件只能从starndard的NuGet源加载 https://api.nuget.org/v3/index.json (或 https://www.myget.org/F/aspnetvnext/api/v2/ )和可选的从 https://开头WWW。 myget.org/F/aspnetvnext/api/v3/index.json (或 https://www.myget.org/F/aspnetmaster/api/v2 ),它可以包含其他ASP.NET稳定的软件包。一个可以%APPDAT%\NuGet\NuGet.Config 手动编辑文件或检查详见上面菜单在Visual Studio源的描述:工具/的NuGet软件包管理器/程序包管理器设置,然后选择包源最后。



1)我删除在中的所有文件%USERPROFILE%\ .dnx\packages
2)使用dnvm名单,我只有 1.0.0-RC1决赛并验证 1.0.0-RC1-UPDATE1 版本DNX的。我使用了类似于卸载dnvm 1.0.0-rc2-16343 -r coreclr -arch 86卸载一些不需要的版本,并验证了 1.0.0-RC1-UPDATE1 是违约使用dnvm升级。在此之后,dnvm清单显示:





3)只设置 https://api.nuget.org/v3/index.json 在我的初始配置:





的Program.cs


$ b你的演示后建设$ b <预类=郎-CS prettyprint-覆盖> 使用系统;

命名空间ConsoleApplication
{
公共类节目
{
公共静态无效的主要(字串[] args)
{
Console.WriteLine(再见,残酷的世界);
Environment.Exit(1);
}
}
}

project.json



<预类=郎JSON prettyprint-覆盖> {
版本 :1.0.0- *,
说明:ConsoleApplication控制台应用程序,
的作者:[

],
标签:

],
projectUrl:,
licenseUrl:,
工具:{
DefaultNamespace的:ConsoleApplication
},
命令:{
ConsoleApplication:ConsoleApplication
},
依赖:{},
框架:{
dnx451:{}
dnxcore50:{
依赖:{
System.Console:4.0 .0- *,
System.Runtime:4.0.21- *,
System.Runtime.Extensions:4.0.11- *
}
}
}
}

我得到解决以下依赖性





和错误消息








现在我安装了最新的不稳定的DNX使用



<预类=郎无prettyprint-覆盖> dnvm升级-u -r coreclr -arch 64
dnvm升级-u - - [R CLR -arch 64
dnvm升级-u -r coreclr
dnvm升级-u -r CLR

显示命令列表dnvm





在我修改的NuGet配置中使用 https://www.myget.org/F/aspnetvnext/api/v3/index.json 额外的:





然后我修改 sdk.verison global.json 1.0.0-RC1-UPDATE11.0.0 -rc2-16343在Visual Studio中的GUI:





和保存更改。之后,我做了还原包,并再次生成项目。我得到的依赖以下版本:





和可以执行的程序没有任何错误



这是说变化重要的是,即使我们会改变 sdk.verison 1.0.0-RC1-UPDATE1我们仍然有依赖关系,从​​ rc2-16343 ,因为这将被用来在%USERPROFILE%\.dnx\packages 。改变的NuGet配置,以原始状态这是非常重要的(取消网址 https://www.myget.org/F/aspnetvnext/api/v3/index.json ),并删除所有的%USERPROFILE%\.dnx\packages 。我建议你​​通过



使用率卸载DNX的unneded晚上构建

  dnvm升级
dnvm卸载1.0.0- rc2-16343 -r coreclr -arch 64
dnvm卸载1.0.0-rc2-16343 -r CLR -arch 64
dnvm卸载1.0.0-rc2-16343 -r coreclr
dnvm卸载1.0.0-rc2-16343 -r CLR

在所有的步骤中的一个应具有相同的状态dnvm清单作为最初。一个可以验证%USERPROFILE%\.dnx\runtimes 不包含 1.0.0-rc2-16343 ,文件%USERPROFILE%\.dnx\alias\default.txt 包含 DNX-CLR-双赢的x86。 1.0.0-RC1-UPDATE1 和路径只包含%USERPROFILE%\.dnx\runtimes\dnx-CLR-双赢x86.1.0.0-RC1到 1.0.0-rc2-16343 -update1\bin ,而不是引用。换句话说,我们完成了我们的测试,并返回到稳定RC1-UPDATE1。


Related: System.Environment in .NET Core

I'm trying to compile a program which uses Environment.Exit in .NET Core. I've used yo aspnet to create the default console application, installed System.Runtime.Extensions and then added a call to Environment.Exit(1) (full sample on github). When running dnu build I get this error:

C:\git\environmentexit\ConsoleApplication\Program.cs(13,25): DNXCore,Version=v5.0 error CS0117: 'Environment' does not contain a definition for 'Exit'

As far as I can tell, this corefx pull request should mean that Environment.Exit is exposed, so I can't figure out what else I'm missing.

Any ideas?

解决方案

First of all I want to confirm that the problem exist in the current stable version of DNX: 1.0.0-rc1-update1 installed together with Visual Studio 2015 Update 1. The problem is already fixed in the current unstable build 1.0.0-rc2-16343.

I try to describe below very detailed how everybody can reproduce the problem step by step. In the next step I would show how to install the latest unstable build of DNX (it's 1.0.0-rc2-16343 today) and to compile your demo successfully. Finally I show how to uninstall unstable build of DNX go back to 1.0.0-rc1-update1.

First of all it's important to understand that one can install multiple version of DNX. On the other side all the packages resolved by usage "Restore Packages" in the context menu of the project or by usage of "dnu restore" command will be saved (cached) in the common folder %USERPROFILE%\.dnx\packages. The dependencies will be resolved from NuGet. To be exactly there are the file %APPDAT%\NuGet\NuGet.Config which contains the configuration of NuGet with URLs used for resolving of dependencies. Thus one can have wrong results after "playing" with different NuGet configurations and with different versions of DNX. I find such behavior as the large design problem of DNX today. I hope that it will be fixed soon.

In any way I strictly recommend to delete all files from %USERPROFILE%\.dnx\packages to have deterministic results. Additionally one should verify NuGet configuration to load the files only from the starndard NuGet source https://api.nuget.org/v3/index.json (or https://www.myget.org/F/aspnetvnext/api/v2/) and optionally from https://www.myget.org/F/aspnetvnext/api/v3/index.json (or https://www.myget.org/F/aspnetmaster/api/v2), which can contains additional ASP.NET stable packages. One can either edit the file %APPDAT%\NuGet\NuGet.Config manually or to check the described above sources in Visual Studio in menu: "Tools" / "NuGet Package Manager" / "Package Manager Settings" and choosing "Package Sources" finally.

1) I removed all files under %USERPROFILE%\.dnx\packages 2) verified using "dnvm list" that I have only 1.0.0-rc1-final and 1.0.0-rc1-update1 versions of DNX. I uninstalled some unneeded version using something like "dnvm uninstall 1.0.0-rc2-16343 -r coreclr -arch x86" and verified that the 1.0.0-rc1-update1 is default by usage "dnvm upgrade". After that the "dnvm list" displayed:

3) set only https://api.nuget.org/v3/index.json in my initial configuration:

After building of your demo with Program.cs

using System;

namespace ConsoleApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Goodbye, cruel world");
            Environment.Exit(1);
        }
    }
}

and project.json

{
  "version": "1.0.0-*",
  "description": "ConsoleApplication Console Application",
  "authors": [
    ""
  ],
  "tags": [
    ""
  ],
  "projectUrl": "",
  "licenseUrl": "",
  "tooling": {
    "defaultNamespace": "ConsoleApplication"
  },
  "commands": {
    "ConsoleApplication": "ConsoleApplication"
  },
  "dependencies": { },
  "frameworks": {
    "dnx451": { },
    "dnxcore50": {
      "dependencies": {
        "System.Console": "4.0.0-*",
        "System.Runtime": "4.0.21-*",
        "System.Runtime.Extensions": "4.0.11-*"
      }
    }
  }
}

I get the following dependencies resolved

and the error message


Now I installed the latest unstable DNX using

dnvm upgrade -u -r coreclr -arch x64
dnvm upgrade -u -r clr -arch x64
dnvm upgrade -u -r coreclr
dnvm upgrade -u -r clr

The command "dnvm list" displayed

After that I modified the NuGet configuration to use https://www.myget.org/F/aspnetvnext/api/v3/index.json additionally:

Then I modified sdk.verison of global.json from "1.0.0-rc1-update1" to "1.0.0-rc2-16343" in the GUI of Visual Studio:

and saved the changes. After that I made "Restore Packages" and build the project once more. I get the following versions of dependencies:

and the program could be executed without any error.

It's vary important to mention that even if we would change the sdk.verison back to "1.0.0-rc1-update1" we will still have the same resolution of dependences from rc2-16343 because it will be used the packages cashed in %USERPROFILE%\.dnx\packages. It's really important to change NuGet configuration to original state (uncheck URL https://www.myget.org/F/aspnetvnext/api/v3/index.json) and delete all %USERPROFILE%\.dnx\packages. I would recommend you to deinstall unneded night build of DNX by usage of

dnvm upgrade
dnvm uninstall 1.0.0-rc2-16343 -r coreclr -arch x64
dnvm uninstall 1.0.0-rc2-16343 -r clr -arch x64
dnvm uninstall 1.0.0-rc2-16343 -r coreclr
dnvm uninstall 1.0.0-rc2-16343 -r clr

After all the steps one should have the same state in "dnvm list" as initially. One can verify that %USERPROFILE%\.dnx\runtimes don't contains any directories with 1.0.0-rc2-16343, the file %USERPROFILE%\.dnx\alias\default.txt contains dnx-clr-win-x86.1.0.0-rc1-update1 and the PATH contains only %USERPROFILE%\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc1-update1\bin and not references to 1.0.0-rc2-16343. In other words we finished our test and are returned back to stable rc1-update1.

这篇关于在.NET核心无法编译Environment.Exit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆