简体   繁体   English

Visual Studio .net 标准库模板使用指令中断?

[英]Visual Studio .net standard library template breaks using directive?

I'm currently trying to learn a bit about .NET and get back into programming with C#.我目前正在尝试了解一些关于 .NET 的知识,并重新开始使用 C# 进行编程。 To do both I'm following this official tutorial on how to create a .NET standard class library. 为此,我正在关注如何创建 .NET 标准 class 库的官方教程。

One of the first steps is to create a Class Library (.NET Standard) template provided by the .NET kit in visual studio.第一步是在 Visual Studio 中创建 .NET 套件提供的Class 库(.NET 标准)模板。 This creates a basic file with the following code:这将使用以下代码创建一个基本文件:

using System;

namespace StringLibrary
{
    public class Class1
    {
    }
}

Now visual studio immediately greets me with this error message:现在视觉工作室立即向我打招呼这个错误消息:

Error CS0246 The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)错误 CS0246 找不到类型或命名空间名称“系统”(您是否缺少 using 指令或程序集引用?)

I tried google, some people have vaguely similar problems, where they forget to add the reverence to their different projects, however I cannot find any way to add System ... Besides, the rest of the tutorial files work fine and are able to import System .我试过google,有些人有类似的问题,他们忘记在他们的不同项目中添加崇敬,但是我找不到任何方法来添加系统......此外,教程文件的rest工作正常并且能够导入系统 (I can also reference the other files just fine) (我也可以参考其他文件就好了)

Did anyone encounter a similar problem?有没有人遇到过类似的问题? Is the template bugged, or did I mess up installing the kit (which I did via the Visual Studio installer, so no idea, how that could happen)?模板是否有问题,或者我是否搞砸了安装套件(我通过 Visual Studio 安装程序完成的,所以不知道这怎么会发生)?

If I can clarify anything, feel free to ask, and thanks in advance.如果我能澄清任何事情,请随时询问,并提前致谢。

As @Lex Li suggested, i used dotnet restore in the project folder and got the error NU1101, which meant, that the package I want to use could not be found.正如@Lex Li 建议的那样,我在项目文件夹中使用了dotnet restore并得到了错误 NU1101,这意味着找不到我想要使用的 package。 I found this website https://www.hossambarakat.net/2020/06/24/fix-error-NU1101/ and chose option A: to add a nuget.config.我找到了这个网站https://www.hossambarakat.net/2020/06/24/fix-error-NU1101/并选择选项 A:添加 nuget.config。 To do this I opened the command prompt and navigated to \Users\myUser\Appdata\Roaming\NuGet and executed NuGet.Config, which opened a file in Visual Studio.为此,我打开命令提示符并导航到\Users\myUser\Appdata\Roaming\NuGet并执行 NuGet.Config,它在 Visual Studio 中打开了一个文件。 Here I only added the package sources lines from the following lines, since the rest was already there (see also the link):在这里,我只从以下几行添加了 package 源代码行,因为 rest 已经存在(另请参见链接):

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>
</configuration>

After that restarting Visual Studio solved the issue, and I can now continue the tutorial.之后重新启动 Visual Studio 解决了这个问题,我现在可以继续教程了。

Thanks for the help!谢谢您的帮助!

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

相关问题 Class 库(.NET 标准)模板在 Visual Studio 2019 中不起作用 - Class Library (.NET Standard) Template Not working in Visual Studio 2019 Visual Studio 2017使用.net标准库时复制太多文件 - Visual Studio 2017 Copy too many files when using a .net standard library Visual Studio 2019 中的 .Net Standard 1.0 class 库 - .Net Standard 1.0 class library in Visual Studio 2019 Visual Studio 2017 不会在 .NET Standard 库中加载 .NET Framework 引用 - Visual Studio 2017 won't load .NET Framework references in .NET Standard library Visual Studio .NET标准库和.NET Framework项目-NuGet dll清单定义不匹配 - Visual Studio .NET Standard library and .NET Framework project - NuGet dll manifest definition does not match 如何从Visual Studio 2017中的.NET Framework 4.5控制台应用程序引用.NET标准库? - How Do You Reference a .NET Standard Library from a .NET Framework 4.5 Console Application in Visual Studio 2017? 如何在Visual Studio 2017中将PCL更改为.net平台标准库? - How can I change a PCL into a .net Platform Standard Library in Visual Studio 2017? Visual Studio扩展中的.Net Standard项目类型 - .Net Standard project type in Visual Studio extension 使用Visual Studio 2010进入asp.net中的类库 - Step into a class library in asp.net using visual studio 2010 使用 RestSharp 方法时 Visual Studio 中断 - When using RestSharp Method Visual Studio breaks
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM