如何外部集(.dll)在Visual Studio中的代码添加到.NET核2.0
问题描述:
我面对关于对Visual Studio代码增加外部组件(.dll
)我.NET Core 2.0
控制台应用程序的一些问题,因为有小到无关于如何做到这一点的文档。如何外部集(.dll)在Visual Studio中的代码添加到.NET核2.0
Microsoft提供了一个very good tutorial关于如何将NuGet Packages
和项目添加到项目引用,但没有关于如何添加外部dlls
的信息。
答
经过一番研究,我设法让它工作。
打开
.csproj
文件下面
</PropertyGroup>
标签中,添加
<ItemGroup>
<Reference Include="Your dll file name">
<HintPath>Your dll file name.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<!-- You may set it to true if your dll has a specific version -->
</Reference>
</ItemGroup>
移动
dll
到您的项目(其中Program.cs
是)导航的根文件夹,使用控制台/终端和执行
dotnet restore
项目的根文件夹导入所有引用然后,执行
dotnet run
做不是从您的根文件夹中删除该DLL。如果你这样做,你会收到以下错误:
error CS0246: The type or namespace name 'Your dll File' could not be found (are you missing a using directive or an assembly reference?)
我今天遇到了类似的问题,与.NET 2.0的核心应用。我的工作是围绕创建一个新的.NET框架的Web应用程序(而不是.net核心)并在那里添加引用。然后我将csproj中的项目组复制到我的.net核心项目的csproj文件中。那就是诀窍。 – agileMike