1

I have a C# solution and some referenced 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..

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?

agatha
  • 1,513
  • 5
  • 16
  • 28
  • Have you modified your default response file? (csc.rsp.cfg or something like that). If this is a short test program, can you give the code? I assume it's just System.Attribute that you're trying to find? – Jon Skeet Sep 29 '11 at 06:37
  • @Jon Skeet it's not system.attribute, I have shortened the name when pasting it here..the file referenced is another dll, tested before as working..and I did modify the response file..not working.. – agatha Sep 29 '11 at 06:45

2 Answers2

4

As you haven't given the code, it's not clear what type Attribute is meant to be. If it's System.Attribute, I'd expect that to be found automatically via the default assembly references. 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
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • @Leah: Even when you've got it working I would strongly recommend against using type names which are already in core BCL namespaces. – Jon Skeet Sep 29 '11 at 06:49
  • I will keep that in mind...as I said before..in this case the name was shortened when pasting the error :) ..It works now. Thanks. – agatha Sep 29 '11 at 07:26
2

CSC knows nothing about the project containing test.cs, nor any libraries which that project is referencing.

You have to use the /r switch in order to reference other assemblies. Note that there is a file called csc.rsp in the folder containing csc.exe, which specifies default command line switches. This contains most of the usual .NET framework assemblies, which is why you do not have to explicitly reference mscorlib.dll, for example.

Adam Ralph
  • 29,453
  • 4
  • 60
  • 67
  • ..curious that some of the referenced dlls were recognized...but not all...works now though – agatha Sep 29 '11 at 07:10