简体   繁体   English

C#编译器找不到dll; VS2010中编译的解决方案

[英]C# compiler does not find dlls ; solution compiled in VS2010

I have a C# solution and some referenced dll-s. 我有一个C#解决方案和一些引用的dll-s。 Even though when compiling in visual studio(vs2010) it appears as it succeeded, when using the C# compiler it fails: missing dll apparently.. 即使在Visual Studio(vs2010)中进行编译时,它看起来像是成功,但在使用C#编译器时却失败了:显然缺少dll。

csc /t:library /out:test.dll test.cs


test.cs(22,10): error CS0246: The type or namespace name
    'Attribute' could not be found (are you missing a using directive
    or an assembly reference?)

Does anyone know why is this happening? 有人知道为什么会这样吗?

As you haven't given the code, it's not clear what type Attribute is meant to be. 由于您没有提供代码,因此尚不清楚Attribute是什么类型。 If it's System.Attribute , I'd expect that to be found automatically via the default assembly references. 如果它是System.Attribute ,我希望可以通过默认的程序集引用自动找到它。 If it's a type in another assembly, you need to explicitly reference it from the command line: 如果它是另一个程序集中的类型,则需要从命令行中显式引用它:

csc /t:library /out:test.dll /r:OtherAssembly.dll test.cs

CSC knows nothing about the project containing test.cs, nor any libraries which that project is referencing. CSC对包含test.cs的项目一无所知,也对该项目所引用的任何库一无所知。

You have to use the /r switch in order to reference other assemblies. 您必须使用/ r开关才能引用其他程序集。 Note that there is a file called csc.rsp in the folder containing csc.exe, which specifies default command line switches. 请注意,包含csc.exe的文件夹中有一个名为csc.rsp的文件,该文件指定默认命令行开关。 This contains most of the usual .NET framework assemblies, which is why you do not have to explicitly reference mscorlib.dll, for example. 它包含大多数常用的.NET Framework程序集,因此,例如,您不必显式引用mscorlib.dll。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM