成功发布dotnet后缺少软件包

时间:2019-06-26 14:37:38

标签: asp.net-core nuget publish

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>

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

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

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

1 个答案:

答案 0 :(得分:1)

四处搜寻,发现this post

有趣的部分是:

  

restore和build可以作为另一个命令的一部分隐式运行,   喜欢发布。当作为另一个命令的一部分隐式运行时,它们是   提供额外的上下文,以便正确的工件   生产的。使用运行时进行发布时(例如,dotnet publish   -r linux-x64),隐式还原将恢复linux-x64运行时的软件包。如果您显式调用还原,则不会还原   默认情况下,运行时程序包不存在,因为它没有该上下文。

基本上,我在运行时.netcore 2.1.1与还原版本2.1.X(X!= 1)之间添加了不匹配。

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

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