使用项目依赖项作为全局命令运行Dnx控制台应用程序

时间:2016-02-26 20:17:23

标签: c# asp.net dnx dnu

我有一个引用类库项目的DNX控制台应用程序。我试图发布它并将其安装为全局命令。

我在Windows 10操作系统上这样做。 Projects Tree

控制台项目Program.cs

namespace Vert.Commands
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var test = new ConsoleWriter();
            test.Talk("Test", ConsoleColor.Cyan);
        }
    }
}

控制台项目project.json

{
  "version": "1.0.0-*",
  "description": "Test App",
  "authors": [ "vrybak" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",
  "compilationOptions": {
    "emitEntryPoint": true
  },
  "dependencies": {
    "CommandLib": "1.0.0-*"
  },
  "commands": {
    "vm-test-job": "Vert.Commands"
  },
  "frameworks": {
    "dnx451": {}
  }
}

班级图书馆:CommandLib档案:ConsoleWriter

namespace CommandLib
{
    public class ConsoleWriter
    {
        public void Talk(string message, ConsoleColor color)
        {
            var currentColor = Console.ForegroundColor;
            Console.ForegroundColor = color;
            Console.WriteLine(message);
            Console.ForegroundColor = currentColor;
        }
    }
}

班级图书馆:project.json

{
  "version": "1.0.0-*",
  "description": "CommandLib Class Library",
  "authors": [ "vrybak" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",
  "frameworks": {
    "dnx451": { }
  }
}

我正在尝试安装全局命令vm-test-job 要做到这一点我

  1. cd进入src/Vert.Commands文件夹
  2. 将其作为包发布
  3. dnu publish --no-source -o artifacts\publish
  4. cd \artifacts\publish\approot
  5. dnu commands install .\packages\Vert.Commands\Vert.Commands.1.0.0.nupkg
  6. 当我尝试运行命令vm-test-job时,我收到错误消息 System.IO.FileNotFoundException: Could not load file or assembly 'CommandLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

    如何安装引用其他项目的控制台应用程序项目中的命令?

1 个答案:

答案 0 :(得分:1)

你试过做过......

dnu restore

...在安装命令之前?我认为dnvm需要在安装之前重建/重新打包您的依赖项。

看一下这个链接,它试图达到和我假设的相同。 http://blogs.msdn.com/b/sujitdmello/archive/2015/04/23/step-by-step-installation-instructions-for-getting-dnx-on-your-laptop.aspx