.NET CLI how to run app after publish on Linux
Asked Answered
H

1

14

I spent ~4 hours investigation and still can't find out how to run published application ( dotnet publish )

Now I can download sources to my remote machine, then call dotnet build and dotnet run - then my app runs as intended. But I want to publish just DLL's (or *.so ?) to my VPS without source files.

What official docs says? To define command in project.json

"commands": {
    "web": "Microsoft.AspNet.Server.Kestrel --server.urls http://unix:/var/aspnet/HelloMVC/kestrel.sock",
}

But it is obsolette, isn't it?

What about default samples?

In default VS2015 sample solution they use publish-iis, Full .NET framework and IIS server, but there is nothing about deployment on linux.

postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]

Here is my dotnet info

.NET Command Line Tools (1.0.0-preview1-002702)

Product Information:
 Version:     1.0.0-preview1-002702
 Commit Sha:  6cde21225e

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.10586
 OS Platform: Windows
 RID:         win10-x64

.NET Core RC2

Hoenir answered 22/5, 2016 at 16:37 Comment(2)
You need to add the RID to the project.json under a node called runtimes. And the publish for it (do not forget to remove the "type":"platform" thingy from your dependencies. dotnet.github.io/docs/core-concepts/app-types.htmlStemma
dotnet publish -r ubuntu.14.04-x64 works for me.Stemma
S
12

Do the following steps (starting from a RC2 portable application; the normal one):

  1. Remove the "type": "platform" annotation from all your dependencies (so it is actuall self-contained and no longer rely on a installed .NET Core platform).

  2. Add a node runtimes to your project.json (so NuGet is able to pull the necessary platform parts to your local machine)

    Sample:

    "runtimes": {
      "osx.10.11-x64": { },
      "win10-x64": { },
      "ubuntu.14.04-x64": { }
    }
    
  3. dotnet restore (to make sure the new runtimes are locally available).

  4. dotnet build (if not already done for the portable app)

  5. dotnet publish -r ubuntu.14.04-x64 (to bundle it up)

  6. See the result directory with a platform specific dotnet command able to run the app.

I followed the steps found in the .NET Core documentation.

Stemma answered 22/5, 2016 at 17:44 Comment(10)
Okay, now I have all these files under "publish" folder. I uploaded these files to my ubuntu server and called dotnet run command, but still no resut - I'm getting Object reference not set to an instance of an object. What am I doing wrong?Hoenir
Have you called it locally? or your shared framework installation? Not that it should make a difference.Stemma
my question was more: have you called it locally like ./dotnet run Foobar.dll or dotnet run Foobar.dll (the dot is the difference ;))Stemma
Thank you man, I did not set Foobar.dll as a param, that was the problem. Now it works. Can you please tell me why it is important to set a name of DLL, because "dotnet run" works just fine on my local dev. environmentHoenir
I think the difference is the project.json, which is locally just the element to execute, while compiled you need to be more explicit. I am a bit surprised by publish that it does not come with a shell script like before. But hey, it is preview1.Stemma
It does produce output similar to dnx, but only when the app is self-contained. If you're not seeing that in your publish output then you might still need to make some changes to your project.json to make the app self-contained instead of portable.Barham
In NET .Core Final, to run "published" DLL you need to run it with dotnet mydll.dll without run keyword, see info in official docs - learn.microsoft.com/en-us/dotnet/articles/core/tools/dotnet-runMenagerie
@DanielGrim I'm trying to do the same except to OSX. Do you know the steps or where I can find it & do I need 'ubuntu.14.04-x64' installed through nuget? On my mac, after creating a directory to save my application I just created/copied from Windows - do I need to install yoeman or anything else? Lastly, will i execute it by typing 'dotnet run' on my mac? I'm on day two trying to figure this out.Antakiya
Link to .NET Core documentation is broken.Butterworth
yes , anyone can re new the links ? page not foundGreenling

© 2022 - 2024 — McMap. All rights reserved.