'.NET Core project - Exclude files from single file publishment

I would like to exclude nuget dlls from single file deployment but I do not know what am I doing wrong.

My current .csproj is this

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
    <PackageReference Include="System.Security.Principal.Windows" Version="5.0.0" />
  </ItemGroup>

  <ItemGroup>
    <Content Update="Newtonsoft.Json.dll">
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
      <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
    </Content>
    <Content Update="System.Security.Principal.Windows.dll">
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
      <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
    </Content>
  </ItemGroup>

</Project>

Method I tried is described here: https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file/overview#exclude-files-from-being-embedded



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source