简体   繁体   中英

Resolving dependencies using “global.json” projects property

Working on an Asp.Net Core project and using " global.json " to pull in external dependencies, seemed to work for a while. But lately it stopped working. The external library does not get pulled into the solution explorer view.

In my effort to figure out what is going on, I setup a trivial example. Below are the various files and procedures I used:

The Project named is MyProject .

The sdk version used is shown below:

~\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*

The "MyProject's" solution explorer view :

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

The project's program.cs source code:

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

}

The project.json file:

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

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

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

The global.json file:

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

The Library project is named: MyLibrary

The version of sdk used:

~\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

The "MyLibrary" solution explorer view :

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

The "MyLibrary" class.cs code:

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

The "MyLibrary" global.json file is:

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

The steps followed for packaging the library in the command line:

 > cd src\MyLibrary
 > dotnet pack

And below is the result of packaging:

~\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

Given all the above, which before I managed to get working, now, when I try to restore the references for "MyProject", the "MyLibrary" package does not get picked up. The Solution explorer remains the same as per before ( and of course the "Class1" reference remains unresolved).

I forgot to mention that I am using VS 2015 community.

Any suggestions would be appreciated.

OK, just figure out what I was missing. In the project.json file of MyProject, I needed to add the following dependency:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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