使用 .NET 8 - 我的 Web 应用程序在调试时运行良好,但当我将其发布到文件夹时,它会引发 FileNotFound 异常。未处理的异常。System.IO.FileNotFoundException:无法加载文件或
使用.NET 8-我的 Web 应用程序在调试时运行良好,但是当我将其发布到文件夹时,它会引发异常 FileNotFound
。
未处理的异常。System.IO.FileNotFoundException:无法加载文件或程序集“Swashbuckle.AspNetCore.SwaggerGen,Culture=neutral,PublicKeyToken=null”。系统找不到指定的文件。文件名:“Swashbuckle.AspNetCore.SwaggerGen,Culture=neutral,PublicKeyToken=null”
我已确保已 Swashbuckle.AspNetCore.SwaggerGen
安装 NuGet 包。
语境:
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers(); // this line here
builder.Services.AddDistributedMemoryCache();
builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromSeconds(60);
options.Cookie.HttpOnly = false;
options.Cookie.IsEssential = true;
});
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseSession();
app.MapControllerRoute("default", "{controller}/{action=Index}/{id?}");
app.MapFallbackToFile("index.html");
return app;
编辑:Jason Pan 要求提供 csproj 文件。这里是
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<SpaRoot>..\prodschedule.client</SpaRoot>
<SpaProxyLaunchCommand>npm start</SpaProxyLaunchCommand>
<SpaProxyServerUrl>https://localhost:4200</SpaProxyServerUrl>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SpaProxy">
<Version>8.*-*</Version>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.ApiDescription.Server" Version="8.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.OpenApi" Version="1.6.18" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.3" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.7.3" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.7.3" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.7.3" />
</ItemGroup>
<ItemGroup>
<Content Include="Sql\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\prodschedule.client\prodschedule.client.esproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="W:\Improvement\Client Subscriptions\SubHashes\SubHashes.csproj" />
<ProjectReference Include="W:\Improvement\Libraries\CSharp\ApiLibrary\Holidays\Holidays.csproj" />
<ProjectReference Include="W:\Improvement\Libraries\CSharp\ApiLibrary\Http\Http.csproj" />
<ProjectReference Include="W:\Improvement\Libraries\CSharp\ApiLibrary\Ostendo\Ostendo.csproj" />
<ProjectReference Include="W:\Improvement\Libraries\CSharp\CSLogger\CSLogger.csproj" />
<ProjectReference Include="W:\Improvement\Libraries\CSharp\Utility\Utility.csproj" />
</ItemGroup>
</Project>