如何外部集(.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的信息。

经过一番研究,我设法让它工作。

  1. 打开.csproj文件

  2. 下面</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>

  1. 移动dll到您的项目(其中Program.cs是)

  2. 导航的文件夹,使用控制台/终端和执行dotnet restore项目的文件夹导入所有引用

  3. 然后,执行dotnet run

  4. 不是从您的根文件夹中删除该DLL。如果你这样做,你会收到以下错误:

  5. error CS0246: The type or namespace name 'Your dll File' could not be found (are you missing a using directive or an assembly reference?)

开始=>
+0

我今天遇到了类似的问题,与.NET 2.0的核心应用。我的工作是围绕创建一个新的.NET框架的Web应用程序(而不是.net核心)并在那里添加引用。然后我将csproj中的项目组复制到我的.net核心项目的csproj文件中。那就是诀窍。 – agileMike