paint-brush
Чӣ гуна хатогиҳои "hostpolicy.dll" ва "singlefilehost.exe" -ро дар .NET 8.0.11 бартараф кардан мумкин астаз ҷониби@markpelf
Таърихи нав

Чӣ гуна хатогиҳои "hostpolicy.dll" ва "singlefilehost.exe" -ро дар .NET 8.0.11 бартараф кардан мумкин аст

аз ҷониби Mark Pelf5m2025/01/03
Read on Terminal Reader

Хеле дароз; Хондан

Пас аз навсозӣ ба .NET 8.0.11, ман ба хатогиҳо шурӯъ кардам ва сохтан/барномаҳо ноком шуданд. Ман "hostpolicy.dll... ёфт нашуд" ва "хатои MSB4018: ... ёфт нашуд ... singlefilehost.exe".
featured image - Чӣ гуна хатогиҳои "hostpolicy.dll" ва "singlefilehost.exe" -ро дар .NET 8.0.11 бартараф кардан мумкин аст
Mark Pelf HackerNoon profile picture
0-item

Тағирот дар .NET Build Tools Аз 8.0.0 то 8.0.11

Пас аз навсозӣ ба.NET 8.0.11, сохтани баъзе лоиҳаҳои ман ноком шуд…

1 Тавсифи мушкилот

Сохтани танзимоти лоиҳа ҳама дар ҷое дар атрофи .NET 8.0.0 хуб кор карданд. Баъдтар, бо навсозии вақти корӣ .NET ба версияҳои охирини .NET 8.0 ва .NET 9.0 ва навсозӣ ба Visual Studio, баъзе аз лоиҳаҳо аз кор монданд. Чунин ба назар мерасад, ки онҳо дар асбобҳои сохтмон тағйироти қатъӣ ворид кардаанд. Мантиқ ҳанӯз солим аст ва намудҳои сохтмон якхелаанд, танҳо асбобҳои сохтан каме дигар рафтор карданд. Конфигуратсияҳои нав ва скриптҳои созанда лозиманд.


Ман фикр мекунам, ки ман метавонам тағиротро дар рафтор дар байни (.NET Framework 8.0.0/.NET SDK 8.0.100) ва (.NET Framework 8.0.11/.NET SDK 8.0.404) пайдо кунам. На ҳама, аммо баъзе лоиҳаҳо ноком шуданд.

1.1 Муҳити зист

Муҳити маъмулие, ки ин мақола ба он дахл дорад, C#/VS2022 мебошад.

Версияи .NET 8.0.11 ё дертар

Ва шумо намуди лоиҳаи SelfContained ё SingleFile сохта истодаед

1.2 Зуҳури мушкилот

Шумо хатоҳо/истисноҳо мегиред:

  • Китобхонаи "hostpolicy.dll", ки барои иҷрои барнома лозим аст, ёфт нашуд

  • хатои MSB4018: …. Файли …. singlefilehost.exe ёфт нашуд


 +++Error1,When running the application:++++++++++++++++++++ A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\Program Files\dotnet\'. Failed to run as a self-contained app. - The application was run as a self-contained app because 'C:\tmpNetBundle\BundleExample02_NET90\ConsoleApp2C\ SelfContained_SingleFile_win-x64\ConsoleApp2C.runtimeconfig.json' was not found. - If this should be a framework-dependent app, add the 'C:\tmpNetBundle\BundleExample02_NET90\ConsoleApp2C\ SelfContained_SingleFile_win-x64\ConsoleApp2C.runtimeconfig.json' file and specify the appropriate framework. PS C:\tmpNetBundle\BundleExample02_NET90\ConsoleApp2C\ SelfContained_SingleFile_win-x64> +++Error2,During build++++++++++++++++++++ error MSB4018: The "GenerateBundle" task failed unexpectedly. [C:\tmpNetBundle\BundleExample01_NET_8.0.0_SDK_8.0.100\ConsoleApp2\ConsoleApp2.csproj] error MSB4018: System.IO.FileNotFoundException: Could not find file 'C:\tmpNetBundle\BundleExample01_NET_8.0.0_SDK_8.0.100\ConsoleApp2\ obj\Release\net8.0-windows\win-x64\singlefilehost.exe'.


1.3 Сабабҳои мушкилот ва ҳалли онҳо

Чунин ба назар мерасад, ки парчами <PublishSingleFile>true</PublishSingleFile> дар файли лоиҳаи .csproj дар баъзе мавридҳо корашро қатъ кардааст. Пас аз он ман дар скриптҳои сохтани худ ба он парчам такя мекардам. Мушкил нест, мо метавонем инро пешгӯӣ кунем, танҳо вақте ки мо медонем, ки чӣ интизор аст.


Чунин ба назар мерасад, ки раванди сохтани "dotnet publish" аз .NET SDK 9.* барои лоиҳаҳое, ки ман барои чаҳорчӯбаи .NET 8.* сохта будам, истифода мешавад. Ҳамин тавр, ман қарор додам, ки файли global.json- ро истифода барам, то аниқ муайян кунад, ки кадом SDK-ро истифода бурдан мехоҳам.

2 Намунаҳои код

Инҳо танзимоти кӯҳнаи сохтмон мебошанд, ки дар NET_8.0.0/SDK_8.0.100 кор мекарданд, вале дар версияҳои баъдӣ кор карданро қатъ кардаанд.

 // NET_8.0.0/SDK_8.0.100 // NOTE: These project settings all worked well somewhere around .NET 8.0.0. Later, with the upgrade of .NET runtime to later versions of .NET 8.0 and .NET 9.0 and an upgrade to Visual Studio, some of projects stopped working. It looks like they introduced breaking changes in the build tools. Logic is still sound and build types are the same, just the build tools started to behave a bit differently. A new build configurations and build scripts are needed. <!--ConsoleApp2C.csproj +++++++++++++++++++++++++++++++++++++--> <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net8.0-windows</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <PlatformTarget>x64</PlatformTarget> <Platforms>AnyCPU;x64</Platforms> <RuntimeIdentifier>win-x64</RuntimeIdentifier> <DebugType>embedded</DebugType> <PublishSingleFile>true</PublishSingleFile> <PublishTrimmed>true</PublishTrimmed> <IsTrimmable>true</IsTrimmable> <SelfContained>true</SelfContained> <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract> <EnableCompressionInSingleFile>true</EnableCompressionInSingleFile> </PropertyGroup> <ItemGroup> <ProjectReference Include="..\ClassLibrary1\ClassLibraryA.csproj" /> </ItemGroup> <Target Name="PostBuild" AfterTargets="PostBuildEvent"> <Exec Command="echo +++Post-Build+++++&#xD;&#xA; if $(ConfigurationName) == Debug ( &#xD;&#xA;echo +++++Debug+++++ &#xD;&#xA;) &#xD;&#xA;&#xD;&#xA; if $(ConfigurationName) == Release ( &#xD;&#xA; echo +++++SelfContained_SingleFile_win-x64.cmd+++++ &#xD;&#xA; call SelfContained_SingleFile_win-x64.cmd &#xD;&#xA; echo +++++SelfContained_SingleFile_win-x64_Trimmed.cmd+++++ &#xD;&#xA; call SelfContained_SingleFile_win-x64_Trimmed.cmd &#xD;&#xA;) " /> </Target> </Project> +++++Script: SelfContained_SingleFile_win-x64.cmd dotnet publish ConsoleApp2C.csproj --no-build --runtime win-x64 --configuration Release -p:PublishSingleFile=true -p:SelfContained=true -p:PublishReadyToRun=false -p:PublishTrimmed=false --output ./SelfContained_SingleFile_win-x64 +++++Script: SelfContained_SingleFile_win-x64_Trimmed.cmd dotnet publish ConsoleApp2C.csproj --no-build --runtime win-x64 --configuration Release -p:PublishSingleFile=true -p:SelfContained=true -p:PublishReadyToRun=false -p:PublishTrimmed=true --output ./SelfContained_SingleFile_win-x64_Trimmed


Инҳо танзимоти нави сохтмон мебошанд, ки дар NET_8.0.11/SDK_8.0.404 кор мекунанд

 // NET_8.0.11/SDK_8.0.404 <!--ConsoleApp2C.csproj +++++++++++++++++++++++++++++++++++++--> <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net8.0-windows</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <PlatformTarget>x64</PlatformTarget> <Platforms>AnyCPU;x64</Platforms> <RuntimeIdentifier>win-x64</RuntimeIdentifier> <DebugType>embedded</DebugType> <PublishSingleFile>true</PublishSingleFile> <PublishTrimmed>true</PublishTrimmed> <IsTrimmable>true</IsTrimmable> <SelfContained>true</SelfContained> <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract> <EnableCompressionInSingleFile>true</EnableCompressionInSingleFile> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\ClassLibrary1\ClassLibraryA.csproj" /> </ItemGroup> <Target Name="RunAfterBuild1" AfterTargets="Build"> <Exec Command="call SelfContained_SingleFile_win-x64.cmd" Condition=" '$(BuildingInsideVisualStudio)' == 'true' "/> </Target> <Target Name="RunAfterBuild2" AfterTargets="Build"> <Exec Command="call SelfContained_SingleFile_win-x64_Trimmed.cmd" Condition=" '$(BuildingInsideVisualStudio)' == 'true' "/> </Target> </Project> +++++Script: SelfContained_SingleFile_win-x64.cmd echo .NET SDK version: dotnet --version dotnet publish ConsoleApp2C.csproj --nologo --no-restore --runtime win-x64 --configuration Release -p:PublishSingleFile=true -p:SelfContained=true -p:PublishReadyToRun=false -p:PublishTrimmed=false --output ./SelfContained_SingleFile_win-x64 +++++Script: SelfContained_SingleFile_win-x64_Trimmed.cmd echo .NET SDK version: dotnet --version dotnet publish ConsoleApp2C.csproj --nologo --no-restore --runtime win-x64 --configuration Release -p:PublishSingleFile=true -p:SelfContained=true -p:PublishReadyToRun=false -p:PublishTrimmed=true --output ./SelfContained_SingleFile_win-x64_Trimmed +++++Configfile: global.json { "sdk": { "version": "8.0.404" } }


Инҳо танзимоти нави сохтмон мебошанд, ки дар NET_9.0.0/SDK_9.0.101 кор мекунанд

 // NET_9.0.0/SDK_9.0.101 <!--ConsoleApp3C.csproj +++++++++++++++++++++++++++++++++++++--> <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net9.0-windows7.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <PlatformTarget>x64</PlatformTarget> <Platforms>AnyCPU;x64</Platforms> <RuntimeIdentifier>win-x64</RuntimeIdentifier> <DebugType>embedded</DebugType> <PublishSingleFile>true</PublishSingleFile> <PublishTrimmed>true</PublishTrimmed> <IsTrimmable>true</IsTrimmable> <SelfContained>true</SelfContained> <PublishReadyToRun>true</PublishReadyToRun> <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract> <EnableCompressionInSingleFile>true</EnableCompressionInSingleFile> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\ClassLibrary1\ClassLibraryA.csproj" /> </ItemGroup> <Target Name="RunAfterBuild1" AfterTargets="Build"> <Exec Command="call SelfContained_SingleFile_win-x64_ReadyToRun.cmd" Condition=" '$(BuildingInsideVisualStudio)' == 'true' " /> </Target> <Target Name="RunAfterBuild2" AfterTargets="Build"> <Exec Command="call SelfContained_SingleFile_win-x64_Trimmed_ReadyToRun.cmd" Condition=" '$(BuildingInsideVisualStudio)' == 'true' " /> </Target> </Project> +++++Script: SelfContained_SingleFile_win-x64_ReadyToRun.cmd echo .NET SDK version: dotnet --version dotnet publish ConsoleApp3C.csproj --nologo --no-restore --runtime win-x64 --configuration Release -p:PublishSingleFile=true -p:SelfContained=true -p:PublishTrimmed=false -p:PublishReadyToRun=true --output ./SelfContained_SingleFile_win-x64_ReadyToRun +++++Script: SelfContained_SingleFile_win-x64_Trimmed_ReadyToRun.cmd echo .NET SDK version: dotnet --version dotnet publish ConsoleApp3C.csproj --nologo --no-restore --runtime win-x64 --configuration Release -p:PublishSingleFile=true -p:SelfContained=true -p:PublishReadyToRun=true -p:PublishTrimmed=true --output ./SelfContained_SingleFile_win-x64_Trimmed_ReadyToRun +++++Configfile: global.json { "sdk": { "version": "9.0.101" } }


L O A D I N G
. . . comments & more!

About Author

Mark Pelf HackerNoon profile picture
Mark Pelf@markpelf
Mark Pelf is the pen name of a Software Engineer from Belgrade, Serbia. https://markpelf.com/

ТЕГИ овезон кунед

ИН МАКОЛА ДАР...