我无法将我的应用程序编译为单个可执行文件

问题描述 投票:0回答:1

我正在尝试将我的 C# 应用程序编译为单文件可执行文件。我可以编译它,但是如果我将可执行文件移动到除构建文件夹之外的任何其他位置,它就无法启动并显示错误。

我按照谷歌搜索到的所有提示进行操作。现在我的

.csproj
文件如下所示:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <PublishSingleFile>true</PublishSingleFile>
    <SelfContained>true</SelfContained>
    <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
    <PublishTrimmed>true</PublishTrimmed>
    <RuntimeIdentifier>linux-x64</RuntimeIdentifier>
  </PropertyGroup>

</Project>

编译命令如下所示:

dotnet publish -c Release -p:PublishReadyToRun=true

然后我就可以开始了

rpr@latita:~/MyApp$ ./bin/Release/net8.0/linux-x64/MyApp 
Hello, World!

但是,如果我使用命令

cp ./bin/Release/net8.0/linux-x64/MyApp ~/MyAppExecutable
复制此文件,然后使用命令
~/MyAppExecutable
启动它,则会显示以下错误:

要执行的应用程序不存在:“/home/rpr/MyApp.dll”。

如何修复丢失的 DLL 错误并制作单文件可执行文件?

这是发布目录的内容(

/home/rpr/MyApp/bin/Release/net8.0/linux-x64/
):

/home/rpr/MyApp/bin/Release/net8.0/linux-x64
├── createdump
├── libclrgc.so
├── libclrjit.so
├── libcoreclr.so
├── libcoreclrtraceptprovider.so
├── libhostfxr.so
├── libhostpolicy.so
├── libmscordaccore.so
├── libmscordbi.so
├── libSystem.Globalization.Native.so
├── libSystem.IO.Compression.Native.so
├── libSystem.Native.so
├── libSystem.Net.Security.Native.so
├── libSystem.Security.Cryptography.Native.OpenSsl.so
├── Microsoft.CSharp.dll
├── Microsoft.VisualBasic.Core.dll
├── Microsoft.VisualBasic.dll
├── Microsoft.Win32.Primitives.dll
├── Microsoft.Win32.Registry.dll
├── mscorlib.dll
├── MyApp
├── MyApp.deps.json
├── MyApp.dll
├── MyApp.pdb
├── MyApp.runtimeconfig.json
├── netstandard.dll
├── publish
│   ├── MyApp
│   └── MyApp.pdb
├── System.AppContext.dll
├── System.Buffers.dll
├── System.Collections.Concurrent.dll
├── System.Collections.dll
├── System.Collections.Immutable.dll
├── System.Collections.NonGeneric.dll
├── System.Collections.Specialized.dll
├── System.ComponentModel.Annotations.dll
├── System.ComponentModel.DataAnnotations.dll
├── System.ComponentModel.dll
├── System.ComponentModel.EventBasedAsync.dll
├── System.ComponentModel.Primitives.dll
├── System.ComponentModel.TypeConverter.dll
├── System.Configuration.dll
├── System.Console.dll
├── System.Core.dll
├── System.Data.Common.dll
├── System.Data.DataSetExtensions.dll
├── System.Data.dll
├── System.Diagnostics.Contracts.dll
├── System.Diagnostics.Debug.dll
├── System.Diagnostics.DiagnosticSource.dll
├── System.Diagnostics.FileVersionInfo.dll
├── System.Diagnostics.Process.dll
├── System.Diagnostics.StackTrace.dll
├── System.Diagnostics.TextWriterTraceListener.dll
├── System.Diagnostics.Tools.dll
├── System.Diagnostics.TraceSource.dll
├── System.Diagnostics.Tracing.dll
├── System.dll
├── System.Drawing.dll
├── System.Drawing.Primitives.dll
├── System.Dynamic.Runtime.dll
├── System.Formats.Asn1.dll
├── System.Formats.Tar.dll
├── System.Globalization.Calendars.dll
├── System.Globalization.dll
├── System.Globalization.Extensions.dll
├── System.IO.Compression.Brotli.dll
├── System.IO.Compression.dll
├── System.IO.Compression.FileSystem.dll
├── System.IO.Compression.ZipFile.dll
├── System.IO.dll
├── System.IO.FileSystem.AccessControl.dll
├── System.IO.FileSystem.dll
├── System.IO.FileSystem.DriveInfo.dll
├── System.IO.FileSystem.Primitives.dll
├── System.IO.FileSystem.Watcher.dll
├── System.IO.IsolatedStorage.dll
├── System.IO.MemoryMappedFiles.dll
├── System.IO.Pipes.AccessControl.dll
├── System.IO.Pipes.dll
├── System.IO.UnmanagedMemoryStream.dll
├── System.Linq.dll
├── System.Linq.Expressions.dll
├── System.Linq.Parallel.dll
├── System.Linq.Queryable.dll
├── System.Memory.dll
├── System.Net.dll
├── System.Net.Http.dll
├── System.Net.Http.Json.dll
├── System.Net.HttpListener.dll
├── System.Net.Mail.dll
├── System.Net.NameResolution.dll
├── System.Net.NetworkInformation.dll
├── System.Net.Ping.dll
├── System.Net.Primitives.dll
├── System.Net.Quic.dll
├── System.Net.Requests.dll
├── System.Net.Security.dll
├── System.Net.ServicePoint.dll
├── System.Net.Sockets.dll
├── System.Net.WebClient.dll
├── System.Net.WebHeaderCollection.dll
├── System.Net.WebProxy.dll
├── System.Net.WebSockets.Client.dll
├── System.Net.WebSockets.dll
├── System.Numerics.dll
├── System.Numerics.Vectors.dll
├── System.ObjectModel.dll
├── System.Private.CoreLib.dll
├── System.Private.DataContractSerialization.dll
├── System.Private.Uri.dll
├── System.Private.Xml.dll
├── System.Private.Xml.Linq.dll
├── System.Reflection.DispatchProxy.dll
├── System.Reflection.dll
├── System.Reflection.Emit.dll
├── System.Reflection.Emit.ILGeneration.dll
├── System.Reflection.Emit.Lightweight.dll
├── System.Reflection.Extensions.dll
├── System.Reflection.Metadata.dll
├── System.Reflection.Primitives.dll
├── System.Reflection.TypeExtensions.dll
├── System.Resources.Reader.dll
├── System.Resources.ResourceManager.dll
├── System.Resources.Writer.dll
├── System.Runtime.CompilerServices.Unsafe.dll
├── System.Runtime.CompilerServices.VisualC.dll
├── System.Runtime.dll
├── System.Runtime.Extensions.dll
├── System.Runtime.Handles.dll
├── System.Runtime.InteropServices.dll
├── System.Runtime.InteropServices.JavaScript.dll
├── System.Runtime.InteropServices.RuntimeInformation.dll
├── System.Runtime.Intrinsics.dll
├── System.Runtime.Loader.dll
├── System.Runtime.Numerics.dll
├── System.Runtime.Serialization.dll
├── System.Runtime.Serialization.Formatters.dll
├── System.Runtime.Serialization.Json.dll
├── System.Runtime.Serialization.Primitives.dll
├── System.Runtime.Serialization.Xml.dll
├── System.Security.AccessControl.dll
├── System.Security.Claims.dll
├── System.Security.Cryptography.Algorithms.dll
├── System.Security.Cryptography.Cng.dll
├── System.Security.Cryptography.Csp.dll
├── System.Security.Cryptography.dll
├── System.Security.Cryptography.Encoding.dll
├── System.Security.Cryptography.OpenSsl.dll
├── System.Security.Cryptography.Primitives.dll
├── System.Security.Cryptography.X509Certificates.dll
├── System.Security.dll
├── System.Security.Principal.dll
├── System.Security.Principal.Windows.dll
├── System.Security.SecureString.dll
├── System.ServiceModel.Web.dll
├── System.ServiceProcess.dll
├── System.Text.Encoding.CodePages.dll
├── System.Text.Encoding.dll
├── System.Text.Encoding.Extensions.dll
├── System.Text.Encodings.Web.dll
├── System.Text.Json.dll
├── System.Text.RegularExpressions.dll
├── System.Threading.Channels.dll
├── System.Threading.dll
├── System.Threading.Overlapped.dll
├── System.Threading.Tasks.Dataflow.dll
├── System.Threading.Tasks.dll
├── System.Threading.Tasks.Extensions.dll
├── System.Threading.Tasks.Parallel.dll
├── System.Threading.Thread.dll
├── System.Threading.ThreadPool.dll
├── System.Threading.Timer.dll
├── System.Transactions.dll
├── System.Transactions.Local.dll
├── System.ValueTuple.dll
├── System.Web.dll
├── System.Web.HttpUtility.dll
├── System.Windows.dll
├── System.Xml.dll
├── System.Xml.Linq.dll
├── System.Xml.ReaderWriter.dll
├── System.Xml.Serialization.dll
├── System.Xml.XDocument.dll
├── System.Xml.XmlDocument.dll
├── System.Xml.XmlSerializer.dll
├── System.Xml.XPath.dll
├── System.Xml.XPath.XDocument.dll
└── WindowsBase.dll
c# compilation .net-8.0 dotnet-cli
1个回答
0
投票

看起来问题是我使用了文件

./bin/Release/net8.0/linux-x64/MyApp
来共享。现在我使用文件
./bin/Release/net8.0/linux-x64/publish/MyApp
publish
添加在路径内)进行共享,问题就消失了。

© www.soinside.com 2019 - 2024. All rights reserved.