项目配置
Project.csproj1 2 3 4 5 6 7 8 9
| <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <AllowUnsafeBlocks>True</AllowUnsafeBlocks> <PublishAot>true</PublishAot> </PropertyGroup> </Project>
|
入口点
Tips: 入口可以是随意文件、类和方法名,但是"EntryPoint"必须设置为"DllMain"
Program.cs1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| using System.Runtime.InteropServices;
namespace Test { public static partial class Program { [UnmanagedCallersOnly(EntryPoint = "DllMain")] #pragma warning disable IDE0060 public static bool DllMain(IntPtr hModule, uint ul_reason_for_call, IntPtr lpReserved) #pragma warning restore IDE0060 { switch (ul_reason_for_call) { case 1: break;
case 0: break;
case 2: break;
case 3: break;
} return true; } } }
|
发布文件
Properties/PublishProfiles/publish.pubxml1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <?xml version="1.0" encoding="utf-8"?> <Project> <PropertyGroup> <Configuration>Debug</Configuration> <Platform>Any CPU</Platform> <PublishDir>bin\publish</PublishDir> <PublishProtocol>FileSystem</PublishProtocol> <_TargetId>Folder</_TargetId> <TargetFramework>net8.0</TargetFramework> <RuntimeIdentifier>win-x64</RuntimeIdentifier> <SelfContained>false</SelfContained> <PublishSingleFile>false</PublishSingleFile> <PublishReadyToRun>true</PublishReadyToRun> </PropertyGroup> </Project>
|