NuGet / Home

Repo for NuGet Client issues
Other
1.49k stars 250 forks source link

[Bug]: Updating `developmentDependency` package reference is overwriting `<PrivateAssets>` and `<IncludeAssets>` statements #12112

Open WardenDrew opened 1 year ago

WardenDrew commented 1 year ago

NuGet Product Used

Visual Studio Package Management UI

Product Version

VS 17.2.6, NuGet 6.2.1

Worked before?

No

Impact

It's more difficult to complete my work

Repro Steps & Context

Edit: Video of issue: https://youtu.be/axtNPpq9_OE

When referencing a package with developmentDependency set and explicitly changing the <PrivateAssets> and <IncludeAssets> lines, on an update to the package, the changes are overwritten with the defaults for a development dependency.

  1. Include the Microsoft.EntityFrameworkCore.Design package, normally a development dependency
  2. Modify the <PackageReference> in the project's csproj file to the following:
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.8">
    <PrivateAssets>contentfiles;analyzers;build</PrivateAssets>
    <IncludeAssets>all</IncludeAssets>
    <ExcludeAssets>none</ExcludeAssets>
</PackageReference>
  1. Build the project
  2. Via the package management UI, update the package to 6.0.9
  3. Observe that the package reference has been changed to:
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.9">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    <ExcludeAssets>none</ExcludeAssets>
</PackageReference>

Expected Behavior:

Only the version is incremented and the custom <PrivateAssets> and <IncludeAssets> statements are not overridden.

Verbose Logs

Logs are from VS's package manager output

Restoring packages for C:\Users\ahaskell\source\repos\devmatics\clockwork-api\src\Clockwork.Data.MigrationHelper\Clockwork.Data.MigrationHelper.csproj...
Installing NuGet package Microsoft.EntityFrameworkCore.Design 6.0.9.
Generating MSBuild file C:\Users\ahaskell\source\repos\devmatics\clockwork-api\src\Clockwork.Data.MigrationHelper\obj\Clockwork.Data.MigrationHelper.csproj.nuget.g.props.
Writing assets file to disk. Path: C:\Users\ahaskell\source\repos\devmatics\clockwork-api\src\Clockwork.Data.MigrationHelper\obj\project.assets.json
Successfully uninstalled 'Microsoft.EntityFrameworkCore 6.0.8' from Clockwork.Data.MigrationHelper
Successfully uninstalled 'Microsoft.EntityFrameworkCore.Abstractions 6.0.8' from Clockwork.Data.MigrationHelper
Successfully uninstalled 'Microsoft.EntityFrameworkCore.Analyzers 6.0.8' from Clockwork.Data.MigrationHelper
Successfully uninstalled 'Microsoft.EntityFrameworkCore.Design 6.0.8' from Clockwork.Data.MigrationHelper
Successfully uninstalled 'Microsoft.EntityFrameworkCore.Relational 6.0.8' from Clockwork.Data.MigrationHelper
Successfully installed 'Microsoft.EntityFrameworkCore 6.0.9' to Clockwork.Data.MigrationHelper
Successfully installed 'Microsoft.EntityFrameworkCore.Abstractions 6.0.9' to Clockwork.Data.MigrationHelper
Successfully installed 'Microsoft.EntityFrameworkCore.Analyzers 6.0.9' to Clockwork.Data.MigrationHelper
Successfully installed 'Microsoft.EntityFrameworkCore.Design 6.0.9' to Clockwork.Data.MigrationHelper
Successfully installed 'Microsoft.EntityFrameworkCore.Relational 6.0.9' to Clockwork.Data.MigrationHelper
Assets file has not changed. Skipping assets file writing. Path: C:\Users\ahaskell\source\repos\devmatics\clockwork-api\src\Clockwork.API\obj\project.assets.json
Restored C:\Users\ahaskell\source\repos\devmatics\clockwork-api\src\Clockwork.API\Clockwork.API.csproj (in 3 ms).

NuGet Config files used:
    C:\Users\ahaskell\AppData\Roaming\NuGet\NuGet.Config
    C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config

Feeds used:
    https://api.nuget.org/v3/index.json
    C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
Executing nuget actions took 86 ms
Time Elapsed: 00:00:01.4394916
========== Finished ==========
WardenDrew commented 1 year ago

Video of issue: https://youtu.be/axtNPpq9_OE

martinrrm commented 1 year ago

I was able to reproduce this, this behavior is also present in dotnet CLI

WardenDrew commented 1 year ago

Keeping this alive, but I can confirm this still happens in VS 17.4.0 with Nuget 6.4.0 still