VisualStudio icon indicating copy to clipboard operation
VisualStudio copied to clipboard

Installing package within VS2019 creates conflict with unsaved version

Open ukWaqas opened this issue 4 years ago • 0 comments

Versions

  • Visual Studio version: Microsoft Visual Studio Community 2019, Version 16.8.6

What happened

When adding two packages to a new solution (one via powershell, and the other within Visual studio itself), Visual Studio is unable to retain the latter one (via Package Manager Console), although does correctly add the packages in the backup project file, but not within existing project file.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Create a new ASP.NET Core Web Application, and choose ASP.NET Core Web API.
  2. Once solution is created, create a sub folder in Solution Explorer called DataAccess.
  3. Goto solution folder via powershell and type dotnet add package Microsoft.Data.Sqlite
  4. Once successfully installed (you will be able to see the Microsoft.Data.Sqlite in the Packages with in Solution Explorer), go to Package Manager Console and type dotnet add package Microsoft.EntityFrameworkCore.sqlite
  5. The following error is displayed: One or more projects ('<project file>.csproj') have been changed outside of the project system, and conflict with unsaved changes. The external changes have been discarded but have been saved in a backup file if you need to manually restore them. warning message is shown in a horizontal yellow bar below the icons And reference to Microsoft.EntityFrameworkCore.sqlite does not appear in the Packages section.

Expected behavior

Both packages should be installed successfully

Screenshots

image

Logs

Log from within Windows Powershell (when installing the sqlite package):

❯ cd .\Documents\
❯ cd .\Developer\
❯ cd .\dotnet-core\
❯ cd .\<Project Name>\
❯ cd .\<Project Name>\
❯ dotnet add package Microsoft.Data.Sqlite
  Determining projects to restore...
  Writing C:\Users\<User>\AppData\Local\Temp\tmp4D6C.tmp
info : Adding PackageReference for package 'Microsoft.Data.Sqlite' into project 'C:\Users\<User>\Documents\Developer\dotnet-core\<Project Name>\<Project Name>\<Project Name>.csproj'.
info :   GET https://api.nuget.org/v3/registration5-gz-semver2/microsoft.data.sqlite/index.json
info :   OK https://api.nuget.org/v3/registration5-gz-semver2/microsoft.data.sqlite/index.json 639ms
info : Restoring packages for C:\Users\<User>\Documents\Developer\dotnet-core\<Project Name>\<Project Name>\<Project Name>.csproj...
info :   GET https://api.nuget.org/v3-flatcontainer/microsoft.data.sqlite/index.json
info :   OK https://api.nuget.org/v3-flatcontainer/microsoft.data.sqlite/index.json 589ms
info :   GET https://api.nuget.org/v3-flatcontainer/microsoft.data.sqlite/5.0.3/microsoft.data.sqlite.5.0.3.nupkg
info :   OK https://api.nuget.org/v3-flatcontainer/microsoft.data.sqlite/5.0.3/microsoft.data.sqlite.5.0.3.nupkg 426ms
info : Installing Microsoft.Data.Sqlite 5.0.3.
info : Package 'Microsoft.Data.Sqlite' is compatible with all the specified frameworks in project 'C:\Users\<User>\Documents\Developer\dotnet-core\<Project Name>\<Project Name>\<Project Name>.csproj'.
info : PackageReference for package 'Microsoft.Data.Sqlite' version '5.0.3' added to file 'C:\Users\<User>\Documents\Developer\dotnet-core\<Project Name>\<Project Name>\<Project Name>.csproj'.
info : Committing restore...
info : Generating MSBuild file C:\Users\<User>\Documents\Developer\dotnet-core\<Project Name>\<Project Name>\obj\<Project Name>.csproj.nuget.g.props.
info : Writing assets file to disk. Path: C:\Users\<User>\Documents\Developer\dotnet-core\<Project Name>\<Project Name>\obj\project.assets.json
log  : Restored C:\Users\<User>\Documents\Developer\dotnet-core\<Project Name>\<Project Name>\<Project Name>.csproj (in 1.25 sec).

Log from within Package Manager Console (when installing the EF Sqlite package):

PM> cd <Project Name>
PM> dotnet add package Microsoft.EntityFrameworkCore.sqlite
  Determining projects to restore...
  Writing C:\Users\<User>\AppData\Local\Temp\tmpA2D7.tmp
info : Adding PackageReference for package 'Microsoft.EntityFrameworkCore.sqlite' into project 'C:\Users\<User>\Documents\Developer\dotnet-core\<Project Name>\<Project Name>\<Project Name>.csproj'.
info :   GET https://api.nuget.org/v3/registration5-gz-semver2/microsoft.entityframeworkcore.sqlite/index.json
info :   OK https://api.nuget.org/v3/registration5-gz-semver2/microsoft.entityframeworkcore.sqlite/index.json 420ms
info : Restoring packages for C:\Users\waqas\Documents\Developer\dotnet-core\mwt-api\mwt-api\mwt-api.csproj...
info : Package 'Microsoft.EntityFrameworkCore.sqlite' is compatible with all the specified frameworks in project 'C:\Users\<User>\Documents\Developer\dotnet-core\<Project Name>\<Project Name>\<Project Name>.csproj'.
info : PackageReference for package 'Microsoft.EntityFrameworkCore.sqlite' version '5.0.3' added to file 'C:\Users\<User>\Documents\Developer\dotnet-core\<Project Name>\<Project Name>\<Project Name>.csproj'.
info : Committing restore...
info : Writing assets file to disk. Path: C:\Users\<User>\Documents\Developer\dotnet-core\<Project Name>\<Project Name>\obj\project.assets.json
log  : Restored C:\Users\<User>\Documents\Developer\dotnet-core\<Project Name>\<Project Name>\<Project Name>.csproj (in 169 ms).

Additional context

The <Project Name> - Backup.csproj has correct package references (also expressed in screenshot), whereas the open solution (<Project Name>.csproj) does not.

<Project Name> - Backup.csproj contents:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <RootNamespace><Project Name></RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Data.Sqlite" Version="5.0.3" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.sqlite" Version="5.0.3" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
  </ItemGroup>

</Project>

<Project Name>.csproj contents:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <RootNamespace><Project Name></RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Data.Sqlite" Version="5.0.3" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="DataAccess\" />
  </ItemGroup>

</Project>

ukWaqas avatar Mar 01 '21 21:03 ukWaqas