引用.NET Core XUnit项目中的标准dll [英] Referencing standard dlls from a .NET Core XUnit project

查看:127
本文介绍了引用.NET Core XUnit项目中的标准dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用最新版本的XUnit,并且遵循了这些步骤启动类库(.NET Core)项目.

整个解决方案中的所有其他库仅使用4.6.1,因此我将pr​​oject.json中的frameworks部分更改为以下内容:

{
    "frameworks": {
        "net461": {
            "dependencies": {
                "Microsoft.NETCore.Platforms": "1.0.1-rc2-24027"
            }
        }
    }
}

,并且在我的解决方案中一切正常.我能够运行测试,并且对其他库的所有引用都可以正常工作,即使它们仅是461.基本上,在我的解决方案中,我还有其他几个类库(.NET Core),而我的XUnit库也依赖于它们,因此我可以直接通过Visual Studio对其进行引用,并将引用添加到XUnit项目的project.json文件中./p>

出现一种情况,我需要执行以下操作:

仅将XUnit项目复制到另一台开发人员计算机.允许他编辑源代码,以便他能够创建测试,但不能授予他访问所有其他库/代码的权限.我认为我将能够简单地将所有其他dll复制到一个随机文件夹中,并能够从独立的XUnit项目中引用它们.但是,事实并非如此,因为在尝试引用时,我收到一条错误消息,说.NET Core项目无法引用标准dll.

有人可以让我知道我该怎么做吗?

解决方案

您应该将库作为nuget软件包分发.

.NET核心只能通过Nuget与依赖项一起使用.即使使用VS UI(添加引用"命令)在后台引用中添加引用也作为nuget包添加:如果打开project.json文件,您将看到您的库是使用相同的"package:version"格式指定的在依赖项"部分中.)

要将代码打包到Nuget软件包中,请使用 dotnet pack 命令.

如果您不使用任何公共Nuget来源,则可以托管您的主机自己的Nuget Feed .

I am using the latest version of XUnit and I followed these steps to get the Class Library (.NET Core) project started.

All other libraries throughout my entire solution are only using 4.6.1 so I changed the frameworks section in project.json to the following:

{
    "frameworks": {
        "net461": {
            "dependencies": {
                "Microsoft.NETCore.Platforms": "1.0.1-rc2-24027"
            }
        }
    }
}

and everything works fine inside of my solution. I am able to run tests and all references to other libraries work fine even though they are 461 only. Basically, in my solution I have several other Class Libraries (.NET Core) and my XUnit Library relies on them so I am simply able to reference them right through visual studio and the references get added to the XUnit project's project.json file.

A situation arose where I need to do the following:

Copy only the XUnit project to another developers computer. Allow him to edit the source code so he is able to create tests, but not give him access to all of the other libraries/code. I figured I would simply be able to copy all of the other dlls into a random folder and be able to reference them from the standalone XUnit project. However, this isn't the case because when trying to reference I get an error saying that .NET Core projects can't reference standard dlls.

Can someone give me an idea of how I can do this?

解决方案

You should distribute your Libraries as nuget packages.

.NET core works with dependencies only via Nuget. Even when you add reference using VS UI ("Add reference" command) in background reference is added as a nuget package: if you open project.json file, you will see that your Libraries are specified using the same "package:version" format in "dependencies" section as others).

To pack your code into Nuget package use the dotnet pack command.

If you do not use any public Nuget sources, you can Hosting Your Own Nuget Feed.

这篇关于引用.NET Core XUnit项目中的标准dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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