gpt4 book ai didi

asp.net-core - 成功发布 dotnet 后软件包丢失

转载 作者:行者123 更新时间:2023-12-02 13:37:18 24 4
gpt4 key购买 nike

发布命令工作正常,但运行后,我必须恢复项目,因为缺少包......

所以如果我运行以下命令:

dotnet publish --runtime win-x64

然后发布就可以了,但是之后我的项目中缺少软件包。

但是如果我在没有运行时的情况下运行发布:

dotnet publish

然后发布工作正常,我没有丢失任何包。

这是正常行为吗?我可以做什么来解决这个问题?这很烦人。

这是我的 csproj 文件:

<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup">
<Version>3.3.6</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.App">
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.StaticFiles">
<Version>2.1.1</Version>
</PackageReference>
<PackageReference Include="NSwag.AspNetCore">
<Version>12.0.13</Version>
</PackageReference>
<PackageReference Include="NSwag.MSBuild">
<Version>12.0.13</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MyProject.Analytics\MyProject.Analytics.csproj" />
<ProjectReference Include="..\MyProject.ApiClient\MyProject.ApiClient.csproj" />
<ProjectReference Include="..\MyProject.CommonApi\MyProject.CommonApi.csproj" />
<ProjectReference Include="..\MyProject.Common\MyProject.Common.csproj" />
<ProjectReference Include="..\MyProject.DbAccess\MyProject.DbAccess.csproj" />
<ProjectReference Include="..\MyProject.Logging\MyProject.Logging.csproj" />
<ProjectReference Include="..\MyProject.Messaging\MyProject.Messaging.csproj" />
<ProjectReference Include="..\MyProject.Model\MyProject.Model.csproj" />
<ProjectReference Include="..\MyProject.Settings\MyProject.Settings.csproj" />
</ItemGroup>
<ItemGroup>
<Content Update="appsettings.Api.Development.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="appsettings.Api.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="appsettings.Api.Production.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include=".ebextensions\never-sleep-again.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="appsettings.Api.PreProduction.json">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Folder Include="MyProjectlogs\Development" />
</ItemGroup>
<ItemGroup>
<ProjectCapability Include="SourceItemsFromImports" />
</ItemGroup>
<Target Name="NSwag" AfterTargets="Build">
<Copy SourceFiles="@(Reference)" DestinationFolder="$(OutDir)References" />
<Exec Command="$(NSwagExe_Core21) run nswag.json /variables" />
<RemoveDir Directories="$(OutDir)References" />
</Target>

编辑:从恢复 nugets 日志中,我得到了我发布的项目的每个依赖项的以下信息

@   Project 'MyProject.Api' is affected (InstallCount = 0)

所以它实际上认为有些东西是不同的,但似乎没有安装任何东西。

最佳答案

四处挖掘,我发现this post .

有趣的部分是:

restore and build can be run implicitly as part of another command,like publish. When run implicitly as part of another command, they areprovided with additional context so that the right artifacts areproduced. When you publish with a runtime (for example, dotnet publish-r linux-x64), the implicit restore restores packages for the linux-x64 runtime. If you call restore explicitly, it does not restoreruntime packages by default, because it doesn't have that context.

基本上,运行时 .netcore 2.1.1 与恢复版本 2.1.X (X != 1) 之间不匹配。

解决方案(在上面的链接中进行了解释)是将其添加到项目文件中:

<PropertyGroup>
...
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup>

关于asp.net-core - 成功发布 dotnet 后软件包丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56775338/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com