Nuget解决本地文件中的依赖项 [英] Nuget Resolve dependencies from local files

查看:431
本文介绍了Nuget解决本地文件中的依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含四个项目,三个PCL和一个WinRT的解决方案.我设法分别为每个程序创建一个nuget程序包,但是,我想为所有程序包都做一个程序包,但是它们之间存在外部依赖关系,而且它们之间也存在依赖关系,因此我不知道如何解决它们.我发现外部依赖项是这样的:

I have a solution with four projects, three PCL and one WinRT. I've managed to create a nuget package for each one, individually, however, I want to do a single package for all of them, but there are external dependencies and also dependencies between them and I do not know how to resolve them. What I found for external dependencies is something of the like:

<?xml version="1.0"?>
(...)
    <dependencies>
      <dependency id="SampleDependency" version="1.0" />
    </dependencies>
(...)
</package>

但是如何指定本地依赖项?
您可以在此处查看结构图: http://i.imgur.com/AlotgHy.png

But how can I specify local dependencies?
You can see a diagram of the strucure here: http://i.imgur.com/AlotgHy.png

推荐答案

我找到了通过Visual Studio Extension项目执行此操作的方法,但是由于问题是针对Nuget的,因此我将在Nuget中发布如何解决此问题. br> 由于我在一个PCL中具有视图,因此事情变得有些复杂,但是当我找到所需的文件和文件结构时,就很容易了.结构如下:

I found a way of doing this with the Visual Studio Extension project, however since the question is for Nuget I'll post how I solved this in Nuget.
Since I had views in one of my PCL, things were getting a little complicated, but when I found what files I needed and file structure it was easy. Here's the structure:

所以这个想法实际上很简单,在这种情况下,我想将所有内容都放在.dlls中,因此您需要添加一个 lib 部分,然后添加平台特定的文件夹(在我的情况下, wpa81 ),然后需要每个.dll文件.

对于WindowsRuntinme项目,您需要两个文件,分别是WindowsRuntinmeProject.priWindowsRuntimeProject.winmd.如果PCL文件带有视图,则需要额外的文件和逻辑,因此您需要在Platform文件夹中添加ClassLibraryWithViews.dll,然后您需要创建一个与PCL项目同名的文件夹,然后在其中放入ClassLibraryWithViews.xr.xml(具有一些xaml标签和信息),然后在项目中创建视图的文件夹结构(如果您碰巧有一个的话).在我的示例中,我在Themes文件夹中有一个Generic.xaml,在View文件夹中有一个PageView.xaml,所以我在这里复制了该结构.您会注意到文件不是.xaml,实际上是.xbf,这是在构建项目后获得的,所以这些是您需要使用的文件.我还应该指出,我的Generic.xbf是ResourceDictionary(无代码隐藏),而我的PageView.xbf实际上是Page,因此它具有代码隐藏功能,但是当您构建软件包时,这是透明的,即很好.

然后,将其安装到项目中后,您将在platform文件夹中看到每个.dll,并且您还将看到WinRT项目,就好像它是.dll.
最好指出,这里的每个文件都是通过在解决方案中构建项目而生成的,因此无需创建任何文件.

值得一提的是,您可以看到我直接将MvvmLight .dlls添加到了我的项目中,尽管如果您希望将它们作为依赖项添加到nuget包元数据中,那么在安装时将获取它们并进行安装.是nuget包.该部分可以在这里看到:

So the idea is pretty simple actually, in this case I wanted to put everything in .dlls, so you need to add a lib section and then the platform specific folder (in my case wpa81) and then every .dll file you need.

In the case of the WindowsRuntinme project you need two files, a WindowsRuntinmeProject.pri and WindowsRuntimeProject.winmd.
In the case of the PCL file with views, extra files and logic is needed, so you need yo add the ClassLibraryWithViews.dll in the platform folder, then you need to create a folder with the same name as the PCL project, and inside put the ClassLibraryWithViews.xr.xml (that has some xaml tags and info) and then you create the folder structure of the views in your project, if you happen to have one. On my example I have a Generic.xaml inside a Themes folder and PageView.xaml inside my View folder, so I replicate that structure here. You can notice that the files are not .xaml, they're actually .xbf, that's what you get after you build the project, so those are the ones you need to use. I should also point that my Generic.xbf is a ResourceDictionary (no code-behind) and my PageView.xbf is in fact a Page, so it has code-behind, but when you're building the package, that's transparent, which is nice.

Then after you install it on your project you'll have every .dll you see in the platform folder, and you'll also see the WinRT project as if it were a .dll.
It's good to point out that every file in here is generated by building the projects in the solution, so there is no need to create any of it.

Another point to mention, you can see that I added the MvvmLight .dlls directly to my project, although if you want you can add them as dependencies in the nuget package metadata, so they will be fetched and installed when you're installing you're nuget package. The section can be seen here:

这篇关于Nuget解决本地文件中的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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