.= 'tag.htm'; break; case 'flag': $pre .= $default_pre .= 'flag.htm'; break; case 'my': $pre .= $default_pre .= 'my.htm'; break; case 'my_password': $pre .= $default_pre .= 'my_password.htm'; break; case 'my_bind': $pre .= $default_pre .= 'my_bind.htm'; break; case 'my_avatar': $pre .= $default_pre .= 'my_avatar.htm'; break; case 'home_article': $pre .= $default_pre .= 'home_article.htm'; break; case 'home_comment': $pre .= $default_pre .= 'home_comment.htm'; break; case 'user': $pre .= $default_pre .= 'user.htm'; break; case 'user_login': $pre .= $default_pre .= 'user_login.htm'; break; case 'user_create': $pre .= $default_pre .= 'user_create.htm'; break; case 'user_resetpw': $pre .= $default_pre .= 'user_resetpw.htm'; break; case 'user_resetpw_complete': $pre .= $default_pre .= 'user_resetpw_complete.htm'; break; case 'user_comment': $pre .= $default_pre .= 'user_comment.htm'; break; case 'single_page': $pre .= $default_pre .= 'single_page.htm'; break; case 'search': $pre .= $default_pre .= 'search.htm'; break; case 'operate_sticky': $pre .= $default_pre .= 'operate_sticky.htm'; break; case 'operate_close': $pre .= $default_pre .= 'operate_close.htm'; break; case 'operate_delete': $pre .= $default_pre .= 'operate_delete.htm'; break; case 'operate_move': $pre .= $default_pre .= 'operate_move.htm'; break; case '404': $pre .= $default_pre .= '404.htm'; break; case 'read_404': $pre .= $default_pre .= 'read_404.htm'; break; case 'list_404': $pre .= $default_pre .= 'list_404.htm'; break; default: $pre .= $default_pre .= theme_mode_pre(); break; } if ($config['theme']) { $conffile = APP_PATH . 'view/template/' . $config['theme'] . '/conf.json'; $json = is_file($conffile) ? xn_json_decode(file_get_contents($conffile)) : array(); } !empty($json['installed']) and $path_file = APP_PATH . 'view/template/' . $config['theme'] . '/htm/' . ($id ? $id . '_' : '') . $pre; (empty($path_file) || !is_file($path_file)) and $path_file = APP_PATH . 'view/template/' . $config['theme'] . '/htm/' . $pre; if (!empty($config['theme_child']) && is_array($config['theme_child'])) { foreach ($config['theme_child'] as $theme) { if (empty($theme) || is_array($theme)) continue; $path_file = APP_PATH . 'view/template/' . $theme . '/htm/' . ($id ? $id . '_' : '') . $pre; !is_file($path_file) and $path_file = APP_PATH . 'view/template/' . $theme . '/htm/' . $pre; } } !is_file($path_file) and $path_file = APP_PATH . ($dir ? 'plugin/' . $dir . '/view/htm/' : 'view/htm/') . $default_pre; return $path_file; } function theme_mode_pre($type = 0) { global $config; $mode = $config['setting']['website_mode']; $pre = ''; if (1 == $mode) { $pre .= 2 == $type ? 'portal_category.htm' : 'portal.htm'; } elseif (2 == $mode) { $pre .= 2 == $type ? 'flat_category.htm' : 'flat.htm'; } else { $pre .= 2 == $type ? 'index_category.htm' : 'index.htm'; } return $pre; } ?>asp.net core - How to build a self-contained executable on Windows - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net core - How to build a self-contained executable on Windows - Stack Overflow

programmeradmin0浏览0评论
  1. Download the dotnet 8 SDK binaries (.0.405-windows-x64-binaries)
  2. Locate dotnet.exe (dotnet-sdk-8.0.405-win-x64\dotnet.exe)
  3. Locate the CSharp compiler (dotnet-sdk-8.0.405-win-x64\sdk\8.0.405\Roslyn\bincore\csc.dll)
  4. Write a simple single-file program and lets name it test.cs, for example.
using System;

class Program
{
    public static void Main(string[] args)
    {
        Console.WriteLine("Test");
        return;
    }
}
  1. Compile using the following script Note that assemblies are located at "packs\Microsoft.NETCore.App.Ref\8.0.8\ref\net8.0"
set sdk_dotnet=dotnet-sdk-8.0.405-win-x64\dotnet.exe
set sdk_dotnet_csc=dotnet-sdk-8.0.405-win-x64\sdk\8.0.405\Roslyn\bincore\csc.dll
%sdk_dotnet% %sdk_dotnet_csc%^
 /r:Microsoft.CSharp.dll^
 /r:Microsoft.VisualBasic.Core.dll^
 /r:Microsoft.VisualBasic.dll^
 /r:Microsoft.Win32.Primitives.dll^
 /r:Microsoft.Win32.Registry.dll^
 /r:mscorlib.dll^
 /r:netstandard.dll^
 /r:System.AppContext.dll^
 /r:System.Buffers.dll^
 /r:System.Collections.Concurrent.dll^
 /r:System.Collections.dll^
 /r:System.Collections.Immutable.dll^
 /r:System.Collections.NonGeneric.dll^
 /r:System.Collections.Specialized.dll^
 /r:System.ComponentModel.Annotations.dll^
 /r:System.ComponentModel.DataAnnotations.dll^
 /r:System.ComponentModel.dll^
 /r:System.ComponentModel.EventBasedAsync.dll^
 /r:System.ComponentModel.Primitives.dll^
 /r:System.ComponentModel.TypeConverter.dll^
 /r:System.Configuration.dll^
 /r:System.Console.dll^
 /r:System.Core.dll^
 /r:System.Data.Common.dll^
 /r:System.Data.DataSetExtensions.dll^
 /r:System.Data.dll^
 /r:System.Diagnostics.Contracts.dll^
 /r:System.Diagnostics.Debug.dll^
 /r:System.Diagnostics.DiagnosticSource.dll^
 /r:System.Diagnostics.FileVersionInfo.dll^
 /r:System.Diagnostics.Process.dll^
 /r:System.Diagnostics.StackTrace.dll^
 /r:System.Diagnostics.TextWriterTraceListener.dll^
 /r:System.Diagnostics.Tools.dll^
 /r:System.Diagnostics.TraceSource.dll^
 /r:System.Diagnostics.Tracing.dll^
 /r:System.dll^
 /r:System.Drawing.dll^
 /r:System.Drawing.Primitives.dll^
 /r:System.Dynamic.Runtime.dll^
 /r:System.Formats.Asn1.dll^
 /r:System.Formats.Tar.dll^
 /r:System.Globalization.Calendars.dll^
 /r:System.Globalization.dll^
 /r:System.Globalization.Extensions.dll^
 /r:System.IO.Compression.Brotli.dll^
 /r:System.IO.Compression.dll^
 /r:System.IO.Compression.FileSystem.dll^
 /r:System.IO.Compression.ZipFile.dll^
 /r:System.IO.dll^
 /r:System.IO.FileSystem.AccessControl.dll^
 /r:System.IO.FileSystem.dll^
 /r:System.IO.FileSystem.DriveInfo.dll^
 /r:System.IO.FileSystem.Primitives.dll^
 /r:System.IO.FileSystem.Watcher.dll^
 /r:System.IO.IsolatedStorage.dll^
 /r:System.IO.MemoryMappedFiles.dll^
 /r:System.IO.Pipes.AccessControl.dll^
 /r:System.IO.Pipes.dll^
 /r:System.IO.UnmanagedMemoryStream.dll^
 /r:System.Linq.dll^
 /r:System.Linq.Expressions.dll^
 /r:System.Linq.Parallel.dll^
 /r:System.Linq.Queryable.dll^
 /r:System.Memory.dll^
 /r:System.Net.dll^
 /r:System.Net.Http.dll^
 /r:System.Net.Http.Json.dll^
 /r:System.Net.HttpListener.dll^
 /r:System.Net.Mail.dll^
 /r:System.Net.NameResolution.dll^
 /r:System.Net.NetworkInformation.dll^
 /r:System.Net.Ping.dll^
 /r:System.Net.Primitives.dll^
 /r:System.Net.Quic.dll^
 /r:System.Net.Requests.dll^
 /r:System.Net.Security.dll^
 /r:System.Net.ServicePoint.dll^
 /r:System.Net.Sockets.dll^
 /r:System.Net.WebClient.dll^
 /r:System.Net.WebHeaderCollection.dll^
 /r:System.Net.WebProxy.dll^
 /r:System.Net.WebSockets.Client.dll^
 /r:System.Net.WebSockets.dll^
 /r:System.Numerics.dll^
 /r:System.Numerics.Vectors.dll^
 /r:System.ObjectModel.dll^
 /r:System.Reflection.DispatchProxy.dll^
 /r:System.Reflection.dll^
 /r:System.Reflection.Emit.dll^
 /r:System.Reflection.Emit.ILGeneration.dll^
 /r:System.Reflection.Emit.Lightweight.dll^
 /r:System.Reflection.Extensions.dll^
 /r:System.Reflection.Metadata.dll^
 /r:System.Reflection.Primitives.dll^
 /r:System.Reflection.TypeExtensions.dll^
 /r:System.Resources.Reader.dll^
 /r:System.Resources.ResourceManager.dll^
 /r:System.Resources.Writer.dll^
 /r:System.Runtime.CompilerServices.Unsafe.dll^
 /r:System.Runtime.CompilerServices.VisualC.dll^
 /r:System.Runtime.dll^
 /r:System.Runtime.Extensions.dll^
 /r:System.Runtime.Handles.dll^
 /r:System.Runtime.InteropServices.dll^
 /r:System.Runtime.InteropServices.JavaScript.dll^
 /r:System.Runtime.InteropServices.RuntimeInformation.dll^
 /r:System.Runtime.Intrinsics.dll^
 /r:System.Runtime.Loader.dll^
 /r:System.Runtime.Numerics.dll^
 /r:System.Runtime.Serialization.dll^
 /r:System.Runtime.Serialization.Formatters.dll^
 /r:System.Runtime.Serialization.Json.dll^
 /r:System.Runtime.Serialization.Primitives.dll^
 /r:System.Runtime.Serialization.Xml.dll^
 /r:System.Security.AccessControl.dll^
 /r:System.Security.Claims.dll^
 /r:System.Security.Cryptography.Algorithms.dll^
 /r:System.Security.Cryptography.Cng.dll^
 /r:System.Security.Cryptography.Csp.dll^
 /r:System.Security.Cryptography.dll^
 /r:System.Security.Cryptography.Encoding.dll^
 /r:System.Security.Cryptography.OpenSsl.dll^
 /r:System.Security.Cryptography.Primitives.dll^
 /r:System.Security.Cryptography.X509Certificates.dll^
 /r:System.Security.dll^
 /r:System.Security.Principal.dll^
 /r:System.Security.Principal.Windows.dll^
 /r:System.Security.SecureString.dll^
 /r:System.ServiceModel.Web.dll^
 /r:System.ServiceProcess.dll^
 /r:System.Text.Encoding.CodePages.dll^
 /r:System.Text.Encoding.dll^
 /r:System.Text.Encoding.Extensions.dll^
 /r:System.Text.Encodings.Web.dll^
 /r:System.Text.Json.dll^
 /r:System.Text.RegularExpressions.dll^
 /r:System.Threading.Channels.dll^
 /r:System.Threading.dll^
 /r:System.Threading.Overlapped.dll^
 /r:System.Threading.Tasks.Dataflow.dll^
 /r:System.Threading.Tasks.dll^
 /r:System.Threading.Tasks.Extensions.dll^
 /r:System.Threading.Tasks.Parallel.dll^
 /r:System.Threading.Thread.dll^
 /r:System.Threading.ThreadPool.dll^
 /r:System.Threading.Timer.dll^
 /r:System.Transactions.dll^
 /r:System.Transactions.Local.dll^
 /r:System.ValueTuple.dll^
 /r:System.Web.dll^
 /r:System.Web.HttpUtility.dll^
 /r:System.Windows.dll^
 /r:System.Xml.dll^
 /r:System.Xml.Linq.dll^
 /r:System.Xml.ReaderWriter.dll^
 /r:System.Xml.Serialization.dll^
 /r:System.Xml.XDocument.dll^
 /r:System.Xml.XmlDocument.dll^
 /r:System.Xml.XmlSerializer.dll^
 /r:System.Xml.XPath.dll^
 /r:System.Xml.XPath.XDocument.dll^
 /r:WindowsBase.dll^
 test.cs

Running test.exe does not run the application and returns an exception.

I've found out that compiling the program will not produce a 'self-contained' app. (an app that has the dotnet runtime embedded into it or inside the same directory). Is there a missing step that will make the application use the SDK residing inside the same directory? Please also note that I copied mscorlib.dll and others into the same directory but an exception is thrown complaining about System.Runtime.dll

Thank you.

  1. Download the dotnet 8 SDK binaries (https://dotnet.microsoft/en-us/download/dotnet/thank-you/sdk-8.0.405-windows-x64-binaries)
  2. Locate dotnet.exe (dotnet-sdk-8.0.405-win-x64\dotnet.exe)
  3. Locate the CSharp compiler (dotnet-sdk-8.0.405-win-x64\sdk\8.0.405\Roslyn\bincore\csc.dll)
  4. Write a simple single-file program and lets name it test.cs, for example.
using System;

class Program
{
    public static void Main(string[] args)
    {
        Console.WriteLine("Test");
        return;
    }
}
  1. Compile using the following script Note that assemblies are located at "packs\Microsoft.NETCore.App.Ref\8.0.8\ref\net8.0"
set sdk_dotnet=dotnet-sdk-8.0.405-win-x64\dotnet.exe
set sdk_dotnet_csc=dotnet-sdk-8.0.405-win-x64\sdk\8.0.405\Roslyn\bincore\csc.dll
%sdk_dotnet% %sdk_dotnet_csc%^
 /r:Microsoft.CSharp.dll^
 /r:Microsoft.VisualBasic.Core.dll^
 /r:Microsoft.VisualBasic.dll^
 /r:Microsoft.Win32.Primitives.dll^
 /r:Microsoft.Win32.Registry.dll^
 /r:mscorlib.dll^
 /r:netstandard.dll^
 /r:System.AppContext.dll^
 /r:System.Buffers.dll^
 /r:System.Collections.Concurrent.dll^
 /r:System.Collections.dll^
 /r:System.Collections.Immutable.dll^
 /r:System.Collections.NonGeneric.dll^
 /r:System.Collections.Specialized.dll^
 /r:System.ComponentModel.Annotations.dll^
 /r:System.ComponentModel.DataAnnotations.dll^
 /r:System.ComponentModel.dll^
 /r:System.ComponentModel.EventBasedAsync.dll^
 /r:System.ComponentModel.Primitives.dll^
 /r:System.ComponentModel.TypeConverter.dll^
 /r:System.Configuration.dll^
 /r:System.Console.dll^
 /r:System.Core.dll^
 /r:System.Data.Common.dll^
 /r:System.Data.DataSetExtensions.dll^
 /r:System.Data.dll^
 /r:System.Diagnostics.Contracts.dll^
 /r:System.Diagnostics.Debug.dll^
 /r:System.Diagnostics.DiagnosticSource.dll^
 /r:System.Diagnostics.FileVersionInfo.dll^
 /r:System.Diagnostics.Process.dll^
 /r:System.Diagnostics.StackTrace.dll^
 /r:System.Diagnostics.TextWriterTraceListener.dll^
 /r:System.Diagnostics.Tools.dll^
 /r:System.Diagnostics.TraceSource.dll^
 /r:System.Diagnostics.Tracing.dll^
 /r:System.dll^
 /r:System.Drawing.dll^
 /r:System.Drawing.Primitives.dll^
 /r:System.Dynamic.Runtime.dll^
 /r:System.Formats.Asn1.dll^
 /r:System.Formats.Tar.dll^
 /r:System.Globalization.Calendars.dll^
 /r:System.Globalization.dll^
 /r:System.Globalization.Extensions.dll^
 /r:System.IO.Compression.Brotli.dll^
 /r:System.IO.Compression.dll^
 /r:System.IO.Compression.FileSystem.dll^
 /r:System.IO.Compression.ZipFile.dll^
 /r:System.IO.dll^
 /r:System.IO.FileSystem.AccessControl.dll^
 /r:System.IO.FileSystem.dll^
 /r:System.IO.FileSystem.DriveInfo.dll^
 /r:System.IO.FileSystem.Primitives.dll^
 /r:System.IO.FileSystem.Watcher.dll^
 /r:System.IO.IsolatedStorage.dll^
 /r:System.IO.MemoryMappedFiles.dll^
 /r:System.IO.Pipes.AccessControl.dll^
 /r:System.IO.Pipes.dll^
 /r:System.IO.UnmanagedMemoryStream.dll^
 /r:System.Linq.dll^
 /r:System.Linq.Expressions.dll^
 /r:System.Linq.Parallel.dll^
 /r:System.Linq.Queryable.dll^
 /r:System.Memory.dll^
 /r:System.Net.dll^
 /r:System.Net.Http.dll^
 /r:System.Net.Http.Json.dll^
 /r:System.Net.HttpListener.dll^
 /r:System.Net.Mail.dll^
 /r:System.Net.NameResolution.dll^
 /r:System.Net.NetworkInformation.dll^
 /r:System.Net.Ping.dll^
 /r:System.Net.Primitives.dll^
 /r:System.Net.Quic.dll^
 /r:System.Net.Requests.dll^
 /r:System.Net.Security.dll^
 /r:System.Net.ServicePoint.dll^
 /r:System.Net.Sockets.dll^
 /r:System.Net.WebClient.dll^
 /r:System.Net.WebHeaderCollection.dll^
 /r:System.Net.WebProxy.dll^
 /r:System.Net.WebSockets.Client.dll^
 /r:System.Net.WebSockets.dll^
 /r:System.Numerics.dll^
 /r:System.Numerics.Vectors.dll^
 /r:System.ObjectModel.dll^
 /r:System.Reflection.DispatchProxy.dll^
 /r:System.Reflection.dll^
 /r:System.Reflection.Emit.dll^
 /r:System.Reflection.Emit.ILGeneration.dll^
 /r:System.Reflection.Emit.Lightweight.dll^
 /r:System.Reflection.Extensions.dll^
 /r:System.Reflection.Metadata.dll^
 /r:System.Reflection.Primitives.dll^
 /r:System.Reflection.TypeExtensions.dll^
 /r:System.Resources.Reader.dll^
 /r:System.Resources.ResourceManager.dll^
 /r:System.Resources.Writer.dll^
 /r:System.Runtime.CompilerServices.Unsafe.dll^
 /r:System.Runtime.CompilerServices.VisualC.dll^
 /r:System.Runtime.dll^
 /r:System.Runtime.Extensions.dll^
 /r:System.Runtime.Handles.dll^
 /r:System.Runtime.InteropServices.dll^
 /r:System.Runtime.InteropServices.JavaScript.dll^
 /r:System.Runtime.InteropServices.RuntimeInformation.dll^
 /r:System.Runtime.Intrinsics.dll^
 /r:System.Runtime.Loader.dll^
 /r:System.Runtime.Numerics.dll^
 /r:System.Runtime.Serialization.dll^
 /r:System.Runtime.Serialization.Formatters.dll^
 /r:System.Runtime.Serialization.Json.dll^
 /r:System.Runtime.Serialization.Primitives.dll^
 /r:System.Runtime.Serialization.Xml.dll^
 /r:System.Security.AccessControl.dll^
 /r:System.Security.Claims.dll^
 /r:System.Security.Cryptography.Algorithms.dll^
 /r:System.Security.Cryptography.Cng.dll^
 /r:System.Security.Cryptography.Csp.dll^
 /r:System.Security.Cryptography.dll^
 /r:System.Security.Cryptography.Encoding.dll^
 /r:System.Security.Cryptography.OpenSsl.dll^
 /r:System.Security.Cryptography.Primitives.dll^
 /r:System.Security.Cryptography.X509Certificates.dll^
 /r:System.Security.dll^
 /r:System.Security.Principal.dll^
 /r:System.Security.Principal.Windows.dll^
 /r:System.Security.SecureString.dll^
 /r:System.ServiceModel.Web.dll^
 /r:System.ServiceProcess.dll^
 /r:System.Text.Encoding.CodePages.dll^
 /r:System.Text.Encoding.dll^
 /r:System.Text.Encoding.Extensions.dll^
 /r:System.Text.Encodings.Web.dll^
 /r:System.Text.Json.dll^
 /r:System.Text.RegularExpressions.dll^
 /r:System.Threading.Channels.dll^
 /r:System.Threading.dll^
 /r:System.Threading.Overlapped.dll^
 /r:System.Threading.Tasks.Dataflow.dll^
 /r:System.Threading.Tasks.dll^
 /r:System.Threading.Tasks.Extensions.dll^
 /r:System.Threading.Tasks.Parallel.dll^
 /r:System.Threading.Thread.dll^
 /r:System.Threading.ThreadPool.dll^
 /r:System.Threading.Timer.dll^
 /r:System.Transactions.dll^
 /r:System.Transactions.Local.dll^
 /r:System.ValueTuple.dll^
 /r:System.Web.dll^
 /r:System.Web.HttpUtility.dll^
 /r:System.Windows.dll^
 /r:System.Xml.dll^
 /r:System.Xml.Linq.dll^
 /r:System.Xml.ReaderWriter.dll^
 /r:System.Xml.Serialization.dll^
 /r:System.Xml.XDocument.dll^
 /r:System.Xml.XmlDocument.dll^
 /r:System.Xml.XmlSerializer.dll^
 /r:System.Xml.XPath.dll^
 /r:System.Xml.XPath.XDocument.dll^
 /r:WindowsBase.dll^
 test.cs

Running test.exe does not run the application and returns an exception.

I've found out that compiling the program will not produce a 'self-contained' app. (an app that has the dotnet runtime embedded into it or inside the same directory). Is there a missing step that will make the application use the SDK residing inside the same directory? Please also note that I copied mscorlib.dll and others into the same directory but an exception is thrown complaining about System.Runtime.dll

Thank you.

Share Improve this question edited Jan 31 at 6:35 DarkBee 15.6k8 gold badges72 silver badges117 bronze badges asked Jan 30 at 13:10 NiebieskiNiebieski 113 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

how to build a self-contained executable on Windows

We use dotnet publish command to publish a self-contained application. You can run command like below in the directory of the root folder of the project. -r is used to set the target runtime and -o is used to define where the app is published to. You can use -f to set the target framework version e.g. -f net8.0, more options can be seen here.

dotnet publish -r win-x64 --self-contained true -o C:\Publish

What you used CSharp compiler csc.dll is used for compiling C# source code into common intermediate language(CIL) code. It can produces .dll or .exe file but it doesn't produce a fully standalone executable file which includes the .NET runtime. Compilation is just one step in the process of creating a runnable application and this is why I introduce dotnet publish command here.

发布评论

评论列表(0)

  1. 暂无评论