简体   繁体   中英

Condition in csproj is ignored

When I am running "do.net 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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM