简体   繁体   English

使用.NET CORE安装NuGet软件包和Visual Studio代码失败

[英]Install NuGet package with .NET CORE and visual studio code failed

I am on ubuntu and I use VSCode and .NET CORE, I installed a package called Otter with the command panel. 我在ubuntu上,使用VSCode和.NET CORE,我在命令面板上安装了名为Otter的软件包。

My .csproj is now like this : 我的.csproj现在是这样的:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Otter" Version="0.9.8.926"/>
  </ItemGroup>

My main .cs file is : 我的主要.cs文件是:

using System;
using Otter;

namespace helloWorldFromCSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello");
        }
    }
}

But when I try to build my project with : 但是当我尝试使用以下命令构建项目时:

dotnet build

I receive this error : 我收到此错误:

Program.cs(2,7): error CS0246: The type or namespace name 'Otter' could not be found (are you missing a using directive or an assembly reference?) [/home/erwan/Documents/helloWorldFromCSharp/helloWorldFromCSharp.csproj]

I don"t know how to fix it. 我不知道该如何解决。

I tested with a simple .Net Core App to reproduce the problem. 我使用一个简单的.Net Core应用程序进行了测试,以重现该问题。 I have the same issue. 我有同样的问题。

Otter is in .Net Framework 4.5, so It won't work with an Asp.Net Core Application. Otter位于.Net Framework 4.5中,因此它将无法与Asp.Net Core应用程序一起使用。

Since you are on Ubuntu, you can't just switch to Asp.Net MVC. 由于您使用的是Ubuntu,因此不能只切换到Asp.Net MVC。 I recommend you to look for another 2d framework wrote in .Net Core or in .Net Standard (don't know if it is possible) 我建议您寻找以.Net Core或.Net Standard编写的另一个2d框架(不知道是否可能)

Looking at Otter.csproj : Otter.csproj

<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>

Meaning, you can't reference it from a project that compiles to netcoreapp2.1 意思是,您不能从编译为netcoreapp2.1的项目中引用它

You might want to clone the project and try to target it to a suitable framework version, if possible. 您可能想要克隆项目,并尝试将其定位到合适的框架版本(如果可能)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Visual Studio Code for Unity中安装Nuget程序包 - Install a Nuget package in Visual Studio Code for Unity Visual Studio Nuget无法安装任何软件包 - Visual Studio Nuget unable to install any package 引用 a.Net Core 3.1 NuGet package 的 a.Net 5 Visual Studio 项目/解决方案如何编译成功? - How can a .Net 5 Visual Studio Project / Solution that reference a .Net Core 3.1 NuGet package compile successfuly? Visual Studio Nuget 包管理器 Net Core 允许高于目标 sdk 的包 - Visual Studio Nuget Package Manager Net Core allowing packages that are higher then target sdk 在.NET Core Web API中安装自定义.NET Standard NuGet软件包 - Install custom .NET Standard NuGet Package in .NET Core Web API 在Visual Studio中构建项目时如何安装Nuget包 - How install Nuget package when building project in Visual Studio 无法安装Visual Studio C#NuGet程序包 - Cannot install Visual Studio C# NuGet package 无法在Visual Studio 2012中安装Nuget程序包帮助页面 - Cannot install Nuget Package HelpPage in Visual Studio 2012 如何使用 Visual Studio Code 从 .NET Core 访问 Nuget 存储库 - How to access Nuget repository from .NET Core using Visual Studio Code 如何解决 Visual Studio 中的“NuGet package 还原失败”? - How to resolve "NuGet package restore failed" in Visual Studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM