NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 252 forks source link

Framework Conditioned warning properties are not respected for multi-targeting projects #5712

Open anangaur opened 7 years ago

anangaur commented 7 years ago

From: https://developercommunity.visualstudio.com/content/problem/88109/cannot-suppress-nu1701-from-project-properties.html

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. Rebuild

Expected:Warnings should disappear Actual: Warnings still show up:

image

Looking at the asset file, the warning is persisted: image

Edit by @nkolev92; repro below

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

  <PropertyGroup>
    <TargetFrameworks>netcoreapp2.2;netcoreapp2.1</TargetFrameworks>
    <NoWarn Condition="'$(TargetFramework)' == 'netcoreapp2.2'">NU1701</NoWarn>
    <AssetTargetFallback>net46</AssetTargetFallback>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="NuGet.Credentials" Version="4.6.2" />
  </ItemGroup>

</Project>
emgarten commented 7 years ago

A restore is needed to update the suppressions, a rebuild should have done that however. @mishra14 would you try this out?

mishra14 commented 7 years ago

@emgarten @anangaur and I discussed this.

It seems that we do not get the NoWarn property from msbuild. Possibly because the property is added with multiple conditions that @anangaur will post here.

anangaur commented 7 years ago

The csproj file reads like the following:

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

Issues:

  1. This should not add warnings under conditions: https://github.com/Microsoft/VSProjectSystem/issues/241

  2. [This bug] Even with the current conditions, the warnings should be suppressed but it is not.

rrelyea commented 7 years ago

@mishra14 - if this is external, please use a label, not just zenhub. can you please look at @anangaur second point and determine how many fixes are necessary, and if this should be one of them.

mishra14 commented 7 years ago

The reason is that we do not pass conditions to msbuild when requesting properties. I will see if it is possible to get this done as part of #5501

mishra14 commented 7 years ago

Update -

I looked more into this and this is a VS only problem. Since, in dotnet restore and msbuild /t:restore calls we can pass in additional properties.

mishra14 commented 7 years ago

Looked more into this -

The core issue is that in multi-targeting projects, the project system adds a condition on the first tfm of the project. I have filed an issue with them - https://github.com/dotnet/project-system/issues/2804

I will wait for their response/traction.

nkolev92 commented 5 years ago

Just to clarify the status here;

https://github.com/NuGet/Home/issues/5712#issuecomment-320808057

Framework conditioned no warns are not supported in either CLI or VS.

Repro that shows this:

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

  <PropertyGroup>
    <TargetFrameworks>netcoreapp2.2;netcoreapp2.1</TargetFrameworks>
    <NoWarn Condition="'$(TargetFramework)' == 'netcoreapp2.2'">NU1701</NoWarn>
    <AssetTargetFallback>net46</AssetTargetFallback>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="NuGet.Credentials" Version="4.6.2" />
  </ItemGroup>

</Project>