core icon indicating copy to clipboard operation
core copied to clipboard

How to run published console app?

Open ryanelian opened this issue 10 years ago • 46 comments

Let's say I have a hello world application named helloworld.

I ran dotnet restore then dotnet publish. This appears:

Publishing helloworld for .NETCoreApp,Version=v1.0
Project helloworld (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
publish: Published to C:\Ryan\helloworld\bin\Debug\netcoreapp1.0\publish
Published 1/1 projects successfully

In the folder I have:

helloworld.deps.json
helloworld.dll
helloworld.pdb
helloworld.runtimeconfig.json

Looks compiled to me but doesn't seem to be an exe file.

How to run this? Or is there a special compilation flag that outputs executable?

Thanks in advance!

ryanelian avatar May 16 '16 17:05 ryanelian

dotnet run path/to/helloworld.dll

Your published project looks like a portable application which does not have a native bootstrapper like a shell script or a executable.

oaiey avatar May 17 '16 08:05 oaiey

Heya. Thanks for responding but that doesn't seem to be working.

dotnet

Yeah I'm curious about that too. I wonder if there's a way to generate the console app as executable.

ryanelian avatar May 17 '16 08:05 ryanelian

You can also run dotnet . A portable app can run on any os and depends on the shared framework for the target platform being there. Currently, the way to get an executable app is to standalone and specify the target runtime ID in project.json. Remove, type: Platform from the netcore.app package reference and add a runtimes section with the right values such as win7-x64.

Petermarcu avatar May 17 '16 11:05 Petermarcu

Oh wow that worked. Thanks Peter! Managed to spit out the executable by using this project.json (for those who are wondering as well):

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },
  "dependencies": {
    "Microsoft.NETCore.App": {
      //"type": "platform",
      "version": "1.0.0-rc2-3002702"
    }
  },
  "frameworks": {
    "netcoreapp1.0": {
      "imports": "dnxcore50"
    }
  },
  "runtimes":{
    "win10-x64": { }
  }
}

Managed to dig out abit about project.json here.

You can also run dotnet

Any idea how to do that against the previously compiled helloworld.dll using the command line? I'm still curious about this one.

Also, since the .NET Core is cross-platform, can I run that helloworld.dll compiled on Windows on Linux or Mac?


EDIT

Slightly off-topic but after reading around I tried playing around and used this configuration:

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },
  "dependencies": {
    "NETStandard.Library": {
      "type": "platform",
      "version": "1.5.0-rc3-24116-00"
      //https://dotnet.myget.org/feed/dotnet-core/package/nuget/NETStandard.Library
    }
  },
  "frameworks": {
    "netstandard1.5": { }
  }
}

Then I do dotnet run. This appears:

E:\helloworld>dotnet run
Project helloworld (.NETStandard,Version=v1.5) will be compiled because inputs were modified
Compiling helloworld for .NETStandard,Version=v1.5

Compilation succeeded.
    0 Warning(s)
    0 Error(s)

Time elapsed 00:00:01.7820775


The targeted framework { 'NETStandard.Library': '1.5.0-rc3-24116-00' } was not found.
  - Check application dependencies and target a framework version installed at:
      C:\Program Files\dotnet\shared\NETStandard.Library
  - Alternatively, install the framework version '1.5.0-rc3-24116-00'.

No error but it asks me to install a framework. How to do this?

ryanelian avatar May 17 '16 18:05 ryanelian

You mean convert a previously compiled portable app into a standalone one? I don't think that's possible, at least not with the current version of the tooling

aL3891 avatar May 17 '16 19:05 aL3891

You mean convert a previously compiled portable app into a standalone one? I don't think that's possible, at least not with the current version of the tooling

Nonono, I meant running the .dll itself. I can't seem to run the compiled binary with dotnet (the command line simply says Object reference not set to an instance of an object. (See screenshot)

ryanelian avatar May 17 '16 19:05 ryanelian

I see, that should work.. if the app is compiled as portable it should run anywhere dotnet is installed. (shouldn't net a null reference error anyway) i'd file a bug on the cli repo

Regarding you edit, did you mean to run on the rc3 bits?

aL3891 avatar May 17 '16 20:05 aL3891

Regarding the edit, yes I meant to run on RC3 bits. Just pure curiosity. Do you know how to do it?

ryanelian avatar May 17 '16 21:05 ryanelian

ok :) You need to add the right myget feeds to nuget.config so for example:

<configuration>
  <packageSources>
    <add key="coreFx" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
    <add key="NuGet" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration>

or you can just add it in the vs options

Here is a sample project.json for a console app:

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

  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0-rc3-*"
    },
    "System.Runtime.CompilerServices.Unsafe": "4.0.0-rc3-*"
  },

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

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

aL3891 avatar May 18 '16 09:05 aL3891

To run a published dll- dotnet app.dll Don't use "dotnet run".

gulshan avatar May 23 '16 05:05 gulshan

To run a published dll- dotnet app.dll Don't use "dotnet run".

Oh wow. That's unexpected. Maybe someone ought to make that clearer in the docs. Thanks!

ryanelian avatar May 26 '16 11:05 ryanelian

@ryanelian, agree - it would be good if it was mentioned right in 'dotnet --help'. I spend a bit of time this morning Bing'ing how to get my console app running on OSX from the publish folder

jkristia avatar May 29 '16 18:05 jkristia

@ryanelian and @jkristia, I've created the following issue on the core-docs repo to improve discoverability of this information: https://github.com/dotnet/core-docs/issues/473

mairaw avatar May 29 '16 22:05 mairaw

can someone point me to where i can get a list of all the options for runtimes? I'm trying to publish an executable for mac os but i'm not sure what i should be putting as a value in the runtimes json field. Right now when i run publish i'm just getting a folder with the same files listed in the first comment.

mattcdavis1 avatar Jun 28 '16 13:06 mattcdavis1

@mattcdavis1 See Runtime Identifier catalog in the documentation.

svick avatar Jun 28 '16 13:06 svick

@svick - thanks! based on that article - i've created a json file that looks like this. However when i run dotnet publish i'm still not seeing a mac executable file. Am i missing something (right now the app is just a "Hello World" single line app)?

mattcdavis1 avatar Jun 28 '16 14:06 mattcdavis1

@mattcdavis1 Based on this article, you also need to remove the "type": "platform" line from your project.json.

svick avatar Jun 28 '16 14:06 svick

yep - that worked. thanks!

mattcdavis1 avatar Jun 28 '16 14:06 mattcdavis1

First off, I'd like to say thank you to you guys for all this information. It really helped me out. Secondly, however, after reading this, I felt really sad in the pit of my stomach that this is so convoluted. This seems like a real mess. It feels like we've went backwards somehow.

bitslasher avatar Jul 10 '16 01:07 bitslasher

It's not very clean. We're looking at moving to a model where you always develop portable apps but you can choose to deploy standalone at publish time.

davidfowl avatar Jul 10 '16 07:07 davidfowl