{"action":"created","issue":{"url":"https://api.github.com/repos/NuGet/Home/issues/300","labels_url":"https://api.github.com/repos/NuGet/Home/issues/300/labels{/name}","comments_url":"https://api.github.com/repos/NuGet/Home/issues/300/comments","events_url":"https://api.github.com/repos/NuGet/Home/issues/300/events","html_url":"https://github.com/NuGet/Home/issues/300","id":64978659,"number":300,"title":"[Verify/Document] Native (conditional) dependency support. ","user":{"login":"nathanaeljones","id":107935,"avatar_url":"https://avatars.githubusercontent.com/u/107935?v=3","gravatar_id":"","url":"https://api.github.com/users/nathanaeljones","html_url":"https://github.com/nathanaeljones","followers_url":"https://api.github.com/users/nathanaeljones/followers","following_url":"https://api.github.com/users/nathanaeljones/following{/other_user}","gists_url":"https://api.github.com/users/nathanaeljones/gists{/gist_id}","starred_url":"https://api.github.com/users/nathanaeljones/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nathanaeljones/subscriptions","organizations_url":"https://api.github.com/users/nathanaeljones/orgs","repos_url":"https://api.github.com/users/nathanaeljones/repos","events_url":"https://api.github.com/users/nathanaeljones/events{/privacy}","received_events_url":"https://api.github.com/users/nathanaeljones/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/NuGet/Home/labels/2%20-%20Working","name":"2 - Working","color":"CCCCCC"},{"url":"https://api.github.com/repos/NuGet/Home/labels/Priority:1","name":"Priority:1","color":"fbca04"},{"url":"https://api.github.com/repos/NuGet/Home/labels/Type:Docs","name":"Type:Docs","color":"207de5"}],"state":"open","locked":false,"assignee":{"login":"MeniZalzman","id":9874966,"avatar_url":"https://avatars.githubusercontent.com/u/9874966?v=3","gravatar_id":"","url":"https://api.github.com/users/MeniZalzman","html_url":"https://github.com/MeniZalzman","followers_url":"https://api.github.com/users/MeniZalzman/followers","following_url":"https://api.github.com/users/MeniZalzman/following{/other_user}","gists_url":"https://api.github.com/users/MeniZalzman/gists{/gist_id}","starred_url":"https://api.github.com/users/MeniZalzman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MeniZalzman/subscriptions","organizations_url":"https://api.github.com/users/MeniZalzman/orgs","repos_url":"https://api.github.com/users/MeniZalzman/repos","events_url":"https://api.github.com/users/MeniZalzman/events{/privacy}","received_events_url":"https://api.github.com/users/MeniZalzman/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/NuGet/Home/milestones/16","html_url":"https://github.com/NuGet/Home/milestones/3.2","labels_url":"https://api.github.com/repos/NuGet/Home/milestones/16/labels","id":1232564,"number":16,"title":"3.2","description":"3.2 client high priority bug fixes from feedback in 3 through 3.1.1 releases","creator":{"login":"emgarten","id":6381138,"avatar_url":"https://avatars.githubusercontent.com/u/6381138?v=3","gravatar_id":"","url":"https://api.github.com/users/emgarten","html_url":"https://github.com/emgarten","followers_url":"https://api.github.com/users/emgarten/followers","following_url":"https://api.github.com/users/emgarten/following{/other_user}","gists_url":"https://api.github.com/users/emgarten/gists{/gist_id}","starred_url":"https://api.github.com/users/emgarten/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emgarten/subscriptions","organizations_url":"https://api.github.com/users/emgarten/orgs","repos_url":"https://api.github.com/users/emgarten/repos","events_url":"https://api.github.com/users/emgarten/events{/privacy}","received_events_url":"https://api.github.com/users/emgarten/received_events","type":"User","site_admin":false},"open_issues":5,"closed_issues":68,"state":"open","created_at":"2015-07-29T23:37:18Z","updated_at":"2015-11-16T21:48:38Z","due_on":"2015-09-03T07:00:00Z","closed_at":null},"comments":36,"created_at":"2015-03-28T19:25:37Z","updated_at":"2015-11-20T01:22:50Z","closed_at":null,"body":"Originally [posted on Paket](https://github.com/fsprojects/Paket/issues/714), but since this is something NuGet is considering as well, I'm adding it here so we can track and (hopefully sync efforts). I hear that the ASP.NET team is doing something with native  dependencies, but I can't find a spec for it. I suspect that a lockfile and transitive dependency support are pre-requisites for this. \r\n\r\nA lot has been written about this (challenging) topic; so I'll link to what I've found (and please add more links in the comments).\r\n\r\n* https://stackoverflow.com/questions/19478775/add-native-files-from-nuget-package-to-project-output-directory\r\n* https://github.com/aspnet/dnx/issues/402\r\n* https://nuget.codeplex.com/workitem/1221\r\n* https://nuget.codeplex.com/workitem/679\r\n* https://nuget.codeplex.com/discussions/412012\r\n* http://ilnumerics.net/blog/anycpu-computing-limping-platform-specific-targets-and-a-happy-deployment-end/\r\n* http://youku.io/questions/392214/nuget-powershell-how-to-add-native-dependencies-how-to-add-files-to-a-project\r\n* https://nuget.codeplex.com/discussions/446656\r\n* https://github.com/MvvmCross/MvvmCross/issues/307\r\n* https://nuget.codeplex.com/discussions/286521\r\n* https://nuget.codeplex.com/discussions/230521\r\n* https://nuget.codeplex.com/workitem/109\r\n\r\nI've been using a https download-during-boot approach for ImageResizer, but that is slow, unreliable, and annoying. I tried to [create an example of how to build the ideal native/managed hybrid project](https://github.com/imazen/paragon), failed, then [started a project to try to hot-fix the problem at runtime](https://github.com/imazen/Imazen.NativeDependencyManager), and [hit another series of roadblocks](https://github.com/imazen/Imazen.NativeDependencyManager/issues/5). \r\n\r\nI've identified a few invalid assumptions that seem responsible for the current state of things. \r\n\r\nSome of these are somewhat comical considering [how easy it is to parse binaries for the major platforms and determine runtime compatibility](https://github.com/imazen/Imazen.NativeDependencyManager). \r\n\r\n1. It is bad to assume all *managed* dlls are AnyCPU. x86 and x64-only binaries continue to have an important place. a) C++/CLI is still important, but only targets Win32 and x64. b) [Binding generation tools like CppSharp](https://github.com/mono/CppSharp)  cannot produce AnyCPU C# - the structure layouts (and other details) are calculated based on a pointer width assumption.  c) There's also manually written C# that uses unsafe code or performs P/Invokes, and doesn't use IntPtr in all the right places, and is therefore x86 or x64-only.\r\n\r\n2. It is bad to assume that precompiled native binaries are appropriate for every operating system distribution. Source compilation needs to be first-class if we want to target a large number of linux or bsd distributions; we can't precompile for everything.\r\n\r\n3. It is bad to assume that binaries are small enough that all the permutations can go in the same zipped nuget package.  OpenCV base libraries could easily be > 2 gigabytes if you did this. You'd also exhaust your server's disk space. And likely your bandwidth allotment. And requests would time out.\r\n\r\n4. It is bad to assume that a windows machine is capable of compiling native code.\r\n\r\n-----\r\n\r\nRemoving these assumptions, what new requirements are we left with? \r\n\r\n1. Nuget packages need to be able to reference other nuget packages - conditionally - based on architecture and operating system. This likely means that we need conditions in the lockfile, too - use version X of package Y on platform Z, etc. At build time, the right versions are copied.\r\n\r\n2. Nuget packages need to be able to describe native binaries - or rather - arbitrary files, and provide multiple versions for each target platform.  For small binaries, a common pattern is likely to combine these two approaches, and provide x86/x64 binaries for windows, and a conditional reference for other platforms. For larger binaries, it's likely that the 'main' package will be empty, and simply list conditional, plat-specific packages as dependencies.\r\n\r\n3. Build time. This is a bit harder. What needs to happen?\r\na) We need to gather the referenced files (nuget references, mind you), and verify that the output folder does not have any conflicting named files. If there are conflicting names, the output folder version MUST be deleted, so that we can AssemblyResolve or LoadLibrary the correct version. We then copy each of the files to an appropriate subfolder of the output folder (or, if AnyCPU, the output folder itself).  Since VisualStudio is blind to compatibility (by choice, one must assume), we may end up fighting with the build process a bit. Perhaps disabling copylocal? Another nice sanity check would be to simply parse the binary headers of everything in the output folder and ensure they are all able to run on a common environment. \r\n\r\n4. Run time. This is where developers have to do a little magic, and call AssemblyResolve for non-AnyCPU managed dlls, and LoadLibrary (or a platform alternative) for the native dependencies. Given a standardized convention, we can make this co-operation possible without .NET runtime changes (although not optimal, since Assembly.Load won't use the default security context). It would be much better if .NET would modify the search path based on platform, as it does for culture. It would also be great if ASP.NET would apply some intelligence or header parsing to assemblies before globbing them all into memory. It's not hard, and only requires between 1 and 3 I/O reads of a few hundred bytes.\r\n\r\n5. Tooling. Tooling needs to understand that there are non-.NET dependencies involved. Unit test runners, in particular, are known for leaving behind native dependencies when they copy (or shadow copy) assembles for testing. These will need to understand the (transitive) dependencies. Perhaps we should emit some kind of manifest? While we can piggy-back on .NET assemblies to document dependencies (via resource manifests or regular assembly attributes), those .NET assemblies would need to document the final transitive set of native dependencies, which might be difficult to achieve. \r\n\r\n\r\nSo, I guess \r\n\r\n* Step 1: Establish (a) plat/arch conditions, and (b) target strings we can use as subfolders.\r\n* Step 2: Describe required changes to the nuget package specification\r\n* Step 3: Implement handling in paket for nuget conditions and native file manifests, through to lockfile.\r\n* Step 4: Implement paket support for triggering bash/.bat build scripts (perhaps requiring user authorization on a per-commit-id basis, if applied to a git reference)? CMake is probably most likely to be used, but if we require Git, we can require Bash.\r\n* Step 5: Implement build-time support for copying and manifest generation.\r\n* Step 6: Submit PRs to major runners and web frameworks to handle manifests and assembly loading properly.\r\n* Step 7: Make .NET into a real platform, where C interop is practical, so we can play with the big kids.\r\n\r\n### Conditions:\r\n\r\n* pointerSize=32|64. Let's say that our MSIL makes an assumption about pointer size, but not platform.\r\n* endianess=\"little|big\" Sometimes this matters more than architecture, and ARM can switch between endianess modes.\r\n* architecture=x86|x64|IA64|Alpha|MIPS|HPPA|PowerPC|SPARC32|s390|s390x  - Should probably support everything [Mono does](http://www.mono-project.com/docs/about-mono/supported-platforms/)\r\n* os=\"posix|winish|linux|osx|win7|win8|win10\" I'm not sure how to best divide windows (or linux) operating systems into groups, or to number them for easy inequality testing, but we probably want to establish sane identifiers that correspond to common build/api compat targets.\r\n\r\nGiven that a fallback mode (building from source) is likely popular, we want to make it easy to ensure that only 1 reference from a conditional set is chosen. We should probably group them within another element or provide an id that prevents duplicates. \r\n\r\n### Target strings \r\n\r\nTarget string need to be as generic as can be permitted based on their restrictions. \r\n\r\n/  - root is AnyCPU\r\n/32b/ - managed, assumes 32-bit pointer, otherwise portable\r\n/64b/ - managed, assumes 64-bit pointer, otherwise portable\r\n/x86/winish/ - 32-bit, requires windows APIs. \r\n\r\npointer size, architecutre, and endianess are combined into the first string. Pointer size and endianess are only included if the architecture string doesn't make them redundant. I.e, we would see /ARM-little/ and /ARM-big/, but not /x86-little/. \r\n\r\n<!---\r\n@huboard:{\"order\":2064.84375,\"milestone_order\":300,\"custom_state\":\"\"}\n-->\r\n"},"comment":{"url":"https://api.github.com/repos/NuGet/Home/issues/comments/158250363","html_url":"https://github.com/NuGet/Home/issues/300#issuecomment-158250363","issue_url":"https://api.github.com/repos/NuGet/Home/issues/300","id":158250363,"user":{"login":"jasonwilliams200OK","id":2031765,"avatar_url":"https://avatars.githubusercontent.com/u/2031765?v=3","gravatar_id":"","url":"https://api.github.com/users/jasonwilliams200OK","html_url":"https://github.com/jasonwilliams200OK","followers_url":"https://api.github.com/users/jasonwilliams200OK/followers","following_url":"https://api.github.com/users/jasonwilliams200OK/following{/other_user}","gists_url":"https://api.github.com/users/jasonwilliams200OK/gists{/gist_id}","starred_url":"https://api.github.com/users/jasonwilliams200OK/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasonwilliams200OK/subscriptions","organizations_url":"https://api.github.com/users/jasonwilliams200OK/orgs","repos_url":"https://api.github.com/users/jasonwilliams200OK/repos","events_url":"https://api.github.com/users/jasonwilliams200OK/events{/privacy}","received_events_url":"https://api.github.com/users/jasonwilliams200OK/received_events","type":"User","site_admin":false},"created_at":"2015-11-20T01:22:50Z","updated_at":"2015-11-20T01:22:50Z","body":"@impinball, like @nathanaeljones noted:\r\n\r\n> It is bad to assume that a windows machine is capable of compiling native code.\r\n\r\nHere is a shining example: https://github.com/nodejs/node-gyp/issues/629 with a [glimpse of hope](https://github.com/nodejs/node-gyp/issues/629#issuecomment-153196245) (in the form of Build Tools 2015 without VS).\r\n\r\nIn npm's case, it is assumed that all Unix-like operating system are packed with C/C++ compilers, while on Windows only MSBuild is supported by node-gyp. The approach you mentioned about phantomJS (and node-sass) is good that prepare the binaries for as many OSs and arch as you can and for the remaining fallback to default node-gyp's compiler from source at installation time behavior, but at the same time, too much work for the maintainer to verify and test binaries on all possible OS and architectures.\r\n\r\nIn my experience, most people are happy if they just do `npm install package` and get things rolling, preferably without compilation step. Even on Unix-likes, npm+node-gyp's advertised approach to compile on the fly fails when we use relatively new feature-set of native languages which some Linux distribution's version's out of the box compilers might not support (CentOS-5.11 which many hosting environments are running till date packs with gcc 4.4, which does not even support `nullptr`!). So every maintainer of the package (should) have to mandate the minimum C/C++ compilers' version on target as well, which does not inspire many consumers..\r\n\r\nNuGet may experience a totally different trend of packaging stuff if this ongoing relevant discussion in CoreFX repo: https://github.com/dotnet/corefx/issues/2302#issuecomment-156132918 get popular."}}