In .NET 8, trying to build a CLI program with dotnet publish

287 views Asked by At

I’m using dotnet publish to build a CLI program called showperms. It runs, but not if I copy the executable by itself to somewhere else, such as to /usr/local/bin/. It needs one or more other files that were built along with it, even though I built it with the --sc (self contained) option. Are there some other option arguments I need to use with dotnet publish that will make this program run as a single file? Actually I would like it best as a small single file that relies on installed libraries. A complication is that the program needs a couple of NuGet packages.

Source is here.

318 Z% ll -trdc `findn showperms showperms/bin`
[ find showperms/bin -iname showperms ]
drwxrwx---  16 yost  admin  512 2023-11-15.19:45:57 .
319 Z% dotnet publish --os osx --arch x64 --sc 
MSBuild version 17.8.3+195e7f5a3 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  DiffResults -> /Users/yost/p/fsharp/showperms/DiffResults/bin/Release/net8.0/osx-x64/DiffResults.dll
  DiffResults -> /Users/yost/p/fsharp/showperms/DiffResults/bin/Release/net8.0/osx-x64/publish/
  DiffResults -> /Users/yost/p/fsharp/showperms/DiffResults/bin/Release/net8.0/DiffResults.dll
  DiffTest -> /Users/yost/p/fsharp/showperms/DiffTest/bin/Release/net8.0/osx-x64/DiffTest.dll
  DiffTest -> /Users/yost/p/fsharp/showperms/DiffTest/bin/Release/net8.0/osx-x64/publish/
  showpermsOld -> /Users/yost/p/fsharp/showperms/showpermsOld/bin/Release/net8.0/osx-x64/showpermsOld.dll
  showpermsOld -> /Users/yost/p/fsharp/showperms/showpermsOld/bin/Release/net8.0/osx-x64/publish/
  showperms -> /Users/yost/p/fsharp/showperms/showperms/bin/Release/net8.0/osx-x64/showperms.dll
  showperms -> /Users/yost/p/fsharp/showperms/showperms/bin/Release/net8.0/osx-x64/publish/
320 Z% ll -trdc `findn showperms showperms/bin`
[ find showperms/bin -iname showperms ]
-rwxr-xr-x@ 1 yost  admin  124032 2023-11-15.20:12:49 showperms/bin/Release/net8.0/osx-x64/showperms
-rwxr-xr-x@ 1 yost  admin  124032 2023-11-15.20:12:49 showperms/bin/Release/net8.0/osx-x64/publish/showperms
321 Z% showperms/bin/Release/net8.0/osx-x64/showperms testDir | head -8
drwxr-xr-x   testDir/
drwxr-xr-x   testDir/1d/
drwxr-xr-x   testDir/2d/
-rw-r--r--   testDir/2d/1f
drwxr-xr-x   testDir/2d/2d/
-rwxr-xr-x   testDir/2d/3f
----------   testDir/2d/4f
dr--------   testDir/3d/
322 Z% cp showperms/bin/Release/net8.0/osx-x64/publish/showperms /usr/local/bin
323 Z% /usr/local/bin/showperms testDir | head -8
The application to execute does not exist: '/usr/local/bin/showperms.dll'.
324 Z% 
1

There are 1 answers

0
Jivopis On

When I build .NET Core from CI/CD stuff I use:

//this will restore NUGET packages
dotnet restore .\\MyProject.csproj
//this will build and pack into zip for you
dotnet publish .\\MyProject.csproj /p:Configuration=Release /p:version=1.1.11 /p:WebPublishMethod=Package /p:PackageLocation=.\\<project package name>.zip