问题描述
我正在使用 Snarl C# API向 snarl 发送通知.
I am using Snarl C# API to send notifications to snarl.
现在我已将上述 url 的内容保存在一个名为 SnarlNetwork.cs
的文件中,我的 test.cs
文件的内容是:
Now I have saved the content of above url in a file named SnarlNetwork.cs
and the content of my test.cs
file are:
using SnarlNetworkProtocol;
using System;
class test
{
public static void Main(String[] args)
{
SNP snarl_object = new SNP();
string hostname = "localhost";
string hostport = "9887";
string appName = "Spotify";
bool val = snarl_object.register(hostname, hostport, appName);
if (val == true)
{
string title = "hello";
string message = "world";
string timeout = "5";
bool newval = snarl_object.notify(hostname, hostport, appName, null, title, message, timeout);
if (newval == true)
{
Console.WriteLine("sucessfull");
}
}
}
}
现在,当我尝试使用 csc test.cs
编译我的 test.cs 文件时,我收到以下错误:
Now when I try to compile my test.cs file using csc test.cs
I get the following error:
C:UsersNoobcsharp>csc test.cs
Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.4926
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.
test.cs(1,7): error CS0246: The type or namespace name 'SnarlNetworkProtocol' could not be found (are you missing a using directive or an assembly reference?)
那么,我在这里做错了什么,因为根据我的说法,我没有错过任何 using 指令
.
So, what am I doing wrong here because according to me I am not missing any using directive
.
推荐答案
这是问题所在:
C:UsersNoobcsharp>csc test.cs
您尚未添加对 DLL 的引用.你需要这样的东西:
You haven't added a reference to the DLL. You need something like:
C:UsersNoobcsharp>csc test.cs /r:SnarlNetwork.dll
(或任何调用程序集).
(or whatever the assembly is called).
或者,如果您没有将其作为单独的库,只需编译这两个文件:
Alternatively, if you haven't got it as a separate library, just compile both files:
C:UsersNoobcsharp>csc test.cs SnarlNetwork.cs
如果您尚未编译程序集但想要,则可以使用:
If you haven't compiled an assembly but want to, you can use:
csc /target:library /out:SnarlNetwork.dll SnarlNetwork.cs
csc Test.cs /r:SnarlNetwork.dll
(实际上,在这种特殊情况下,指定输出文件是不必要的,但它仍然更清晰......)
(In fact, specifying the output file is unnecessary in this particular case, but it's still clearer...)
这篇关于为什么我收到错误 CS0246:找不到类型或命名空间名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!