NetBeauty2 icon indicating copy to clipboard operation
NetBeauty2 copied to clipboard

How do I package the dotnet runtime with my apps?

Open ferenc-a opened this issue 1 year ago • 14 comments

I've been following this example: https://github.com/nulastudio/NetBeauty2?tab=readme-ov-file#customize-apphost. I thought the "shared runtime" meant that somehow the dotnet runtime is packaged by NetBeauty, but that doesn't seem to be the case. I also want to package a single instance of ASP.NET Core Runtime with my app set, that all apps would find, and doesn't need to be installed. Can I achieve this with NetBeauty?

ferenc-a avatar Jan 08 '25 15:01 ferenc-a

you should use the self-contained deployment mode with shared runtime enabled

liesauer avatar Jan 10 '25 06:01 liesauer

check this example, https://github.com/nulastudio/NetBeauty2/tree/master/NetBeautyTest

liesauer avatar Jan 10 '25 06:01 liesauer

It works, thanks! I have an issue though: if I ony specify --self-contained on publish, not on build, the app fails to run with No frameworks were found..., as if there were no framework at all. The difference between the two published folders (one with --self-contained build, one without) is only in the runtimeconfig.json and the main dll, all else is the same, the runtime is also present in both cases.

I want only my publish to be self-contained, not my whole build, so that I don't have a separate instance of the runtime for each app at every CI build step, only on publish.

ferenc-a avatar Jan 10 '25 11:01 ferenc-a

Could you help me solve this, so I won't need to add --self-contained to builds too?

ferenc-a avatar Jan 17 '25 08:01 ferenc-a

typically, we should turn off NetBeauty when on build

<BeautyOnPublishOnly>True</BeautyOnPublishOnly>

liesauer avatar Jan 19 '25 10:01 liesauer

I already have that set. That's not the issue.

My problem is when I build without --self-contained, then publish with --self-contained, the app fails at launch. I could add --self-contained to both build and publish to fix this. But I want to avoid that, because I build often and this makes builds take up more space and slower. NetBeauty copies basically all the right files in the first scenario too (no --self-contained for build), but it gets something wrong and the app fails at launch.

(By build and publish, I mean running dotnet build and dotnet publish specifically).

ferenc-a avatar Jan 20 '25 07:01 ferenc-a

did you run the command via cmd/powershell or using the visual studio? this shouldn't happen, unless the dotnet reuses the built files.

liesauer avatar Jan 20 '25 07:01 liesauer

can you provide a demo so i can have a deep look on it.

liesauer avatar Jan 20 '25 07:01 liesauer

I ran it in a shell. It does reuse build files, I also pass --no-build to publish. Is that not supported?

ferenc-a avatar Jan 20 '25 08:01 ferenc-a

i can't tell, but build without --self-contained, and then publish with --self-contained, there must be something different and this behaivor has changes to break NetBeauty, have you try deleting obj and bin before publishing the app?

liesauer avatar Jan 20 '25 08:01 liesauer

What do you want me to do exactly? I tried this:

  1. build without --self-contained
  2. delete the obj directory
  3. publish with --self-contained and with --no-build

But my publish just failed: error NETSDK1004: Assets file ...\obj\project.assets.json' not found. Run a NuGet package restore to generate this file. I haven't tried deleting the object dir before, but I did all my previous bug repros with clean obj and bin directories.

ferenc-a avatar Jan 20 '25 08:01 ferenc-a

try deleting obj and bin before running dotnet publish

liesauer avatar Jan 20 '25 10:01 liesauer

If I delete the obj and bin directory and add --no-build to publish, it just fails with the error I said. I tried what you said, does not work.

If I don't add --no-build it works fine. I ask again, is --no-build not supported?

ferenc-a avatar Jan 20 '25 11:01 ferenc-a

you are right, --no-build is unsupported

liesauer avatar Jan 20 '25 12:01 liesauer