简体   繁体   中英

How to restore or install Nuget packages from copy then paste to *.csproj file?

I am using Microsoft Visual Studio Community 2019 Preview - Version 16.8.0 Preview 2.0 , .NET Core 5.0.100-preview.8.20417.9 , ASP.NET Core 5.0-preview Web API. Original file *.csproj

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

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

</Project>

Then I add (copy a part from another projects manually)

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

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="AWSSDK.Polly" Version="3.5.0.5" />
    <PackageReference Include="ChilkatNativeLib" Version="9.5.0.83" />
    <PackageReference Include="HtmlAgilityPack" Version="1.11.24" />
    <PackageReference Include="HtmlAgilityPack.NetCore" Version="1.5.0.1" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.0-preview.8.20414.8" />
    <PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.0-preview.8.20414.8" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="5.0.0-preview.8.20414.8" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0-preview.8.20407.4" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0-preview.8.20407.4" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.0-preview.8.20407.4">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Identity.Core" Version="5.0.0-preview.8.20414.8" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.0-preview.8.20419.1" />
    <PackageReference Include="MimeKit" Version="2.9.1" />
    <PackageReference Include="NAudio" Version="1.10.0" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    <PackageReference Include="NUnit" Version="3.12.0" />
    <PackageReference Include="RestSharp" Version="106.11.5-alpha.0.18" />
    <PackageReference Include="SendGrid" Version="9.21.0" />
    <PackageReference Include="Serilog" Version="2.10.0-dev-01240" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.1" />
    <PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.5.1" />
    <PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="5.5.1" />
    <PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="5.5.1" />
    <PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.5.1" />

    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.9" />

    <PackageReference Include="System.ServiceModel.Syndication" Version="5.0.0-preview.8.20407.11" />
    <PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0-preview.8.20407.11" />

  </ItemGroup>
</Project>

Then I run

dotnet restore

but not success.

How to restore or install Nuget packages from copy then paste to *.csproj file?

How to restore or install Nuget packages from copy then paste to *.csproj file?

I think it is an issue on Visual Studio Preview 16.8 with Net Core 5.0.

First of all , update-package -reinstall command cannot be used for Net Core project, it is used for Net Framework projects with packages.config nuget management format.

For Net Core projects, you can just click build which will restore nuget packages.

Actually , when you install the nuget package on the Net Core 5.0 project, it restores packages successfully on the global nuget folder.

You can first delete all nuget packages under C:\\Users\\xxx(current user)\\.nuget\\packages and then rebuild your project.

The packages will all restore under that folder.

====================================================================

But however, the main issue is that:

For Net Core 5.0 , nuget package has no name and reference path though it can be restored and build without any warnings and errors.

在此处输入图片说明

While in Net Core 3.1, it has the name and full reference path so that VS can find it.

在此处输入图片说明

That's why the yellow triangle occurs. And not sure whether this behavior will affects your developing.

And the name and path are the given by the system and we cannot change it.

You can try to change your project from Net Core 5.0 to Net Core 3.1 , I am sure that most of the yellow triangles will disappear.

Since it is an issue , I have reported it to our DC Forum .

You can vote it or add any comments if I did not describe the issue in detail. And I hope the Team will check the issue and resolve the issue as soon as possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM