在.NET vNext引用本地项目时,同名的NuGet包发布 [英] Reference local project in .net vNext when a nuget package of the same name is published

查看:109
本文介绍了在.NET vNext引用本地项目时,同名的NuGet包发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立新vNext项目类型包VS 2015年。

我想引用相同的解决方案项目(这是不vNext),但其试图找到一个包的NuGet该项目,而不是直接引用它。

我在做什么错了?

  {
    版本:1.0.0- *,
    依赖:{
        Microsoft.AspNet.Mvc:6.0.0.0-β2
    },
    构架: {
        aspnet50:{
            依赖:{
                响应://它不能找到一个包,这个即使我有一个项目在我的解决方案命名为
            }
        },
        aspnetcore50:{
            依赖:{
                System.Runtime:4.0.20-β-22231
            }
        }
    }
}

项目结构:

 解决方案文件夹
  - SRC
    - global.json {来源:]}
    - 阵营(项目文件夹)
    - 我的图书馆(项目文件夹)
  - 斌
    - 调试
      - 阵营


解决方案

答案很简单::您需要一个 net45 配置添加到您的 project.json 在这里你可以再加入阵营依赖(假设它是一个 net45 二进制)。

注:的我已经更新了的简答的以反映新加入的问题的信息。下面长的答案是纯粹的信息。

这是依赖解析简介:
要注意的重要一点是,在vNext(ASP.NET 5)Visual Studio是没有必要的。因此,我们不能以这是我的解决方案,因为这是一个Visual Studio概念方面想的事情,一切都被设计为工作的Visual Studio之外。

所以,让我们先说说有什么可以从项目中vNext中引用:


  1. 的包。

  2. 来源$ C ​​$ C(字面.CS文件),只要有一个project.json。

  3. 的DLL。

我认为这一切,但我可​​以忘记。

现在这里的美妙之处在于它们的引用都可以互换。这意味着你的另外的依赖响应的:可以引用一个DLL,包或源$ C ​​$ C(来源$ C ​​$ C具有最高优先级,如果有冲突)。需要注意的是留下版本基本上意味着1.0或来源$ C ​​$ C。

现在为止看完这个你可能在想,O.K.酷我只写了这个问题,说我有冲突,为什么不是我的依赖关系正确解决?所以第一关有两种方式提供,您可以添加一个依赖关系。

为有效的源$ C ​​$ C /项目的位置

  1. 表现:会尽可能找到code你周围自动地

  2. 指定:提供一个global.json指示到哪里寻找源$ C ​​$ C

90%,你应该使用#2时,其中#1,你应该使用纯粹是为了演示:)如果你能避免它。

哪里一个global.json去了?在父母的文件夹。结果
中有什么global.json 所有你需要的是有效的JSON,它可以是这个样子:

  {
    来源:SRC,测试]
}

通过这个global.json,在的src 测试的所有源$ C ​​$ C 文件夹都将被发现

又名:

   -  global.json
- / src目录
- > A.cs
- /测试
- > B.cs

这种类型的文件夹结构的例子: https://github.com/aspnet/Mvc

希望这有助于!

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

解决方案

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!

这篇关于在.NET vNext引用本地项目时,同名的NuGet包发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆