What is the expected behaviour of parent-relative directories in global.json?
Asked Answered
A

1

28

(Now raised as DNX issue 3206...)

DNX environment: 1.0.0-rc1, Windows 10 x64.

Imagine I have three solutions:

  • Application1
  • Application2
  • Common

Each of these solutions has multiple projects in; it wouldn't make sense to have all the projects in a single solution, even though that would simplify this particular issue.

Various projects in Application1 and Application2 depend on a project in Common. Their project.json files indicate that dependency in a normal way. While eventually I'd like to publish the artifacts from Common to a NuGet server (internal or external), it makes sense to temporarily just build everything from source.

I can do that by editing global.json within (say) Application1 to have:

{
  "projects": [ "src", "test", "../Common/src" ], 
  "sdk": { "version": "1.0.0-rc1-final"  }
}

With that in place, I can perform a dnu restore from the Application1 directory... but not from the root directory. (The error is "Unable to locate Dependency 'Common' >= 0.0.0-*".) I can run dnu restore Application1 from the root directory, but not just dnu restore.

I've tried numerous ways to refer to the Common src directory (including "./Common/src", "Common/src", "../repo-name/Common/src"), but haven't had any joy yet. In every case, I get the error message shown above. I've tried using dnu -v restore but that didn't appear to give any extra information about which directories were being probed for source-based packages.

So, how should the "../Common/src" be resolved in global.json? Is this a resonable approach to the development scenario I've described, and if so is it just a matter of filing a bug against DNX?

Aerostatics answered 25/11, 2015 at 14:37 Comment(10)
I'm still learning, but shouldn't you only have one global.json file and it be at the root?Voile
@KhalidAbuhakmeh: One per solution. This is a case of multiple solutions, each with multiple projects. Will clarify the question.Aerostatics
No experience in global.json (or dnx); but in general, I try to avoid relative references like "../folder" because are problematic in different contexts. Have you tried to store the Common/src contents inside the folder of the given application and refer to it without the "../" part? Just for testing. To see if this is the problem.Earlineearls
@varocarbas: I'm sure that would be fine, but not helpful for file organizational purposes. I'm only expecting that the layout in the file system will match the layout in the repo - there's no cross-repo expectations here.Aerostatics
It was a suggestion for mere testing purposes (to remove potential sources of error; not saying that files cannot locate anywhere, just that perhaps the way you used to refer the path is not supported). For example, PHP's require/include doesn't allow this format. Anyway... I am sure that you know much more than me about all this. Just trying to help.Earlineearls
@jon-skeet, your expectation sounds reasonable to me. I would file a bug. :-)Archenteron
Hmm well I guess you could get around it by making a symbolic link in the filesystem. Considering you said this was temporary that shouldn't be too big an ask.Tapp
@Michael: It probably would, but there's no way I'm going to stoop that low :) (This really has to work wherever you happen to check out the repo, and on whatever operating system.)Aerostatics
@JonSkeet I presume that comment was meant to be directed at me ;) Step it up an extra evil level, pre-build task to create the symbolic link if it doesn't exist. </sarcasm>Tapp
@laurencee: Not sure. It's possible it was aimed at a now-deleted comment...Aerostatics
M
7

It doesn't work the way you expect it, when you start dnu restore it tries to find global.json in current or parent directories, and reads project path from it. So in your example it doesn't read anything because global.json is in sub-directory.

One way to solve this problem is to add global.json to root folder with the following content:

{
   "projects": [ "Application/src", "Common/src" ]
}

I will ask around about this scenario and if it might change when moving to dotnet cli

Mcdavid answered 25/11, 2015 at 18:58 Comment(2)
So it only looks for project.json when searching child directories? That would make sense of the behvaviour, but seem an odd design choice. Will experiment though - thanks!Aerostatics
Right, having played a bit more, I think this is exactly the problem. Will amend the issue appropriately :)Aerostatics

© 2022 - 2024 — McMap. All rights reserved.