How to bypass Microsoft.Bcl.Build warning

2019-06-26 09:27发布

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?

2条回答
做自己的国王
2楼-- · 2019-06-26 10:07

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>
查看更多
Deceive 欺骗
3楼-- · 2019-06-26 10:13

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.

查看更多
登录 后发表回答