Skip to content

indirect DllImport-ed files are not copied on "Out"-Deployment for a TestRun #5557

@LukasGelke

Description

@LukasGelke

Summary

I need to copy a Native DLL to the Test-Run-Deplyoment folder, with "minimal effort". (For VisualStudio locally and vstest/dotnet in Pipelines)

Background and Motivation

As System.Data.SqlClient is deprecated, we are switching to Microsoft.Data.SqlClient. One caveat is that (under Windows, but currently our main Platform) there is a Native DLL necesarry (Microsoft.Data.SqlClient.SNI.x64.dll (NetFramework) / win-x64\native\Microsoft.Data.SqlClient.SNI.dll (Net) or whatever target architechture). These DLLs are present in the build output. However it will not be copied upon an MsTest Deployment (ie the "Out" folder), because it is only referenced via Dll-Import as far as i understand

Proposed Feature

(one of:)
a) DeploymentItemAttribute for entire Assembly

  • currently, tests will work if given [DeploymentItem("Microsoft.Data.SqlClient.SNI.x64.dll")]. However it is unfeasible to provide this attribute for all affected tests (even if using it on the class)
    • and there would be #ifs for NetFramework vs net8
  • making a crude Compile-Include in the Directory.Build.targets would certainly be convenient, even if that's bad design

b) simmilar to a: a Property-List in the runsettings that specifies such files (with the same syntax as the sttribute? And/Or EnvVar resolution?)

  • this appears to had been possible previously with the also now deprecated testsettings file. But I cannot find information if this exists in the runsettings format (without using legacy stuff)

c) "somehow" figure out that there is a Dependency

  • the DllImportAttribute may not specify a full path and no search path; so not sure if going just by reflection and that name would be reliable
  • unless there may be a runsettings-Property, i.e. Name-Allow-List or similar

d) "somehow" change the M.D.SqlClient Library, so that MsTest can pick it up

  • which would be "their issue"
  • not sure if that's even possible at all or has other/worse implications/drawbacks

Alternative Designs

Trying to reference the SNI.dll in the Test Project does not work. Using None/Content will not copy it on Test. Using Reference is not possible, because it does only allow managed dlls.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: MSTestIssues with MSTest that are not specific to more refined area (e.g. analyzers or assertions)Needs: Triage 🔍

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions