7

I have a solution with multiple projects, one of them has this build warning that shows

All projects referencing Project.csproj must install nuget package Microsoft.Bcl.Build

I want to get rid of this warning as we are going to apply a clean build approach for build integration where all warnings would be counted as error. So all warnings and errors should be cleared before pushing to remote repository which would trigger the CI build, and for merging in master build needs to be successful.

How can I Remove/Suppress/Bypass this particular warning?

Mamun Reza
  • 608
  • 1
  • 6
  • 19
  • 3
    Have you tried actually following the instructions in the warning and install the said nuget package in those projects? – Sefe Jan 05 '17 at 11:47
  • 1
    Yes, then the warning spreads across other projects and all of them show this warning. Why should I install this when everything is working fine without it? – Mamun Reza Jan 05 '17 at 11:53
  • Yes, we are treating warnings as error to keep a clean solution and to follow best coding practices at most. Does it mean we need to install a package that has nothing to do with applications' architecture, business or anything related? There has to be a reason to have that package, and from googling I have not found any straight forward answer regarding that. – Mamun Reza Jan 05 '17 at 12:11
  • 3
    If so, do you actually need it at all? have you tried to remove the reference completely? – nozzleman Jan 05 '17 at 12:39
  • @nozzleman thanks!! I did not notice before, but although no .dll was installed for Microsoft.Bcl.Build in project but somehow there was reference in pakcage.config. So I removed all Microsoft.Bcl.Build related references from everywhere and now the warning seems gone! – Mamun Reza Jan 05 '17 at 13:14
  • 1
    Since you have resolve the issue, please post an answer, and mark it as answer, it will be beneficial to other communities. – Zhanglong Wu - MSFT Jan 06 '17 at 09:27

4 Answers4

14

I have resolved the issue by completely removing all Microsoft.Bcl and Microsoft.Bcl.Build references as @nozzleman suggested in comments.

Although no dll references were present in the References list in solution explorer, there were entries in package.config for those 2 packages as below:

<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net461" />
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net461" />

I did a search (Ctrl + F) in full solution for the terms Microsoft.Bcl and Microsoft.Bcl.Build and removed all those entries from packages.config and also from .csproj files which had entries like below:

<Import Project="..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
  <Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
    <Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
    <Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
  </Target>

Those lines were appended when it was installed before and as someone manually removed references by pressing Delete key, they were not removed.

After cleaning those 2 items from everywhere the warning is gone from build.

Mamun Reza
  • 608
  • 1
  • 6
  • 19
5

How can I Remove/Suppress/Bypass this particular warning?

You can add a parameter named Properties with value SkipValidatePackageReferences=true to to disable for projectreferences from projects that don't yet support Nuget, which is safe. Like this:

<ItemGroup>
    <ProjectReference Include="..\MyProject\Project.csproj">
      <Name> Project</Name>
      <Project>{77ACF4A4-5F19-40E9-991D-BDB09B175366}</Project>
      <Private>True</Private>
      <RoleType>Web</RoleType>
      <RoleName>MyProject</RoleName>
      <UpdateDiagnosticsConnectionStringOnPublish>True</UpdateDiagnosticsConnectionStringOnPublish>
      <Properties>SkipValidatePackageReferences=true</Properties>
    </ProjectReference>
  </ItemGroup>
Zhanglong Wu - MSFT
  • 1,652
  • 1
  • 7
  • 8
  • 1
    SkipValidatePackageReferences is applied to the ProjectReference so no other NuGet package references will be validated for the referenced project. This seems too broad as other packages should rightly be validated, no? I suppose that is why you as well as many others are clear to state:"projects that don't yet support Nuget". But by limiting this workaround to only when "projects that don't yet support NuGet" it does not address the fact that projects with other package references still render the compiler warning. – Adam Caviness Aug 15 '17 at 16:18
  • i would not recommend this as it can cause your assemblies to be rebuild if another reference of the same project does not have the same properties. causing issue son code analysis and instrumentation – Oscar Cabrero Oct 26 '18 at 22:33
  • This doesnt work in VS 2022. – Greg Aug 29 '22 at 11:00
0

In my case I had the same error, but it turned out that I should fix the path to the packages in the proj file. I changed it from: ..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets to

..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets

Simply this package was the first one and the build was failing due to incorrect packages path.

K. B.
  • 3,342
  • 3
  • 19
  • 32
0

If your project is referencing another project that is referencing Microsoft.Bcl.Build then the warning will appear at build-time.

My project was showing the build warning "All projects referencing MyProject.csproj must install nuget package Microsoft.Bcl.Build" . It was referencing a nuget package called TweetinviAPI-1.3.0-JsonLanguageConverterFix which was referencing Microsoft.Bcl.Build . Once I removed the reference to TweetinviAPI-1.3.0-JsonLanguageConverterFix the warning disappeared.

sevzas
  • 701
  • 2
  • 5
  • 13