【问题标题】:dotnet restore for package System.Diagnostics.FileVersionInfo in .csproj.csproj 中包 System.Diagnostics.FileVersionInfo 的 dotnet restore
【发布时间】:2017-05-08 08:00:26
【问题描述】:

我目前正在尝试在 debian 中运行 netcore 应用程序。但是,一旦我运行dotnet restore,就会出现错误。为了检查 dotnet 是否正常,我使用 dotnet new 创建了一个新项目。那里的恢复工作正常。但是一旦我添加了对 System.Diagnostics.FileVersionInfo,我收到以下错误:

/opt/dotnet/sdk/1.0.3/NuGet.targets(97,5):错误:对象引用未设置为对象的实例。 [/root/test/test.csproj]

原始项目是在 Windows 中使用 Visual Studio 2017 开发的。如果我在那里执行dotnet restore,它可以正常工作。即使我做一个dotnet restore -r debian.8-x64

有人知道这里出了什么问题吗?

我为测试目的创建的test.csproj 也失败了,如下所示:

<PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>


  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
    <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
    <PackageReference Include="System.Diagnostics.FileVersionInfo" Version="4.3.0" />
  </ItemGroup>


</Project>

【问题讨论】:

  • 你使用的是什么版本的 NuGet?

标签: c# nuget .net-core


【解决方案1】:

System.Diagnostics.FileVersionInfo 包需要以下 NuGet 版本。

使用 NuGet 3.x 时,此包至少需要 3.4 版。
需要 NuGet 2.12 或更高版本。

您可以查看System.Diagnostics.FileVersionInfo

要检查 NuGet 版本,只需在终端 nuget 中打印

$ nuget
NuGet Version: 2.8.7.0
usage: NuGet <command> [args] [options] 
Type 'NuGet help <command>' for help on a specific command.

更新 1 如何在 LINUX Original Answer 上安装 NUGET

一旦您按照(有点烦人的)安装步骤安装了 .Net 核心并从https://www.microsoft.com/net/core 设置了 apt 存储库,您就可以这样做了:

sudo apt install nuget

你的本地机器上会有一个工作的 nuget:

$ cat /etc/issue
Ubuntu 16.04.1 LTS \n \l

$ nuget
NuGet Version: 2.8.7.0
usage: NuGet <command> [args] [options] 
Type 'NuGet help <command>' for help on a specific command.

请注意,在撰写本文时不要运行 nuget update -self,因为虽然它会成功安装更新版本的 nuget,但该版本实际上不会运行。

如果你真的把它弄坏了,你总是可以把它吹走并重新安装:

sudo apt remove nuget
sudo apt install nuget

【讨论】:

  • 哦,好的,谢谢,那时可能使用了错误的 nuget 版本,但我不确定。我实际上不需要安装nuget。如果我错了,请纠正我,但 dotnet 没有集成自己的 nuget 版本吗?如果我运行dotnet nuget,我会看到一个帮助屏幕,上面写着“NuGet 命令行 4.0.0.0”。如果我从 apt-get 获得的 nuget 版本似乎太旧了。它是 2.8.1.0。
  • @timothy3001 package.json 在新版本的 .net core 中仅用于 npm。 NuGet 正在使用 .csproj 文件。
  • 好的,谢谢。没有查看 Ubuntu 指南,只查看了 Debian 指南,他们没有提到更新 apt 存储库。到目前为止非常感谢,正在尝试将存储库也放入我的 apt 中。
  • @timothy3001 按照 MSDN 文档,您需要安装 .NET Core SDK、Mono 并在 Mono 上运行 NuGet docs.microsoft.com/en-us/nuget/guides/install-nuget
  • 嗯,谢谢。我想我会同意的。尽管安装 Mono 并使用它来获得更新版本的 nuget 是很奇怪的。老实说,这对我来说似乎是一个肮脏的解决方法,但我想没有其他办法。我想我会在 github 上打开一个问题,因为我认为这应该得到适当的修复。否则,您将无法在 linux 平台上正确开发..
猜你喜欢
  • 2023-04-02
  • 2017-06-06
  • 1970-01-01
  • 2018-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-21
  • 2022-01-16
相关资源
最近更新 更多