[英]How to add a DLL to a C# program in Visual Studio Code?
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.我有一个 DLL(不是 NuGet 包)我想在 Visual Studio Code(不是 Visual Studio)V1.52.1 中的 C# 程序中引用。 I cannot seem to add the reference.我似乎无法添加参考。
The DLL is named Plumage.dll. DLL 被命名为 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)"这会生成错误“找不到类型或命名空间名称'Plumage'(您是否缺少 using 指令或程序集引用?) [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;我尝试将 dll 复制到:与我的源相同的目录; to the subdirectories obj\Debug\net5.0
and obj\Debug\net5.0\ref
;到子目录obj\Debug\net5.0
和obj\Debug\net5.0\ref
; and to the subdirectories bin\Debug\net5.0
and bin\Debug\net5.0\ref
.以及子目录bin\Debug\net5.0
和bin\Debug\net5.0\ref
。
I have tried adding different variations of the following to my.csproj file:我尝试将以下不同变体添加到 my.csproj 文件中:
<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.更改后我正在运行dotnet restore
(和/或dotnet restore force
)。 Still no progress.仍然没有进展。
I've read and tried the approaches here (but that's to add a project, not a dll) and here .我已经阅读并尝试了这里的方法(但那是添加一个项目,而不是一个 dll)和这里。
I'm finding a lot of information on how to add a NuGet package (but this is not a NuGet package);我找到了很多关于如何添加 NuGet package 的信息(但这不是 NuGet 包); and a lot of information adding a reference using Visual Studio (but this is Visual Studio Code );以及使用 Visual Studio 添加引用的大量信息(但这是 Visual Studio Code ); but I'm still stuck.但我还是被困住了。
The Include
attribute in the Reference
tag isn't supposed to have the .dll
extension. Reference
标记中的Include
属性不应具有.dll
扩展名。 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?您可以在此答案中看到示例: https://stackoverflow.com/a/16580870/103167并在此问题中:在 csproj 文件中哪个是正确的程序集引用方法?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.