1

I have a DLL (not a NuGet package) I want to reference in a C# program, in Visual Studio Code (not Visual Studio) V1.52.1. I cannot seem to add the reference.

The DLL is named Plumage.dll. The source code line looks like this:

Plumage.TSDRReq t = new Plumage.TSDRReq();

That generates the error "The type or namespace name 'Plumage' could not be found (are you missing a using directive or an assembly reference?) [testplum]csharp(CS0246)"

Adding

Using Plumage;

does not help and generates the same error message for that line.

I have tried copying the dll to: the same directory as my source; to the subdirectories obj\Debug\net5.0 and obj\Debug\net5.0\ref; and to the subdirectories bin\Debug\net5.0 and bin\Debug\net5.0\ref.

I have tried adding different variations of the following to my .csproj file:

<ItemGroup>
  <Reference Include="Plumage.dll">
    <HintPath>Plumage.dll</HintPath>
    <SpecificVersion>False</SpecificVersion> 
  </Reference>
</ItemGroup>

I am running dotnet restore (and/or dotnet restore force) after changes. Still no progress.

I've read and tried the approaches here (but that's to add a project, not a dll) and here .

I'm finding a lot of information on how to add a NuGet package (but this is not a NuGet package); and a lot of information adding a reference using Visual Studio (but this is Visual Studio Code); but I'm still stuck.

codingatty
  • 2,026
  • 1
  • 23
  • 32
  • is there a specific reason why you use ```VS Code``` for that instead ```VS``` ? – Tomek Feb 03 '21 at 22:20
  • @Tomek: One possible reason would be that .NET 5 and Visual Studio Code run on Linux and Visual Studio doesn't. – Ben Voigt Feb 03 '21 at 22:21
  • You are missing a "using" statment at top of module. To find the namespace (like System.Data) in Solution Explorer under reference right click and selct properties. The namespace will be in the properties. – jdweng Feb 03 '21 at 22:22
  • @BenVoigt that's why I am asking if there is a reason not to use VS .. – Tomek Feb 03 '21 at 22:23
  • @jdweng: No `using` statement is needed when using qualified names, as the example line of code does. But the compiler will need a `/reference` parameter, which should be setup through the project file. – Ben Voigt Feb 03 '21 at 22:24
  • the path to Plumage.dll is probably wrong. You probably need some of these guys, "..\", to get the correct relative path – ShanieMoonlight Feb 03 '21 at 22:27
  • Aha, thank you, @Shanie, that was the problem. At least with a fully-qualified pathname it's found. I can play around and see what relative paths work now. I'm on to new problems now, but at least I can move forward. – codingatty Feb 03 '21 at 22:31
  • @codingatty Cool, glad to help – ShanieMoonlight Feb 03 '21 at 22:34

1 Answers1

2

The Include attribute in the Reference tag isn't supposed to have the .dll extension. It's not a filename.

You can see examples in this answer: https://stackoverflow.com/a/16580870/103167 and in this question: Which one is correct approach for assembly reference in csproj file?

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720