运行.NET 9控制台应用时提示缺失hostpolicy.dll的问题求助
运行.NET 9控制台应用时提示缺失hostpolicy.dll的问题求助
各位大佬好,我最近在折腾.NET 9控制台应用的时候碰到了一个棘手的问题,想请大家帮忙看看。
当我运行控制台应用时,直接弹出了下面的错误提示:
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:\Users\erikw\source\repos\MainDict2\MainDict2\bin\x64\Debug\net9.0\MainDict2.runtimeconfig.json' did not specify a framework. If this should be a framework-dependent app, specify the appropriate framework in 'C:\Users\erikw\source\repos\MainDict2\MainDict2\bin\x64\Debug\net9.0\MainDict2.runtimeconfig.json'.
这是我的主项目文件内容:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net9.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences> <Platforms>AnyCPU;x64</Platforms> </PropertyGroup> <ItemGroup> <Reference Include="Microsoft.Extensions.DotNetDeltaApplier"> <HintPath>..\..\..\..\..\..\Program Files\dotnet\sdk\9.0.302\DotnetTools\dotnet-watch\9.0.302-servicing.25319.7\tools\net9.0\any\hotreload\Microsoft.Extensions.DotNetDeltaApplier.dll</HintPath> </Reference> <Reference Include="System.Collections"> <HintPath>..\..\..\..\..\..\Program Files\dotnet\shared\Microsoft.NETCore.App\9.0.7\System.Collections.dll</HintPath> </Reference> <Reference Include="System.Collections.Concurrent"> <HintPath>..\..\..\..\..\..\Program Files\dotnet\shared\Microsoft.NETCore.App\9.0.7\System.Collections.Concurrent.dll</HintPath> </Reference> <Reference Include="System.Console"> <HintPath>..\..\..\..\..\..\Program Files\dotnet\shared\Microsoft.NETCore.App\9.0.7\System.Console.dll</HintPath> </Reference> <Reference Include="System.IO.Pipes"> <HintPath>..\..\..\..\..\..\Program Files\dotnet\shared\Microsoft.NETCore.App\9.0.7\System.IO.Pipes.dll</HintPath> </Reference> <Reference Include="System.Linq"> <HintPath>..\..\..\..\..\..\Program Files\dotnet\shared\Microsoft.NETCore.App\9.0.7\System.Linq.dll</HintPath> </Reference> <Reference Include="System.Net.Http"> <HintPath>..\..\..\..\..\..\Program Files\dotnet\shared\Microsoft.NETCore.App\9.0.7\System.Net.Http.dll</HintPath> </Reference> <Reference Include="System.Private.CoreLib"> <HintPath>..\..\..\..\..\..\Program Files\dotnet\shared\Microsoft.NETCore.App\9.0.7\System.Private.CoreLib.dll</HintPath> </Reference> <Reference Include="System.Runtime"> <HintPath>..\..\..\..\..\..\Program Files\dotnet\shared\Microsoft.NETCore.App\9.0.7\System.Runtime.dll</HintPath> </Reference> <Reference Include="System.Runtime.InteropServices"> <HintPath>..\..\..\..\..\..\Program Files\dotnet\shared\Microsoft.NETCore.App\9.0.7\System.Runtime.InteropServices.dll</HintPath> </Reference> <Reference Include="System.Text.Encoding.Extensions"> <HintPath>..\..\..\..\..\..\Program Files\dotnet\shared\Microsoft.NETCore.App\9.0.7\System.Text.Encoding.Extensions.dll</HintPath> </Reference> <Reference Include="System.Threading"> <HintPath>..\..\..\..\..\..\Program Files\dotnet\shared\Microsoft.NETCore.App\9.0.7\System.Threading.dll</HintPath> </Reference> </ItemGroup> </Project>
这里我要说明下,我特意开启了<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>,因为我替换了自定义的System.Private.CoreLib.dll(修改了里面的Dictionary.cs泛型类),这一切都是为了跟着《Programming C# 10.0》这本书里的例子折腾学习用的。
我试过直接引用hostpolicy.dll,但系统提示“引用无效或不被支持”,现在完全不知道该怎么解决这个问题了,有没有大佬能给我点建议?谢谢大家!
内容来源于stack exchange
相关产品推荐
相关产品推荐

