หมายเหตุ
การเข้าถึงหน้านี้ต้องได้รับการอนุญาต คุณสามารถลอง ลงชื่อเข้าใช้หรือเปลี่ยนไดเรกทอรีได้
การเข้าถึงหน้านี้ต้องได้รับการอนุญาต คุณสามารถลองเปลี่ยนไดเรกทอรีได้
Multiple APIs related to an assembly's file location have behavior changes when they're invoked in a single-file publishing format.
Change description
In single-file publishing for .NET 5 and later versions, bundled assemblies are loaded from memory instead of extracted to disk. For single-file published apps, this means that certain location-related APIs return different values on .NET 5 and later than on previous versions of .NET. The changes are as follows:
| API | Previous versions | .NET 5 and later |
|---|---|---|
| Assembly.Location | Returns extracted DLL file path | Returns empty string for bundled assemblies |
| Assembly.CodeBase | Returns extracted DLL file path | Throws exception for bundled assemblies |
| Assembly.GetFile(String) | Returns null for bundled assemblies |
Throws exception for bundled assemblies |
Environment.GetCommandLineArgs()[0] |
Value is the name of the entry point DLL | Value is the name of the host executable |
| AppContext.BaseDirectory | Value is the temporary extraction directory | Value is the containing directory of the host executable |
Version introduced
5.0
Recommended action
Avoid dependencies on the file location of assemblies when publishing as a single file.