Home > Software engineering >  What is the difference between PackageReference Update and PackageReference Include?
What is the difference between PackageReference Update and PackageReference Include?

Time:03-29

    <PackageReference Update="Microsoft.NETCore.App" Version="2.1.22" />
    <PackageReference Include="Platform.Core" Version="1.8.0" />

What is the difference between "Update" and "Include" in the above two lines?

CodePudding user response:

See these docs.

It looks like Update is used when you want to modify only some properties on a pre-existing item with the same name

So you could do:

<PackageReference Include="Some.Package" Version="1.2.3"/>
<PackageReference Update="Some.Package" PrivateAssets="all"/>

The Update line would add the PrivateAssets="all" property to the pre-existing Some.Package item, with the end result being the same as:

<PackageReference Include="Some.Package" Version="1.2.3" PrivateAssets="all"/>

If you had used Include instead of Update, you'd have overwritten the first line entirely, and lost the Version="1.2.3" property.

Note that just using Update when there isn't a pre-existing item to update seems to be harmless, but is pointless.

  • Related