本文介绍了ASP.NET Core 1.0 (vNext) 中的引用库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 ASP.NET Core 1.0 (vNext).考虑到这一点,我有一个结构如下的解决方案:

I am learning ASP.NET Core 1.0 (vNext). With that in mind, I have a solution that is structured like this:

MySolution
  src
    MyLibrary
      MyClass.cs
      project.json
    MyWebSite
      Startup.cs
      project.json

我使用 dnu build 从命令行成功编译了 MyLibrary.我运行了生成 MyLibrary.1.0.0.nupkgdnu pack.还有两个文件夹:dnx451dnxcore50,它们都包含 MyLibrary.1.0.0.dll.我想在 MyWebSite 中使用 MyLibrary,但是,我很困惑.

I am successfully compiling MyLibrary from the command-line using dnu build. I ran dnu pack which generated MyLibrary.1.0.0.nupkg. There are also two folders: dnx451 and dnxcore50 which both contain MyLibrary.1.0.0.dll. I want to use MyLibrary in MyWebSite, however, I'm confused.

  1. 如何将MyLibrary包含"到MyWebSite 中?我是否手动复制 .dll 文件?如果有,是哪一个?我应该改用 nupkg 文件吗?这是一个私有程序集,我不想通过 NuGet 全局发布它.
  2. 我在 MyWebSite/project.json 中放什么来引用 MyLibrary 程序集?
  1. How do I "include" MyLibrary into MyWebSite? Do I manually copy over the .dll file? If so, which one? Should I use the nupkg file instead? This is a private assembly, I do not want to publish it globally via NuGet.
  2. What do I put in MyWebSite/project.json to reference the MyLibrary assembly?

推荐答案

如果不想与解决方案之外的其他人/项目共享包,则不必将包发布到 NuGet.您可以直接从源代码中引用包.

You don't have to publish the package to NuGet if you don't want to share it with other people/projects outside of your solution. You can just reference the package directly from source.

但是,如果这仍然不适合您,那么您有三个选择:

However, if that still doesn't work for you then you have three options:

  1. 使用 Roslyn 进行内部化.示例:project.json实际代码
  2. 您可以直接引用来源.示例 project.json
  3. 创建构建时依赖项.示例 project.json包的实际代码
  1. Internalize using Roslyn. Example: project.json and the actual code
  2. You can reference the sources directly. Example project.json
  3. Create a build time dependency. Example project.json and actual code for the package

这篇关于ASP.NET Core 1.0 (vNext) 中的引用库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 00:35