我有一个有趣的问题。当我在台式机上使用dotnet publis时,它会在 Linux 运行时编译我的项目而不会出错。当我在笔记本电脑上编译同一个项目时,Linux 运行出现一个错误,即在Microsoft.AspNetCore.JsonPatch上抱怨。当我试图找出问题所在时,我发现笔记本电脑上的dotnet publis使用 v2.2,如果我从 VS2019 构建我的解决方案,它使用正确的 3.0 版本(我的项目是 .net core 3)。
有趣的是,在我的笔记本电脑上,我生成了包含以下内容的web.config文件
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\portalnekretnine.com" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: F1180308-B6BA-4CCE-A131-F48B9B2DFD5E-->
有任何想法吗?
这是我如何从命令行构建
dotnet publish D:\Projects\PortalNekretnine\Backend\PortalNekretnine.sln --configuration Release --framework netcoreapp3.0 --output .\build\ --self-contained false --runtime linux-x64 --verbosity quiet
我的 API 的 csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<AssemblyName>portalnekretnine.com</AssemblyName>
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
<RunAnalyzersDuringLiveAnalysis>false</RunAnalyzersDuringLiveAnalysis>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="4.9.4" />
<PackageReference Include="IdentityModel" Version="4.0.0" />
<PackageReference Include="IdentityServer4" Version="3.0.1" />
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Analyzers" Version="3.0.0-preview3-19153-02" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.0" />
<PackageReference Include="Microsoft.OpenApi" Version="1.1.4" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="NSwag.Core" Version="13.1.3" />
<PackageReference Include="Serilog" Version="2.9.0-dev-01133" />
<PackageReference Include="Serilog.Exceptions" Version="5.3.1" />
<PackageReference Include="Serilog.Settings.AppSettings" Version="2.2.2" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0-dev-00850" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc4" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="5.0.0-rc8" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="5.0.0-rc4" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="5.0.0-rc4" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.0.0-rc4" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.6.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\portalnekretnine.infrastructures\portalnekretnine.infrastructures.csproj" />
<ProjectReference Include="..\portalnekretnine.models\portalnekretnine.models.csproj" />
<ProjectReference Include="..\portalnekretnine.services\portalnekretnine.services.csproj" />
</ItemGroup>
</Project>
如果需要任何代码示例或配置,请告诉我。
谢谢