1

When I am running "dotnet publish --runtime=linux-x64 -c Release" the libusb-1.0.pdb file is added to the publish folder even though the condition flag is set to different than Release

<ItemGroup>
    <Content Include="..\lib\Windows\libusb-1.0.pdb" Condition="'$(Configuration)' != 'Release'">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
<ItemGroup>
    <Content Include="..\lib\Windows\libusb-1.0.pdb" Condition="'$(Configuration)' != 'Release'">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
Tony
  • 31
  • 5
  • see: [Why the `Condition` attribute doesn't work for the `ItemGroup` element?](https://stackoverflow.com/questions/28851338/why-the-condition-attribute-doesnt-work-for-the-itemgroup-element) – Luuk Dec 02 '22 at 13:52
  • I'm not sure but try these options: 1) Set the condition on the ItemGroup element - OR 2) Try the inverse: if Release, Content Remove. 3) For every change to the .csproj, reload the project and rebuild it – Ergis Dec 02 '22 at 14:30

1 Answers1

1

Assuming you reference a .dll file in the same location, MSBuild will pick up "related files" automatically. You can work around this by limiting the extensions of related files:

<PropertyGroup Condition="'$(Configuration)' != 'Release'">
  <AllowedReferenceRelatedFileExtensions>
    .xml;
    .pri;
    .dll.config;
    .exe.config
  </AllowedReferenceRelatedFileExtensions>
</PropertyGroup>

Note that this is a copy of what can be found in the .NET SDK in Microsoft.Common.props but without an entry for .pdb.

Do note that you should no longer need to include the .pdb file as a Content item. If you do, you need to also keep your original definition for that item.

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217