How to add reference to an external dll file in asp.net core project

一笑奈何 提交于 2019-12-11 07:58:42

问题


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 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.

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


回答1:


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.

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.Download Nuget.exe and place it in the folder where .csproj file exists.

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

3.Open the created file and add tag:

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

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

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.Close Nuget package manager and again open it. Now you can find it in your created package source under browse tab.

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>

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

https://docs.nuget.org/create/creating-and-publishing-a-package

https://docs.nuget.org/create/hosting-your-own-nuget-feeds

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

See if this helps.



来源:https://stackoverflow.com/questions/41198974/how-to-add-reference-to-an-external-dll-file-in-asp-net-core-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!