C# 类型或命名空间名称";彼得罗;找不到
我只是试着用demohello.cs程序使用回购协议。但我最终遇到了以下问题 1)属性PeterO.Cbor在颜色上没有其他属性反射。请参考以下代码。C# 类型或命名空间名称";彼得罗;找不到,c#,.net,visual-studio-code,cbor,C#,.net,Visual Studio Code,Cbor,我只是试着用demohello.cs程序使用回购协议。但我最终遇到了以下问题 1)属性PeterO.Cbor在颜色上没有其他属性反射。请参考以下代码。 using System; using System.IO; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; using System.Threading.Tasks; using PeterO; u
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using PeterO;
using PeterO.Cbor; // Why this attribute is in different color?
namespace Hello
{
public class HelloWorld
{
public static void Main(string[] args)
{
Console.WriteLine ("Hello World!");
var cbor1 = CBORObject.NewMap()
.Add("item", "any string")
.Add("number", 42)
.Add("map", CBORObject.NewMap().Add("number", 42))
.Add("array", CBORObject.NewArray().Add(999f).Add("xyz"))
.Add("bytes", new byte[] { 0, 1, 2 });
// The following converts the map to CBOR
byte[] bytes = cbor1.EncodeToBytes();
// The following converts the map to JSON
string json = cbor1.ToJSONString();
System.Console.WriteLine(json);
Console.ReadKey();
}
}
}
2)执行hello.cs程序时出错。请从下面的快照中找到相同的内容。
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using PeterO;
using PeterO.Cbor; // Why this attribute is in different color?
namespace Hello
{
public class HelloWorld
{
public static void Main(string[] args)
{
Console.WriteLine ("Hello World!");
var cbor1 = CBORObject.NewMap()
.Add("item", "any string")
.Add("number", 42)
.Add("map", CBORObject.NewMap().Add("number", 42))
.Add("array", CBORObject.NewArray().Add(999f).Add("xyz"))
.Add("bytes", new byte[] { 0, 1, 2 });
// The following converts the map to CBOR
byte[] bytes = cbor1.EncodeToBytes();
// The following converts the map to JSON
string json = cbor1.ToJSONString();
System.Console.WriteLine(json);
Console.ReadKey();
}
}
}
使用的命令:mcs hello.cs-out:hello
编译错误输出消息:
hello.cs(8,7): error CS0246: The type or namespace name `PeterO' could not be found. Are you missing an assembly reference?
Compilation failed: 1 error(s), 0 warnings
其他信息:
Dotnet-sdk installation steps:
a) wget https://download.visualstudio.microsoft.com/download/pr/f01e3d97-c1c3-4635-bc77-0c893be36820/6ec6acabc22468c6cc68b61625b14a7d/dotnet-sdk-3.1.402-linux-x64.tar.gz
b) mkdir -p $HOME/dotnet && tar zxf dotnet-sdk-3.1.402-linux-x64.tar.gz -C $HOME/dotnet
c) export DOTNET_ROOT=$HOME/dotnet
d) export PATH=$PATH:$HOME/dotnet
Visual Studio Code installation steps:
a) wget https://az764295.vo.msecnd.net/stable/2af051012b66169dde0c4dfae3f5ef48f787ff69/code_1.49.3-1601661857_amd64.deb
b) sudo dpkg -i code_1.49.3-1601661857_amd64.deb && sudo apt-get update
a) Ubuntu Command: lsb_release -a
Output:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.5 LTS
Release: 18.04
Codename: bionic
Path: /path/to/repo/CBOR/
Command: dotnet restore
Output:
Determining projects to restore...
/path/to/repo/CBOR/CBOR.csproj : error NU1108: Cycle detected. [/path/to/repo/CBOR.sln]
/path/to/repo/CBOR/CBOR.csproj : error NU1108: PeterO.Cbor -> PeterO.Cbor (>= 4.2.0). [/path/to/repo/CBOR.sln]
1)Dotnet sdk和Visual Studio代码安装步骤如下所示:
Dotnet-sdk installation steps:
a) wget https://download.visualstudio.microsoft.com/download/pr/f01e3d97-c1c3-4635-bc77-0c893be36820/6ec6acabc22468c6cc68b61625b14a7d/dotnet-sdk-3.1.402-linux-x64.tar.gz
b) mkdir -p $HOME/dotnet && tar zxf dotnet-sdk-3.1.402-linux-x64.tar.gz -C $HOME/dotnet
c) export DOTNET_ROOT=$HOME/dotnet
d) export PATH=$PATH:$HOME/dotnet
Visual Studio Code installation steps:
a) wget https://az764295.vo.msecnd.net/stable/2af051012b66169dde0c4dfae3f5ef48f787ff69/code_1.49.3-1601661857_amd64.deb
b) sudo dpkg -i code_1.49.3-1601661857_amd64.deb && sudo apt-get update
a) Ubuntu Command: lsb_release -a
Output:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.5 LTS
Release: 18.04
Codename: bionic
Path: /path/to/repo/CBOR/
Command: dotnet restore
Output:
Determining projects to restore...
/path/to/repo/CBOR/CBOR.csproj : error NU1108: Cycle detected. [/path/to/repo/CBOR.sln]
/path/to/repo/CBOR/CBOR.csproj : error NU1108: PeterO.Cbor -> PeterO.Cbor (>= 4.2.0). [/path/to/repo/CBOR.sln]
2)Ubuntu、Dotnet和Visual Studio代码版本详细信息:
Dotnet-sdk installation steps:
a) wget https://download.visualstudio.microsoft.com/download/pr/f01e3d97-c1c3-4635-bc77-0c893be36820/6ec6acabc22468c6cc68b61625b14a7d/dotnet-sdk-3.1.402-linux-x64.tar.gz
b) mkdir -p $HOME/dotnet && tar zxf dotnet-sdk-3.1.402-linux-x64.tar.gz -C $HOME/dotnet
c) export DOTNET_ROOT=$HOME/dotnet
d) export PATH=$PATH:$HOME/dotnet
Visual Studio Code installation steps:
a) wget https://az764295.vo.msecnd.net/stable/2af051012b66169dde0c4dfae3f5ef48f787ff69/code_1.49.3-1601661857_amd64.deb
b) sudo dpkg -i code_1.49.3-1601661857_amd64.deb && sudo apt-get update
a) Ubuntu Command: lsb_release -a
Output:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.5 LTS
Release: 18.04
Codename: bionic
Path: /path/to/repo/CBOR/
Command: dotnet restore
Output:
Determining projects to restore...
/path/to/repo/CBOR/CBOR.csproj : error NU1108: Cycle detected. [/path/to/repo/CBOR.sln]
/path/to/repo/CBOR/CBOR.csproj : error NU1108: PeterO.Cbor -> PeterO.Cbor (>= 4.2.0). [/path/to/repo/CBOR.sln]
3)Dotnet还原命令输出:
Dotnet-sdk installation steps:
a) wget https://download.visualstudio.microsoft.com/download/pr/f01e3d97-c1c3-4635-bc77-0c893be36820/6ec6acabc22468c6cc68b61625b14a7d/dotnet-sdk-3.1.402-linux-x64.tar.gz
b) mkdir -p $HOME/dotnet && tar zxf dotnet-sdk-3.1.402-linux-x64.tar.gz -C $HOME/dotnet
c) export DOTNET_ROOT=$HOME/dotnet
d) export PATH=$PATH:$HOME/dotnet
Visual Studio Code installation steps:
a) wget https://az764295.vo.msecnd.net/stable/2af051012b66169dde0c4dfae3f5ef48f787ff69/code_1.49.3-1601661857_amd64.deb
b) sudo dpkg -i code_1.49.3-1601661857_amd64.deb && sudo apt-get update
a) Ubuntu Command: lsb_release -a
Output:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.5 LTS
Release: 18.04
Codename: bionic
Path: /path/to/repo/CBOR/
Command: dotnet restore
Output:
Determining projects to restore...
/path/to/repo/CBOR/CBOR.csproj : error NU1108: Cycle detected. [/path/to/repo/CBOR.sln]
/path/to/repo/CBOR/CBOR.csproj : error NU1108: PeterO.Cbor -> PeterO.Cbor (>= 4.2.0). [/path/to/repo/CBOR.sln]
因此,我将文件/path/to/repo/Cbor/Cbor.csproj中的PackageId PeterO.Cbor替换为PackageId Peter Cbor。然后它给出了构建输出,如下所示
Path: /path/to/repo/CBOR/
Command: dotnet restore
Output:
Determining projects to restore... Restored
/path/to/repo/CBOR/CBOR.csproj (in 306 ms).
Restored /path/to/repo/CBORTest/CBORTest.csproj (in 319 ms).
6 of 8 projects are up-to-date for restore.
我对visualstudio代码和dotnet框架也很陌生
有谁能纠正我这个问题,让我知道哪里出了问题。1:这不是一个属性,它被称为a,它与Java、Python(甚至更多)中的
import
基本相同,与C/C++中的#include
相当。在C#中是完全不同的
2:mcs
是Mono C#编译器,与.NET无关。相反,使用to,以及更多
现在,你的整个问题有点让人困惑,所以我会一步一步地告诉你如何做你想做的事
YourProjectName
,并将所需的所有内容都放在其中。即,一个YourProjectName.csproj
文件和一个Program.cs
文件。Program.cs
只是一种约定,您的入口点(Main
方法)可以位于任何地方
CBOR在上可用,这意味着我们可以简单地运行
到您的YourProjectName.csproj
文件,并还原(下载/生成任何依赖项)您的项目
Program.cs
现在,您可以打开VS Code(或任何文本编辑器)并编辑Program.cs
,以执行所需操作。如果您想测试您的程序,只需切换到终端,cd
到项目目录,然后运行dotnet run
。这将编译并运行您的项目p.S:我强烈建议遵循指南中给出的建议您是否在项目中添加了对
Peter0
的引用?你的参考资料的屏幕截图可能有用。你做了吗?它被称为“使用
指令”。C#有一个完全不同的功能,名为,所以最好不要混淆名称。@mjwills我已经使用nuget数据包管理器安装了PeterO.Cbor
包。仅安装之后,我就遇到了上述错误。@WSC能否请您参考链接中的所有参考点?创建新项目并使用nuget cli安装cbor工作正常。谢谢dotnet新控制台——命名YourProjectName;dotnet添加包PeterO.Cbor——版本4.2.0;dotnet恢复;网络运行代码>但是,我想将cbor与fiddler工具集成,在那里它可以与mono一起工作。如何执行此操作?如果我尝试运行命令mcs Program.cs-out:exe
,则得到的错误为Program.cs(2,7):错误CS0246:找不到类型或命名空间名称'PeterO'。是否缺少程序集引用?编译失败:1个错误,0个警告。那么,您需要使用mono而不是dotnet构建应用程序。但这很简单,因为您只需使用msbuild
命令即可构建.csproj
项目。如果您想将其用作fiddler扩展,则需要遵循指南。不要直接使用mcs
,请使用生成系统(msbuild
),否则您需要自己手动指定所有依赖项和所有内容,类似于在生成C/C++项目时必须手动指定所有链接器参数