如何将对本地创建的NON ASP.Net 5 dll的引用添加到ASP.Net 5项目 [英] How do you add references to locally created NON ASP.Net 5 dlls to an ASP.Net 5 project

查看:108
本文介绍了如何将对本地创建的NON ASP.Net 5 dll的引用添加到ASP.Net 5项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

asp.net主页Wiki 出现表示可以通过 bin包装为本地生成的dll(程序集)添加引用。但是,似乎project.json文件中可能仅包含一个bin包装器。那么,将引用添加到针对.net framework 4.6和可移植库.net framework 4.6编译的外部类库dll的正确方法是什么?

The asp.net home wiki appears to indicate that one can add references to locally produced dlls (assemblies) via the "bin" wrapper. However, it appears that only one bin wrapper may be included in a project.json file. So, what is the correct way to add references to external class library dlls compiled against .net framework 4.6 and portable library .net framework 4.6?

BTW。这些DLL与ASP.Net项目不在同一解决方案中。

BTW. These DLLs are not in the same solution as the ASP.Net project.

推荐答案

一年后,我能够获得对包含和编译的非本地dll的引用。有一些遗漏和误解的步骤需要遵循。

Nearly a year later, I was able to get a reference to a non-local dll included and compiled against. There are some missing and mis-understood steps that need to be followed.

在过去的一年中,我找不到许多以前命名的版本DNX实用程序。就在最近,我发现了一篇文章,说您必须运行DNVM才能选择运行时的版本。完成后,将DNX的路径放置在path变量上。别忘了在此时启动新的CMD(或PowerShell)副本以选择新的环境变量。另请注意,.dnx文件夹是隐藏文件夹,除非您已关闭隐藏隐藏文件夹,否则不会使用dir命令或在Windows资源管理器中显示。有关运行DNVM的更多讨论,请参见堆栈溢出问题 DNX不起作用

Along my journey over the past year, I could not find any of the many previously named versions of the DNX utility. Just recently, I found an article that says you must run DNVM to pick a version of the runtime. Once that is done, the path to DNX is placed on the path variable. Do not forget to start a new copy of CMD (or PowerShell) at that point to pick up the new environment variable. Also note that the .dnx folder is a hidden folder and will not show with a dir command or in windows explorer unless you have turned off hide hidden folders. See Stack Overflow question "DNX does not work" for more discussion about running DNVM.

一旦设置了dnx环境,便可以运行dnu wrap。第一个问题是解决方案文件夹中必须有global.json文件。默认情况下,不会创建此文件,并且该文件的内容将不存在。该文件中需要包含的信息很少。

Once the dnx environment is setup, dnu wrap can be run. First problem is that you must have a global.json file in the solution folder. This file is not created by default and the documentation for what should be in it is next to non-existent. The file needs to have minimal information in it.

{
"projects": [
    "web"
    ],
"sdk": {
    "version": "1.0.0-rc1-update1",
    "runtime": "clr",
    "architecture": "x86"
    }
}

web 是解决方案中唯一项目的名称。其他可以根据需要添加。创建完成后,将解决方案目录作为当前目录,然后发出dnu wrap命令。

In my example, web is the name of the only project in the solution. Others may be added as required. Once created make the solution directory the current directory and then issue a dnu wrap command.

dnu wrap full_path_to_an_assembly -f framework_version

说实话,我不确定框架版本可以/应该加入什么。我使用了dnx461 ,因为那是我编译dll所依据的框架版本。 dnu wrap操作的输出将进入solution文件夹下的 wrap文件夹,并且global.json文件将被更新,以在项目部分中包含wrap项目(文件夹)。

To be honest, I am not completely sure of what can/should go in as the framework version. I used dnx461 as that was the version of the framework against which I had compiled the dlls. The output of the dnu wrap operation will go into the "wrap" folder under the solution folder and the global.json file will be updated to include the wrap project (folder) in the projects section.

由于在每个新解决方案中都包含多个dll的过程似乎很繁琐,因此我手动创建了用于包装的project.json文件,并将其放置在全局位置(通常.net程序集将引用它们)。然后,我将该文件夹的完整路径作为一个项目放置在global.json文件中,并且能够添加引用并进行编译。一个问题是,即使支持相对路径,它们之间的相对关系似乎也有些混乱。我必须在提供二进制包装的project.json文件中包括二进制文件(和pdbs)的完整路径。
用于包装二进制文件的示例project.json

Since this process seemed like a lot of work for including several dlls in every new solution, I manually created the project.json files for the wrapping and placed them in a global location (right next to from which a normal .net assembly would reference them). I then placed the full path to that folder as a project in the global.json file and I was able to add references and compile. One issue was that even though relative paths are supported, there appears to be some confusion as to what they are relative too. I had to include the full path of the binaries (and pdbs) in the project.json files that provide the binary wrapping. Example project.json for wrapping a binary

  {
    "version": "1.0.0-*",
    "frameworks": {
      "dnx461": {
        "bin": {
          "assembly": "../../bin/log4net.dll"
          }
        }
      }
  }

请注意上面相对路径的使用。那不能正常工作。将其更改为所讨论程序集的完整路径。

Note the use of the relative path above. That does not work correctly. Change that to a full path to the assembly in question.

好消息是,一旦一切都正确设置,就可以在Visual Studio中对项目的依赖项进行智能感知。 .json将在您键入dll时指示其名称。

The good news, is that once everything is setup correctly, intellisense in Visual Studio for the dependencies section of the project.json will indicate the name of the dll as you type it in.

这篇关于如何将对本地创建的NON ASP.Net 5 dll的引用添加到ASP.Net 5项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆