Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
684 views
in Technique[技术] by (71.8m points)

c# - Referencing standard dlls from a .NET Core XUnit project

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...