About creating a Snap of a Mono application


#1

I’ve written a hello world, and I’ve an .exe created using Mono

How do I create a Snap package for it ?

I have created the below snapcraft.yaml and trying to run it :

name:  test1
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: hello world
description:
 Print hello world

grade: devel 
confinement: devmode #

apps:
  test123:
    command: mono $/home/boschrexroth/Desktop/test/test1.exe
    plugs: [network-bind]
    daemon: simple

parts:
  test123:
    plugin: dump
    source: .
    source-type: local
    stage-packages:
       - mono-runtime
       - libmono-corlib4.5-cil
       - libmono-system-core4.0-cil
       - libmono-system-net-http4.0-cil
       - libmono-system-runtime4.0-cil
       - libmono-system-web-extensions4.0-cil
       - libmono-system-xml4.0-cil
       - libmono-system-web4.0-cil
       - libmono-system-web-http4.0-cil
       - libmono-system-xml-linq4.0-cil
       - libmono-microsoft-csharp4.0-cil
       - libmono-http4.0-cil
       - curlile 

but i am getting the below errors :

Sorry, an error occurred in Snapcraft:
Traceback (most recent call last):
  File "/usr/bin/snapcraft", line 9, in <module>
    load_entry_point('snapcraft==2.43.1', 'console_scripts', 'snapcraft')()
  File "/usr/lib/python3/dist-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1037, in invoke
    return Command.invoke(self, ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/lib/python3/dist-packages/snapcraft/cli/_runner.py", line 93, in run
    ctx.forward(lifecyclecli.commands["snap"])
  File "/usr/lib/python3/dist-packages/click/core.py", line 552, in forward
    return self.invoke(cmd, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/snapcraft/cli/lifecycle.py", line 136, in snap
    project = _execute(steps.PRIME, parts=[], **kwargs)
  File "/usr/lib/python3/dist-packages/snapcraft/cli/lifecycle.py", line 35, in _execute
    lifecycle.execute(step, project_config, parts)
  File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle/_runner.py", line 90, in execute
    executor.run(step, part_names)
  File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle/_runner.py", line 187, in run
    with config.CLIConfig() as cli_config:
  File "/usr/lib/python3/dist-packages/snapcraft/config.py", line 63, in __enter__
    self.load()
  File "/usr/lib/python3/dist-packages/snapcraft/config.py", line 77, in load
    with open(self.config_path) as f:
PermissionError: [Errno 13] Permission denied: '/home/boschrexroth/.config/snapcraft/cli.cfg'
We would appreciate it if you created a bug report at
https://launchpad.net/snapcraft/+filebug with the above text included.

#2

command: mono $/home/boschrexroth/Desktop/test/test1.exe
This line is wrong. Imagine the snap was installed on my computer, I’d have /home/alan not your user ID. The binary you built needs to be dumped into the snap. As such it needs to be executed from inside the snap.

command: mono $SNAP/test1.exe

Would be more likely, assuming test1.exe is your binary and is dumped into the root of your snap.


#3

thanks for your quick response.

I did the above update and i still get the same error :

Sorry, an error occurred in Snapcraft:
Traceback (most recent call last):
  File "/usr/bin/snapcraft", line 9, in <module>
    load_entry_point('snapcraft==2.43.1', 'console_scripts', 'snapcraft')()
  File "/usr/lib/python3/dist-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1037, in invoke
    return Command.invoke(self, ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/lib/python3/dist-packages/snapcraft/cli/_runner.py", line 93, in run
    ctx.forward(lifecyclecli.commands["snap"])
  File "/usr/lib/python3/dist-packages/click/core.py", line 552, in forward
    return self.invoke(cmd, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/snapcraft/cli/lifecycle.py", line 136, in snap
    project = _execute(steps.PRIME, parts=[], **kwargs)
  File "/usr/lib/python3/dist-packages/snapcraft/cli/lifecycle.py", line 35, in _execute
    lifecycle.execute(step, project_config, parts)
  File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle/_runner.py", line 90, in execute
    executor.run(step, part_names)
  File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle/_runner.py", line 187, in run
    with config.CLIConfig() as cli_config:
  File "/usr/lib/python3/dist-packages/snapcraft/config.py", line 63, in __enter__
    self.load()
  File "/usr/lib/python3/dist-packages/snapcraft/config.py", line 77, in load
    with open(self.config_path) as f:
PermissionError: [Errno 13] Permission denied: '/home/boschrexroth/.config/snapcraft/cli.cfg'
We would appreciate it if you created a bug report at
https://launchpad.net/snapcraft/+filebug with the above text included.

and now the snapcraft.yaml file is like below :

name:  test1
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: hello world program # 79 char long summary
description:
 Print hello world

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots

apps:
  test123:
    command: mono $SNAP/test1.exe
    plugs: [network-bind]
    daemon: simple

parts:
  test123:
    plugin: dump
    source: .
    source-type: local
    stage-packages:
       - mono-runtime
       - libmono-corlib4.5-cil
       - libmono-system-core4.0-cil
       - libmono-system-net-http4.0-cil
       - libmono-system-runtime4.0-cil
       - libmono-system-web-extensions4.0-cil
       - libmono-system-xml4.0-cil
       - libmono-system-web4.0-cil
       - libmono-system-web-http4.0-cil
       - libmono-system-xml-linq4.0-cil
       - libmono-microsoft-csharp4.0-cil
       - libmono-http4.0-cil
       - curl

#4

This looks odd. Did you run sudo snapcraft at some point? That file should be owned by you.

alan@KinkPad-K450:~$ ls -l ~/.config/snapcraft/cli.cfg
-rw-rw-r-- 1 alan alan 0 Jun 25 22:13 /home/alan/.config/snapcraft/cli.cfg

(also please wrap your long text output inside three backticks top and bottom to format nicely)