问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/37866997/referencing-standard-dlls-from-a-net-core-xunit-project