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

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

问题描述

相关:

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

使用 Program.cs

构建演示后

使用系统;命名空间控制台应用程序{公开课计划{public static void Main(string[] args){Console.WriteLine("再见,残酷的世界");环境.退出(1);}}}

project.json

{"版本": "1.0.0-*","description": "ConsoleApplication 控制台应用程序",作者":["],标签":["],"projectUrl": "","licenseUrl": "",工具":{"defaultNamespace": "控制台应用程序"},命令":{控制台应用程序":控制台应用程序"},依赖关系":{},构架": {dnx451":{},dnxcore50":{依赖关系":{"System.Console": "4.0.0-*","System.Runtime": "4.0.21-*","System.Runtime.Extensions": "4.0.11-*"}}}}

我解决了以下依赖项

和错误信息

<小时>

现在我使用

安装了最新的不稳定 DNX

dnvm upgrade -u -r coreclr -arch x64dnvm 升级 -u -r clr -arch x64dnvm 升级 -u -r coreclrdnvm 升级 -u -r clr

显示命令dnvm list"

之后我修改了 NuGet 配置以另外使用 https://www.myget.org/F/aspnetvnext/api/v3/index.json:

然后我将 global.jsonsdk.verison"1.0.0-rc1-update1" 修改为 "1.0.0-rc2-16343" 在 Visual Studio 的 GUI 中:

并保存更改.之后我制作了Restore Packages"并再次构建项目.我得到以下版本的依赖项:

并且程序可以没有任何错误地执行.

值得一提的是,即使我们将 sdk.verison 改回 "1.0.0-rc1-update1" 我们仍将拥有相同的分辨率来自 rc2-16343 的依赖,因为它将使用 %USERPROFILE%.dnxpackages 中兑现的包.将 NuGet 配置更改为原始状态非常重要(取消选中 URL https://www.myget.org/F/aspnetvnext/api/v3/index.json)并删除所有 %USERPROFILE%.dnxpackages.我建议您使用

卸载 DNX 的不需要的夜间构建

dnvm 升级dnvm 卸载 1.0.0-rc2-16343 -r coreclr -arch x64dnvm 卸载 1.0.0-rc2-16343 -r clr -arch x64dnvm 卸载 1.0.0-rc2-16343 -r coreclrdnvm 卸载 1.0.0-rc2-16343 -r clr

在所有步骤之后,dnvm 列表"中的状态应该与最初相同.可以验证 %USERPROFILE%.dnx untimes 不包含任何带有 1.0.0-rc2-16343 的目录,文件 %USERPROFILE%.dnxaliasdefault.txt 包含 dnx-clr-win-x86.1.0.0-rc1-update1 并且 PATH 只包含 %USERPROFILE%.dnx untimesdnx-clr-win-x86.1.0.0-rc1-update1in 而不是对 1.0.0-rc2-16343 的引用.换句话说,我们完成了测试并返回到稳定的 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:gitenvironmentexitConsoleApplicationProgram.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%.dnxpackages. The dependencies will be resolved from NuGet. To be exactly there are the file %APPDAT%NuGetNuGet.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%.dnxpackages 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%NuGetNuGet.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%.dnxpackages 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%.dnxpackages. 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%.dnxpackages. 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 untimes don't contains any directories with 1.0.0-rc2-16343, the file %USERPROFILE%.dnxaliasdefault.txt contains dnx-clr-win-x86.1.0.0-rc1-update1 and the PATH contains only %USERPROFILE%.dnx untimesdnx-clr-win-x86.1.0.0-rc1-update1in 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 Core 中编译 Environment.Exit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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