如何在asp.net核心项目中添加对外部dll文件的引用

问题描述:

每次我尝试将对非asp.net核心项目中任何dll文件的引用添加到我的新asp.net核心项目中时,都会收到此错误消息:

Everytime I try to add reference to any dll file from my non asp.net core projects to my new asp.net core project i get this error message:

.NET Core项目在此版本中仅支持引用.NET Framework程序集.参考 其他程序集,则需要将它们包含在NuGet包中,并且 引用那个包裹.

.NET Core projects only support referencing .NET framework assemblies in this release. To reference other assemblies, they need to be included in a NuGet package and reference that package.

这应该怎么办?有什么特殊的方法吗?,接缝中我缺少与以前的所有asp.net版本不同的东西

What should be happen here? is there a special way to do it?, seams there is something I am missing here which different than all previous asp.net version

到目前为止,您无法直接将完整的.NET Framework dll直接添加到ASP.NET核心项目( netcoreapp1.0 )中.您将必须创建NuGet程序包.

As of now, you cannot directly add full .NET framework dll into ASP.NET core project (netcoreapp1.0) directly. You will have to create NuGet package.

如果它是项目特定的dll,则创建本地NuGet包.这些是我们在项目中遵循的生成NuGet包的步骤-

If it is project specific dll then create local NuGet package. These are the steps we followed in our project to generate NuGet package-

1.下载Nuget.exe并将其放置在.csproj文件所在的文件夹中.

1.Download Nuget.exe and place it in the folder where .csproj file exists.

2.打开cmd并键入nuget spec.将创建具有.nuspec扩展名的文件.

2.Open cmd and type nuget spec. File with .nuspec extension will be created.

3.打开创建的文件并添加标签:

3.Open the created file and add tag:

<files> <file src="..\..\SomeRoot\**\*.*" target="libs\net461" /> </files>

4.在cmd中执行nuget pack A.csproj –IncludeReferencedProjects.创建具有.nupkg扩展名的文件.

4.Execute nuget pack A.csproj –IncludeReferencedProjects in cmd. File with .nupkg extension gets created.

5.转到Visual Studio.在NuGet程序包管理器设置中,添加程序包源"并提供.nupkg.nuspec文件所在的路径.

5.Go to visual studio. In NuGet package manager settings, Add in "Package Sources" and provide path where your .nupkg and .nuspec file exists.

6.关闭Nuget程序包管理器,然后再次打开它.现在,您可以在创建的包源中的浏览"选项卡下找到它.

6.Close Nuget package manager and again open it. Now you can find it in your created package source under browse tab.

注意:您的.nuspec文件应类似于:

Note: Your .nuspec file should be like :

<?xml version="1.0"?>
<package  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <metadata  xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
    <id>ABC.XYZ.FL</id>
    <version>1.0.0.0</version>
    <title>ABC.XYZ.FL</title>
    <authors>ABC</authors>
    <owners>ABC</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Framework that will be used to create objects in XYZ world</description>
    <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
    <copyright>2016</copyright>
    <tags>ABC.XYZ.FL</tags>
  </metadata>
  <files>
    <file src="bin\Debug\*.dll" target="lib\net461" />
  </files>
</package>

以下链接包含有关创建nuget程序包并将其托管在本地的更多详细信息:

The following links contains more details about creating nuget package and hosting it locally:

https://docs.nuget.org/create/creating并发布一个包

https://docs.nuget.org/create/hosting -您自己的裸体饲料

https://docs.nuget.org/consume/nuget-config-file

看看这是否有帮助.