Search code examples
c#command-line-interface.net-coreself-contained

Trouble building self contained .NetCore App


So I am trying to build a self contained .NetCore App, just a simple default hello world one.

I followed Scott Hanselman's example on how to create the app after googling for answers.

So I have this code in my project.json

{
  "version": "1.0.0-*",
  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true
  },
  "dependencies": {},
  "frameworks": {
    "netcoreapp1.1": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          //"type": "platform",
          "version": "1.1.0"
        }
      },
      "imports": "dnxcore50",
      "runtimes": {
        "win10-x64": {},
        "osx.10.10-x64": {},
        "ubuntu.14.04-x64": {}
      }
    }
  }
}

As you can see I have commented out the type line and added the runtimes for each platform.

But I keep getting this error:

Can not find runtime target for framework '.NETCoreApp,Version=v1.1' compatible with one of the targe
t runtimes: 'osx.10.10-x64'. Possible causes:
1. The project has not been restored or restore failed - run `dotnet restore`
2. The project does not list one of 'osx.10.10-x64' in the 'runtimes' section.
3. You may be trying to publish a library, which is not supported. Use `dotnet pack` to distribute li
braries.

Now I am running this on a Mac, but the same error happens on ubuntu but then reports error relating it to ubuntu.

My dotNet version is = 1.0.0-preview2-1-003177

I am a bit stuck, everything seems to point to the fact it should work and it is probably an obvious thing I am overlooking.

Any help is appreciated.


Solution

  • I think you need change the structure of your json to:

    {
        "version": "1.0.0-*",
        "buildOptions": {
            "debugType": "portable",
            "emitEntryPoint": true
        },
        "dependencies": {},
        "frameworks": {
            "netcoreapp1.1": {
                "dependencies": {
                    "Microsoft.NETCore.App": {
                        "version": "1.1.0"
                    }
                 }
             }
        },
        "runtimes": {
            "win10-x64": {},
            "osx.10.10-x64": {},
            "ubuntu.14.04-x64": {}
        }
    }
    

    Big difference is that the runtimes section is not within the framework section.

    Be sure to run a dotnet restore --no-cache after you changed your project.json.

    You can find more information on Self contained deployment (SCD) on this page and with this excellent answer