Referencing standard dlls from a .NET Core XUnit project
Asked Answered
M

1

3

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?

Matthus answered 16/6, 2016 at 18:39 Comment(0)
M
7

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.

Matsuyama answered 16/6, 2016 at 19:11 Comment(4)
Thank you, I ended up creating my own custom feed and used nuget.exe to pack up all of the dlls into a package then referenced it!Matthus
Referencing assemblies directly from disk should be available when .NET Core 2.0 ships. github.com/dotnet/sdk/issues/120Tusk
@JaanusVarus: doesn't look like it's possible. The option is there, compilation against the types in the referenced assembly works, but at runtime the referenced assembly is not found as it's not added to TRUSTED_PLATFORM_ASSEMBLIES. Major pain in the posterior.Lodie
dotnet pack link is broken.Fundamental

© 2022 - 2024 — McMap. All rights reserved.