【问题标题】:Running a Dnx Console App with Project Dependencies as Global Command将项目依赖项作为全局命令运行 Dnx 控制台应用程序
【发布时间】:2016-02-26 20:17:23
【问题描述】:

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

我在 Windows 10 操作系统上执行此操作。

控制台项目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

当我尝试运行我的命令 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.

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

【问题讨论】:

  • 欢迎来到 StackOverflow。请您指定操作系统(我猜是 Windows),您使用的框架版本。谢谢。
  • 您是否指定了此处指定的依赖项:docs.asp.net/en/latest/dnx/projects.html#adding-dependencies
  • 我确实指定了我的依赖项,在我的 project.json 文件中查看它们

标签: c# asp.net dnx dnu


【解决方案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

【讨论】:

  • 我之前也尝试过还原。如果依赖包不存在,它不会让我发布它。问题是当我尝试安装全局命令时,dnx 不知道在哪里可以找到项目引用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多