繁体   English   中英

使用“ global.json”项目属性解决依赖关系

[英]Resolving dependencies using “global.json” projects property

Asp.Net Core项目上工作并使用“ global.json ”获取外部依赖关系似乎工作了一段时间。 但是最近它停止工作了。 外部库不会进入解决方案资源管理器视图。

为了弄清楚发生了什么,我建立了一个简单的示例。 以下是我使用的各种文件和过程:

名为MyProject的项目。

使用的sdk版本如下所示:

~\MyProject> dotnet --info
  .NET Command Line Tools (1.0.0-preview2-1-003177)
  Product Information:
   Version:            1.0.0-preview2-1-003177
   Commit SHA-1 hash:  a2df9c2576
  Runtime Environment:
   OS Name:     Windows
   OS Version:  10.0.14393
   OS Platform: Windows
   RID:         win10-x64*

“ MyProject的” 解决方案资源管理器视图

Solution 'MyProject' (1 project)
   Solution Items
  global.json
   src
      MyProject
        Properties
        References
        Program.cs
        project.json

项目的program.cs源代码:

namespace MyProject
{
   public class Program
   {
       public static void Main(string[] args)
       {
           var Var1 = new MyLib();
           Console.WriteLine($"{Var1.VariableOne}");
       }
   }

}

project.json文件:

{
  "version": "1.0.0-*",
  "buildOptions": {
   "emitEntryPoint": true
  },

  "dependencies": {
    "Microsoft.NETCore.App": "1.0.1"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": "dnxcore50"
    }
  }
}

global.json文件:

{
  "projects": [ "src", "../MyLibrary/src" ],
  "sdk": {
    "version": "1.0.0-preview2-1-003177"
  }
}

图书馆项目名为: MyLibrary

使用的sdk版本:

~\MyLibrary\src\MyLibrary>dotnet --info

.NET Command Line Tools (1.0.0-preview2-1-003177)

Product Information:
 Version:            1.0.0-preview2-1-003177
 Commit SHA-1 hash:  a2df9c2576

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64

“ MyLibrary” 解决方案资源管理器视图

Solution 'MyLibrary' (1 project)
 > Solution Items
    > global.json
 > src
    > MyLibray
        > Properties
        > References
        > Class1.cs
        > project.json

“ MyLibrary” class.cs代码:

namespace MyLibrary
{
    public class Class1
    {
        public string VariableOne { get; set; } = "MessageOne";
        public int MyProperty { get; set; }
    }
}

“ MyLibrary” global.json文件为:

{
  "projects": [ "src", "test" ],
  "sdk": {
    "version": "1.0.0-preview2-1-003177"
  }
}

在命令行中将库打包的步骤如下:

 > cd src\MyLibrary
 > dotnet pack

以下是包装的结果:

~\MyLibrary\src\MyLibrary\bin\Debug>dir
12/14/2016  06:33 PM             2,926 MyLibrary.1.0.0.nupkg
12/14/2016  06:33 PM             5,264 MyLibrary.1.0.0.symbols.nupkg
12/14/2016  06:22 PM    <DIR>          netstandard1.6

鉴于以上所有这些,在我设法开始工作之前,现在,当我尝试恢复“ MyProject”的引用时,“ MyLibrary”软件包不会被使用。 解决方案资源管理器与以前相同(当然,“ Class1”引用仍未解决)。

我忘了提到我正在使用VS 2015社区。

任何建议,将不胜感激。

好吧,弄清楚我所缺少的。 在MyProject的project.json文件中,我需要添加以下依赖项:

"MyLibrary": {
    "target": "Project",
    "version": "*"
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM