Unable to compile environment. Exit in .NET Core

Related: System.Environment in .NET Core

I am trying to compile a program that uses Environment.Exit in .NET Core. I used yo aspnet to create the default console application installed by 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 output request should mean that Environment.Exit is expanding , so I can't figure out what else I am missing.

Any ideas?

+6
source share
1 answer

First of all, I want to confirm that the problem exists in the current stable version of DNX: 1.0.0-rc1-update1 installed with the Visual Studio 2015 update 1. The problem has already been fixed in the current unstable assembly 1.0.0-rc2-16343 .

I will try to describe in great detail below how anyone can reproduce the problem step by step. In the next step, I will show how to install the latest unstable DNX build (this is 1.0.0-rc2-16343 today) and compile your demo version successfully . Finally, I will show how to remove the unstable DNX assembly to return to 1.0.0-rc1-update1 .

First of all, it’s important to understand that you can install the multiple DNX version. On the other hand, all packages allowed with the help of "Restore packages" in the project context menu or with the "dnu restore" command will be saved (cached) in the %USERPROFILE%\.dnx\packages public folder %USERPROFILE%\.dnx\packages Dependencies will be resolved from NuGet. To be precise, there is a %APPDAT%\NuGet\NuGet.Config that contains the NuGet configuration with the URLs used to resolve the dependencies. Thus, you may have incorrect results after a β€œgame” with different NuGet configurations and with different versions of DNX. I find behavior like the big DNX design challenge today. I hope this is fixed soon.

In any case, I strongly recommend deleting all files from %USERPROFILE%\.dnx\packages to get deterministic results. In addition, you need to check the NuGet configuration to download files only from the NuGet starndard 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 may contain additional stable ASP.NET packages. You can either edit the %APPDAT%\NuGet\NuGet.Config manually, or check the sources described above in Visual Studio in the menu: "Tools" / "NuGet Package Manager" / "Package Manager Settings" and, finally, select "Package Sources" .

1) I deleted all the files in %USERPROFILE%\.dnx\packages 2) checked using the "dnvm list" that I only have versions 1.0.0-rc1-final and 1.0.0-rc1-update1 DNX. I uninstalled some unnecessary version using something like "dnvm uninstall 1.0.0-rc2-16343 -r coreclr -arch x86" and confirmed that the value 1.0.0-rc1-update1 used by default "dnvm upgrade". After that, the "dnvm list" will be displayed:

enter image description here

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

enter image description here

After creating a 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:

enter image description here

and error message

enter image description here


Now I installed the last 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 "dnvm list" command is displayed

enter image description here

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

enter image description here

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

enter image description here

and saved the changes. After that I created "Restore Packages" and once again I created the project. I get the following dependency versions:

enter image description here

and the program can be executed without errors .

It is important to remember that even if we change sdk.verison to "1.0.0-rc1-update1" , we will still have the same resolution of dependencies on rc2-16343 , because it will be used for packages cashed in %USERPROFILE%\.dnx\packages . It is very important to change the configuration of NuGet to its original state (uncheck https://www.myget.org/F/aspnetvnext/api/v3/index.json ) and delete all %USERPROFILE%\.dnx\packages . I would recommend you uninstall the DNX nightly build using

 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, you need to have the same state in the "dnvm list" as it was originally. You can verify that %USERPROFILE%\.dnx\runtimes does not contain directories from 1.0.0-rc2-16343 , the file %USERPROFILE%\.dnx\alias\default.txt contains dnx-clr-win-x86.1.0.0-rc1-update1 , and PATH contains only %USERPROFILE%\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc1-update1\bin , and not links to 1.0.0-rc2-16343 . In other words, we finished our test and returned to stable rc1-update1.

+13
source

All Articles