The publish command works fine but after it is run, I have to restore the project as there are missing packages...
So if I run the following command :
dotnet publish --runtime win-x64
Then the publish works but I have missing packages in my project right after.
BUT if I run publish without a runtime :
dotnet publish
Then the publish works fine and I don't have any missing package.
Is it a normal behaviour? What can I do to fix this? This is annoying.
Here is my csproj file :
<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>
Edit : From the restore nugets logs, I get the following for each dependency of the project I publish
@ Project 'MyProject.Api' is affected (InstallCount = 0)
So it actually thinks something is different but doesn't seem to install anything.
Digging around, I found this post.
The interesting part is :
restore and build can be run implicitly as part of another command, like publish. When run implicitly as part of another command, they are provided with additional context so that the right artifacts are produced. 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 restore runtime packages by default, because it doesn't have that context.
Basically I had a mismatch between the runtime .netcore 2.1.1 vs the restore one 2.1.X (X != 1).
The solution (explained in the link above) is to add this to the project file :
<PropertyGroup>
...
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup>