[英]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.