65

When I build my .NET Core (NETStandard v2.0) project I am getting the following warning:

ViewModels: [FodyPackageReference] Fody: The package reference for PropertyChanged.Fody does not contain PrivateAssets='All'

The warning is in reference to the PropertyChanged.Fody NuGet package.

While the warning does not stop the build, I would like to resolve the warning. However, I don't understand what it is trying to communicate.

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Ryan Payne
  • 5,249
  • 4
  • 28
  • 69

1 Answers1

62

PrivateAssets is a metadata tag used to control dependency assets.

You might be using a dependency purely as a development harness and might not want to expose that to projects that will consume your package. In this scenario, you can use the PrivateAssets metadata to control this behavior.

Package references (PackageReference) in project files

In your case, unless you want to expose PropertyChanged.Fody to a consumer (i.e. you are releasing a library), setting PrivateAssets to All in your .csproj file will remove the warning.

<Project Sdk="Microsoft.NET.Sdk">
    <ItemGroup>
      <PackageReference Include="PropertyChanged.Fody" Version="3.3.1" PrivateAssets="All" />
    </ItemGroup>
</Project>
Ryan Payne
  • 5,249
  • 4
  • 28
  • 69
  • 4
    Thanks a lot, that's great and helped. I discovered, that sometimes the notation in the .csproj is like: ` 3.3.1 All ` – marsh Jan 19 '21 at 09:54
  • 1
    It was changed. Please, update the comment with: ``. – rios0rios0 Jul 27 '21 at 00:00
  • 2
    @rios0rios0 What has changed? Also, why does it matters what you put in the Include or Version attributes? This question and answer is about the PrivateAssets attribute, not about a specific dependency. – Ryan Payne Jul 27 '21 at 13:25
  • @RyanPayne please, try to do what you said in the new version of the packages. And you'll get an error. There's no property called "PropertyChanged.Fody". It doesn't exist anymore. The property "PrivateAssets" only works in the declaration of the package, as I said. – rios0rios0 Jul 27 '21 at 19:36
  • 4
    @rios0rios0 Costura.Fody is a completely separate package from PropertyChanged.Fody (see https://github.com/Fody/Costura). I just tried it out and the above code still works fine. – Ryan Payne Jul 28 '21 at 22:07
  • When I add this fix I have an exclamation mark in Dependencies->Packages->PropertyChanged.Fody – raV720 Jun 24 '22 at 13:21
  • @raV720 I'm not sure what you mean. This isn't really a fix but an optional parameter. I can't really help you debug your issue without more information. – Ryan Payne Jun 24 '22 at 19:44
  • @RyanPayne Visual Studio 2022 v17.1.6 -> create new WPF project with .net 6.0 -> add PropertyChanged.Fody nuget -> the warning about PrivateAssets='All' appears -> set PrivateAssets='All' in project project file as described in your answer -> immediately exclamation mark in Dependencies appears – raV720 Jun 27 '22 at 06:01
  • @raV720 interesting. If I were you, I'd post a new Stack Overflow question about the specific issue you're experiencing. – Ryan Payne Jun 27 '22 at 12:34