成功发布dotnet后缺少软件包

dye*_*yes 6 publish nuget asp.net-core

publish命令工作正常,但是运行后,由于缺少软件包,我必须还原项目...

因此,如果我运行以下命令:

dotnet发布--runtime win-x64

然后进行发布,但是之后我的项目中缺少程序包。

但是如果我没有运行就运行发布:

dotnet发布

然后发布工作正常,我没有任何缺少的程序包。

这是正常行为吗?我该怎么做才能解决此问题?真烦人

这是我的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>
Run Code Online (Sandbox Code Playgroud)

编辑:从还原nugets日志中,对于发布的项目的每个依赖项,我都会得到以下内容

@   Project 'MyProject.Api' is affected (InstallCount = 0)
Run Code Online (Sandbox Code Playgroud)

因此,它实际上认为有些不同,但似乎没有安装任何东西。

dye*_*yes 3

四处挖掘,我发现了这篇文章

有趣的部分是:

恢复和构建可以作为另一个命令(例如发布)的一部分隐式运行。当作为另一个命令的一部分隐式运行时,它们会被提供额外的上下文,以便生成正确的工件。当您使用运行时发布(例如,dotnetpublish -r linux-x64)时,隐式还原将还原 linux-x64 运行时的包。如果您显式调用恢复,默认情况下它不会恢复运行时包,因为它没有该上下文。

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

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

<PropertyGroup>
    ...
    <RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
    <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)