undefined
undefined

Reputation: 34299

Reference local project in .net vNext when a nuget package of the same name is published

I am trying to build a package with the new vNext project type in VS 2015.

I would like to reference a project in the same solution (which isn't vNext) but its trying to find a nuget package for that project rather than directly referencing it.

What am I doing wrong?

{
    "version": "1.0.0-*",
    "dependencies": {
        "Microsoft.AspNet.Mvc": "6.0.0.0-beta2"
    },
    "frameworks": {
        "aspnet50": {
            "dependencies": {
                "React": "" //it cant find a package for this even though I have a project named this in my solution
            }
        },
        "aspnetcore50": {
            "dependencies": {
                "System.Runtime": "4.0.20-beta-22231"
            }
        }
    }
}

Project structure:

Solution Folder
 - src 
   - global.json {"sources": [""]} 
   - React (project folder)
   - My Library (project folder)
 - bin
   - Debug
     - React

Upvotes: 2

Views: 1692

Answers (2)

N. Taylor Mullen
N. Taylor Mullen

Reputation: 18301

Short Answer: You need to add a net45 configuration to your project.json where you can then add the React dependency (assuming its a net45 binary).

NOTE: I've updated the Short Answer to reflect new information added to the question. The long answer below is purely informational.

Info on Dependency Resolution: An important thing to note is that in vNext (ASP.NET 5) Visual Studio is not necessary. Therefore we can't think of things in terms of "it's in my solution" since that's a Visual Studio concept and everything is designed to work outside of Visual Studio.

So, lets first talk about what can be referenced from a project in vNext:

  1. A package.
  2. Source code (literally .cs files) as long as there's a project.json.
  3. A dll.

I think that's everything but I could be forgetting.

Now the beauty here is that their references are all interchangeable. Meaning your addition of the dependency "React": "" can reference a dll, package, or source code (source code has the highest priority if there's conflicts). Note that leaving the version as "" essentially means "1.0" OR source code.

Now after reading this far you're probably thinking, o.k. cool I just wrote this issue saying I have a conflict, why aren't my dependencies resolving correctly? So first off there are two ways to provide locations for valid Source Code/projects that you can add a dependency to.

  1. Implied: Tries its best to finds the code around you automagically
  2. Specified: Provide a global.json to indicate where to look for source code.

90% of the time you should be using #2 where #1 you should be using purely for demos :) if you can avoid it.

Where does a global.json go? In a parents folder.
What's in a global.json? All you need is valid json, it can look something like this:

{
    "sources": ["src", "test"]
}

With this global.json, all source code in the src and test folder will be discovered.

Aka:

- global.json
- /src
-> A.cs
- /test
-> B.cs

Examples of this type of folder structure: https://github.com/aspnet/Mvc

Hope this helps!

Upvotes: 4

aidrivenpost
aidrivenpost

Reputation: 1943

If you using VS2015 CTP there is an option to create the nuget package automatically, by checking the produce outputs on build in the project property/build section. The nuget package will be create in the artifact folder of the solution you will need to manually push those your nuget server.

Regarding what project you can add as reference is a little bit tricky. This is what I did. I created 5 projects 2 using vs2013 and 3 using vs2015 the last one is a web project to test project reference.

Only C# project are allow as reference, VB projects for now are not supported. Assuming that you have a class library that was create on 2013 you can add those to your VS2015 solution without an upgrade (so far) then you can add those as reference to others vNext projects but will not work aspnet5core.

VNExt Project Reference Nuget Packages Creates VS2015 Options to create nuget packages

Upvotes: 2

Related Questions