question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Building portable DLLs that can be tested

See original GitHub issue

As more of Roslyn moves to target .Net Standard we’re running into a problem with our unit test DLLs. Like our code they need to move to target .Net Standard so we can run our tests on desktop, CoreCLR and across operating systems. Yet there doesn’t seem to be a way to build DLLs which target .Net Standard that are easily tested.

Consider for example the C# syntax unit test project. This targets .Net Standard and runs on CoreCLR / across OS. It does so as a part of our CI system with great success.

This setup though is frustrating because the project can’t be tested directly. The project.json file lacks a runtimes section hence we can’t use <CopyNuGetImplementations>true</CopyNuGetImplementations>. This means the build output of this project lacks the necessary DLLS to make the project runnable. As a result no unit test app works as a developer would expect: test driven.Net, Test Explorer, xunit console runner, etc …

In order to make the tests runnable we have a deployment project: one for desktop and one for CoreCLR. These deployment projects are do-nothing EXE which reference all of our portable unit test assemblies. Because it’s an EXE, the runtimes section is valid, NuGet implementations are copied and the output is runnable. But again none of the standard tooling like TDD.Net / Test Explorer understand this setup. Hence there is always an extra step for developers to take to run their tests.

How can we setup our portable projects to avoid this? This seems like a pretty straight forward problem, hopefully someone has figured out a good solution to this.

We’ve tried adding runtimes sections to the project.json file in our DLL projects. But that only results in loads of NuGet errors.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:19 (19 by maintainers)

github_iconTop GitHub Comments

1reaction
jaredparcommented, Jan 30, 2017

Disagree. This should be an option that I pass to LUT / Test Explorer. Absent of an option they could default to the current runtime.

My project file should not have to change from a standard portable DLL in order to enable tests.

1reaction
tmatcommented, Jan 30, 2017

I think this needs to be addressed on multiple layers:

dotnet SDK

Currently one can specify multiple targets for project build via <TargetFrameworks>, which results in the project compiled and deployed multiple times along with all the necessary implementation assemblies and runtime config files for each target framework.

If the project is truly portable (i.e. the same code works on all platforms) repeating the compilation steps is unnecessary. In Roslyn, for example, most tests can be made portable and target netstandard and those that can’t could be moved to separate “Desktop” test projects. We still want to run tests on (possibly multiple versions of) CoreCLR and on Desktop FX.

What I think would be useful here is having the option to specify something like <DeploymentFrameworks> for a project. Setting this property in context of a TargetFramework would result in the compilation outputs compiled for that particular TargetFramework to be copied from the intermediate directory to multiple deployment directories (based on the list in DeploymentFrameworks) along with the runtime assemblies and config files specific to the respective DeploymentFramework. In the Roslyn test scenario, we would specify TargetFramework=netstandard1.3 and DeploymentFrameworks=netcoreapp1.0;netfx461, for example.

vstest/dotnet test/Test Explorer/Live Unit Testing

Ability to select a DeploymentFramework to run tests on. In VS Test Explorer this could be added as a drop-down list to Test Explorer, for example.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Make portable .dll without second compilation ? : r/cpp
The short answer is no, you can't make one file that works in both Linux and Windows. The file formats are different, but...
Read more >
How to: Write unit tests for C++ DLLs - Visual Studio
Learn how to develop a native C++ DLL using test-first methodology. Begin by creating a native test project.
Read more >
Build and test DLLs
Build DLLs that call a REST API to return the latest price of bitcoin in US dollars ... Compile the code that is...
Read more >
How do you create a unit test assembly for a .NET Portable ...
Adding a manual direct assembly reference to C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.
Read more >
How to build and use DLLs on Windows
To build a stripped, size-optimized DLL, square.dll : $ cc -shared -Os -s -o square.dll square.c. Now a test program to link against...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found