ChatGPT解决这个技术问题 Extra ChatGPT

warning : All projects referencing MyProject.csproj must install nuget package Microsoft.Bcl.Build

I have an ASP.NET MVC 4 app developed in VS 2012. The app consists of a main project (MyProject), a unit-test project (MyProject.Tests), an Azure deployment project (MyProject.Azure), and a couple of general-purpose library projects.

When I right-click on either the solution or the main project and select Manage NuGet Packages, I see a bunch of Microsoft updates that have apparently become available in the last month or so. If I click on the Update All button then the updates are apparently installed without any obvious problems, but when I build the solution I get this error message TWICE:

warning : All projects referencing MyProject.csproj must install nuget package Microsoft.Bcl.Build

Ok, so I have two projects that reference MyProject: MyProject.Tests and MyProject.Azure. I can right-click MyProject.Tests, select ManageNuGet Packages, and add Microsoft.Bcl.Build. That gets rid of one of the two warnings. But VS does not give me an option to manage NuGet packages for the MyProject.Azure project.

How do I add the Microsoft.Bcl.Build package to the Azure deployment project?

EDIT:

Thanks to user swell, I now know that a Microsoft Connect issue for this problem has been opened here.

Thanks for the reference to the connect issue, this is an annoying problem.
Related to the warning when building the deployment project, there is also a bug that causes a spurious warning when publishing the project. The publish-related bug is also reported on Connect. I don't know of a workaround.
The same issue happens to me for WiX projects that have references to other projects (for the purpose of harvesting project output aka. "heat"). It makes no sense whatsoever for a WiX installer project to install NuGet packages! Argh!!
The link to the connect issue now returns 404 connect.microsoft.com/VisualStudio/feedback/details/789839/…

S
Sander

The answer provided by TheESJ is correct, however the wording wasn't clear to me. Since I cannot comment on the answer, I will provide more details here. Specifically, I was having this problem with an Azure project and the following workaround was required to make the warning go away:

When you double-click the warning in VisualStudio, you will be taken to the BclBuildValidateNugetPackageReferences target in the Microsoft.BclBuild.targets file. Above the actual target element, you should find a large comment block that talks about disabling the project reference checks. Since Azure projects cannot have any library references, it is impossible for those Azure projects to fulfill the requirements of this particular build target.

The solution? Disable reference checking from the Azure project since it is impossible to actually add a nuget package reference.

EXAMPLE

So, assume we have two projects: MyAzureProject.ccproj which references MyProject.csproj. Follow these steps:

Right-click on "MyAzureProject" in the Solution Explorer and select "Edit Project File." Find the project reference to "MyProject." It should look something like: MyProject {1d99490e-d140-4897-9890-238e673a5864} ... Add the following element inside of the ProjectReference element: SkipValidatePackageReferences=true Your project reference should now look like this: MyProject {1d99490e-d140-4897-9890-238e673a5864} ... SkipValidatePackageReferences=true Right-click on "MyAzureProject" in Solution Explorer and choose "Reload Project."

You should now be able to rebuild and the error should be gone.


In my version of VS I have to first right-click and "Unload Project" before I can right-click to edit the project file
Did you mean MyAzureProject.ccproj rather than MyAzureProject.csproj?
It works only if I add 'SkipValidatePackageReferences=true' to referenced project *.csproj file. Just editing *.ccproj doesn't work.
@pius It's a small feature, but there's an 'Edit Project File' contextual menu option under 'Power Commands' in Productivity Power Tools, available for several editions of VS. It will unload the project and open the project file for you in one click.
@EdwardBrey Good question. .ccproj is used for azure cloud projects, so it's not a typo.
T
TheESJ

If you double click the warning it gives you instructions for disabling the warning.

It is safe to disable for projectreferences from projects that don't yet support Nuget.

See below portion in bold copied from Microsoft.Bcl.Build.targets.

BclBuildValidateNugetPackageReferences

This target can be disabled for a project reference by setting SkipValidatePackageReferences=true for the reference:

<ProjectReference Include="..\pcl\pcl.csproj">
  <Project>{664a9e98-fac7-4567-a046-0dde95fddb48}</Project>
  <Name>pcl</Name>
  <Properties>SkipValidatePackageReferences=true</Properties>
</ProjectReference>

Arthur, can you try setting the AdditionalPropertes metadata value instead of Properties?
@TheESJ I was having this problem with a WiX project and looks like setting AdditionalProperties instead of Properties works. I'm interested in knowing why though
This works for just building the solution, but when you actually use 'Run' with the azure project as your startup project, you will see the warnings again.
Don't work even on build. VS 2015 Community Edition.
Did not work in VS2015 Professional. I have the same issue adding this line.
s
superjos

I faced the same issue and was trying to update Microsoft.Bcl.Build.targets; which did not help.

After some investigation found that .csproj file of the Azure Service project must be modified to include <Properties>SkipValidatePackageReferences=true</Properties>.

This was not apparent from the answer of @TheESJ and so decided to post separate answer. Thanks to @TheESJ.


o
ozz

I encountered this issue a number of times, and the Properties method does indeed work, but when dealing with a Wix project, I had to do the following instead:

<AdditionalProperties>SkipValidatePackageReferences=true</AdditionalProperties>

When I used the Properties Xml node, I got a new error:

The OutputPath property is not set for project 'MyInstallerProject.csproj'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='Debug' Platform='x86'. This error may also appear if some other project is trying to follow a project-to-project reference to this project, this project has been unloaded or is not included in the solution, and the referencing project does not build using the same or an equivalent Configuration or Platform.


M
Mick

After failing to resolve the issues with any of the above answers, I simply followed the instructions contained within the Microsoft.Bcl.Build.targets file (displayed after double clicking on the error in the build output window). I unloaded my project (referencing Azure packages), encountering the error. Edited the project file and inserted the following...

<PropertyGroup>
      <SkipValidatePackageReferences>true</SkipValidatePackageReferences>
</PropertyGroup>

...at the top of the project file before the first PropertyGroup.