project-system icon indicating copy to clipboard operation
project-system copied to clipboard

Suppressing warnings through project properties UI adds tfm condition in csproj file for multi targeting project

Open mishra14 opened this issue 7 years ago • 12 comments

Repro steps:

  1. Create a new NetCore 2.0 Console App
  2. Multi-target to netcoreapp2.0;net461: <TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
  3. Add a NuGet reference to a net 461 compat package like RestSharp
  4. Build -> Show 2 warnings which seems to be another bug: https://github.com/dotnet/sdk/issues/1474
  5. Suppress warning NU1701 from Project->Properties->Build->Suppress Warnings
  6. Edit the csproj file -
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netcoreapp2.0|AnyCPU'">
    <NoWarn>1701;1702;1705;NU1701</NoWarn>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="RestSharp" Version="105.2.3" />
  </ItemGroup>

</Project>

The issue here is that the user did not select netcoreapp2.0 while suppressing the warning but the csproj has netcoreapp2.0 in the condition.

Other Info:

if you try the same steps in a project that does not multi-target then the condition is fine -

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <NoWarn>1701;1702;1705;NU1701</NoWarn>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="RestSharp" Version="105.2.3" />
  </ItemGroup>

</Project>

VS Version: 15.4.0 Preview 2 | d15rel/16828.0

cc: @natidea @emgarten

mishra14 avatar Sep 07 '17 23:09 mishra14