79

Every time I build a project using the new .NET Core RC2 templates I am not provided with a runnable .EXE file. If I hit F5 for debugging my console application it runs fine through the

C:\Program Files\dotnet\dotnet.exe 

application. And if I use the

dotnet run 

command in the folder, it runs fine as well. But I see no way to run the application without the .NET Core CLI tools.

The contents of my

 bin\Debug\netcoreapp1.0\

folder looks like this:

Bin folder structure

As you can see there is no .EXE file available. Just the dll.

Am I overlooking something? Or is there something wrong with my project.json file?

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0-rc2-3002702"
    }
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": "dnxcore50"
    }
  }
}

Thanks!

ArunPratap
  • 4,816
  • 7
  • 25
  • 43
Johannes Heesterman
  • 1,248
  • 1
  • 12
  • 21
  • @DavidPine The answer there for using compilationOptions is deprecated in RC2. I tried it anyway, and it gave the same result. – Johannes Heesterman May 23 '16 at 13:35
  • You are right, sorry about that. It should be `buildOptions` and you already have the `"emitEntryPoint": true` which should do the trick. Did you attempt to manually run `dotnet build` from the **cmd** line window? Also, are you certain that you are looking in the right output directory? – David Pine May 23 '16 at 13:37
  • @DavidPine Yeah, I tried the build, run and publish commands. They all work fine. I just don't get an .exe file in my bin folder or any underlying folder. – Johannes Heesterman May 23 '16 at 13:57
  • You're supposed to run netcoreapp1.0 with "dotnet yourfile.dll", i guess. Well that works for me on both windows and WSL perfectly fine. – Felype Aug 10 '16 at 00:55

5 Answers5

72

There are actually 2 app models in .NET Core:

  • Portable apps: heavily inspired by "DNX console apps", these apps don't produce .exe files and are instead executed by the .NET Core shared runtime (whose version is defined by the Microsoft.NETCore.App package, thanks to its special type: platform attribute). The corresponding .NET Core runtime must be installed on the machine to be able to use portable apps. If the exact version cannot be found, an exception is thrown when running dotnet run.

  • Standalone apps: standalone apps are really similar to good old .NET console apps as they produce .exe files. The .NET Core runtime doesn't have to be installed on the machine, because it is directly embedded with the application itself.

You're currently using the first model. To use the standalone model, you need to tweak your project.json:

  • Add a runtimes section to list the environments your app will target (e.g win7-x64 or ubuntu.14.04-x64). You can find the complete list here.
  • Remove the Microsoft.NETCore.App dependency. You can replace it by this package instead: "NETStandard.Library": "1.5.0-rc2-24027".

Here's an example of a standalone app:

{
  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true,
    "warningsAsErrors": true
  },

  "dependencies": {
    "Microsoft.Extensions.Configuration.Binder": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.CommandLine": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
    "Microsoft.Extensions.DependencyInjection": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final",
    "NETStandard.Library": "1.5.0-rc2-24027"
  },

  "frameworks": {
    "net451": { },

    "netcoreapp1.0": {
      "dependencies": {
        "System.Net.Ping": "4.0.0-rc2-24027"
      },

      "imports": [
        "dnxcore50",
        "dotnet5.6",
        "portable-net451+win8"
      ]
    }
  },

  "runtimes": {
    "win7-x64": { }
  }
}
Kévin Chalet
  • 39,509
  • 7
  • 121
  • 131
  • 2
    That's it! Thanks! – Johannes Heesterman May 23 '16 at 14:06
  • Can you explain whether the `netcoreapp1.0` frameworks section is/is not required ? That is you have listed `System.Net.Ping` as a dependancy - could this be moved to the previously defined `dependencies` section? – wal May 23 '16 at 22:12
  • 3
    Neither of these app models produces a single .exe - I'm guessing that's only possible on the full .NET Framework? – Roman Starkov Jun 07 '16 at 08:17
  • @romkyns a single .exe? You mean without any .dll? – Kévin Chalet Jun 08 '16 at 17:04
  • @Pinpoint - great explanation. Your link to MS docs lists Linux runtimes too (e.g. debian.8-x64). Can they be built as standalone apps? – Alien Technology Sep 01 '16 at 16:05
  • I got EXE file as you said. I ran it and it says that it's listening to "localhost:5000". However when I try to enter the site, the browser says "The localhost page isn’t working. localhost is currently unable to handle this request." – JohnyL Sep 18 '16 at 18:18
  • To convert my portable app to standalone app I simply commented the `type` attribute in my dependencies - `"dependencies": { "Microsoft.NETCore.App": { //"type": "platform", "version": "1.0.1" } }`. It still worked for me. I didn't have to add `NetStandard.Library` as you have suggested. Are they equivalent? – RBT Feb 21 '17 at 09:45
13

The answer is in the documentation with complete steps now.

You can create two types of deployments for .NET Core applications:

  1. Framework-dependent deployment
  2. Self-contained deployment

For a runnable .EXE file, the Publish self-contained should be used.

zwcloud
  • 4,546
  • 3
  • 40
  • 69
9

To create a runnable application from a .NET Core console application you can use the dotnet tool. Just run in your project directory:

dotnet publish --runtime win7-x64

This creates a standalone app (self-contained deployment; includes all necessary libraries consuming at least 60MB on your disk). Of course you can also choose other runtimes, like osx.10.11-x64 or ubuntu.16.04-x64.

If you used the default configuration (New Project -> Console App (.NET Core)), there is no modification of any configuration file necessary.

Jack Miller
  • 6,843
  • 3
  • 48
  • 66
4

step 1: remove "type": "platform", from Project.json under frameworks section

step 2: add run time section to your project.json. Note each section is separeted by a comma. Add your runtime. below is just an example for win 10.

"runtimes": {
       "win10-x64": {}      
     }

Step 3: dotnet restore command on your project. ( open cmd, go to your project folder wherever src folder is there, run dotnet restor)

step 4: dotnet pack step 4: dotnet build -r win10-x64 - or just build.

Step 5: you can notice .exe created under debug/netcore/win10/

Shankar S
  • 387
  • 5
  • 13
2

In ASP.NET Core try changing your app type to default, in project.json:

"Microsoft.NETCore.App": {
  "type": "default",
  "version": "1.0.0-*"
}
Serj Sagan
  • 28,927
  • 17
  • 154
  • 183