Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

dnx

dnu

(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?

like image 763
Jon Skeet Avatar asked Nov 25 '15 14:11

Jon Skeet


People also ask

Which symbol represents the parent directory in relative pathnames?

The dot dot (..) represents the parent directory. Because relative path names specify a path starting in the current directory, they do not begin with a slash (/).

What is a relative directory?

A relative path refers to a location that is relative to a current directory. Relative paths make use of two special symbols, a dot (.) and a double-dot (..), which translate into the current directory and the parent directory. Double dots are used for moving up in the hierarchy.

What is absolute and relative path in Linux?

An absolute path is the full path to a file or directory. It is relative to the root directory ( / ). Note that it is a best practice to use absolute paths when you use file paths inside of scripts. For example, the absolute path to the ls command is: /usr/bin/ls . If it's not absolute, then it's a relative path.

How does relative path work in Python?

A relative path starts with / , ./ or ../ . To get a relative path in Python you first have to find the location of the working directory where the script or module is stored. Then from that location, you get the relative path to the file want.


1 Answers

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

like image 138
Pavel Krymets Avatar answered Sep 19 '22 09:09

Pavel Krymets