Snap a dotnet application by using the binaries from using "dotnet publish" command

I have created and published a dotnet web app using the below commands :slight_smile:

dotnet new webapi dotnet restore dotnet build dotnet run dotnet publish

and the published files are as below :

and now how to snap the dotnet app using only the published binaries ?.

I would need to do this way, because the developers team from my project gives me only the published binaries in my project and i need to snap it.

i have tried using the below snapcraft.yaml file :

name: secondwebapi
version: '0.1'
summary: A simple example snap for dotnet in snaps
description: A simple example snap for dotnet in snaps

grade: devel 
confinement: strict 

base: core

apps:
  test1:
    command: secondwebapi

parts:
  test1:
    source: .
    plugin: dotnet

and its not working. Can someone help me with this ?

You should use the dump plugin instead… plugins are meant to drive the build process for the content under source, considering that you have already built the assets, you just need to dump them.

1 Like

Thank you for your response.

I tried using dump plugin as below :

name: secondwebapi
version: '0.1'
summary: A simple example snap for dotnet in snaps
description: A simple example snap for dotnet in snaps

grade: devel 
confinement: strict 

base: core

apps:
  test1:
    command: dotnet secondwebapi

parts:
  test1:
    source: .
    plugin: dump

Then i get the below error :

i am doing some mistake while giving the command to execute i think …or is it something else . can you please guide me with this ?

Ah, I assumed this was using --self-contained with dotnet publish.

Some things to try, if you need the runtime,:

  • Add stage-snaps: [dotnet-runtime-22] and use the dotnet command provided there.
  • Download the runtime from dotnet upstream
  • A little more involved, use the content interface to use the dotnet snap at runtime to provide the runtime for your app.
1 Like

Thanks for all the tips.

I tried this. Looking at an other example on the forum.

name: snaptest
version: '0.1'
summary: A simple example snap for dotnet in snaps
description: A simple example snap for dotnet in snaps

grade: devel 
confinement: strict 

base: core

apps:
  test1:
    command: SnapTest
    environment:
        DOTNET_ROOT : $SNAP/dnet

plugs:
    dotnet-runtime:
      content: dotnet-runtime-22
      interface : content
      default-provider: dotnet-runtime-22
      target: $SNAP/dnet

parts:
  test1:
    source: publish
    plugin: dump
    stage-packages:
        - libasn1-8-heimdal
        - libcurl3
        - libgssapi3-heimdal
        - libhcrypto4-heimdal
        - libheimbase1-heimdal
        - libheimntlm0-heimdal
        - libhx509-5-heimdal
        - libkrb5-26-heimdal
        - libldap-2.4-2
        - liblttng-ust0
        - libroken18-heimdal
        - librtmp1
        - libsasl2-2
        - libunwind8
        - liburcu4
        - libwind0-heimdal
        - icu-devtools
        - wget
        - zlib1g

and now i get the below error :

Did you run “snap connect” to connect the interface?

1 Like

nope havent tried it. I will try and keep you posted on this.