Add as link to within a project folder to copy always to root of output

1k views Asked by At

I'm doing some interop with unmanaged .dlls in a standard c# project. I cannot add these .dlls as simple references and have to use P/Invoke to actually use them. They don't include manifests so doing any clever reflection stuff to load these dynamically (And thus solve the problem of including them as explicit, separate files) is simply out of the question.

I am not concerned with installer releases, I can tell WiX(Or whatever installer platform I choose) what files to exactly put where on a target system.

The problem is in terms of debugging output, I need these .DLLs side-by-side with my own project's executable, but I don't want them cluttering up my actual managed code.

So my situation is this;

  • I add several .dll's into a project's folder as links.
  • I attempt to change the .csproj to output the linked files at the root of the debugging output.

It looks something like this:

<None Include="..\..\externals\MyLibraries\ADll.dll">
  <Link>TidyFolder\ADll.dll</Link>
  <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>

Now, normally you'd change the <Link> tag to where you want the output to go, but doing this:

<None Include="..\..\externals\MyLibraries\ADll.dll">
  <Link>ADll.dll</Link>
  <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>

Changes the folder the linked .dlls are residing in within my project explorer; it does output correctly, but the clutter is undesirable and the reason why I wanted to throw them into a folder in the first place.

TL;DR: How can you simultaneously control where a linked item is visible within a project, as well as its output location on debug.

1

There are 1 answers

1
Nissim On

Consider adding them as embedded resource:

  <ItemGroup>
    <EmbeddedResource Include="..\..\externals\MyLibraries\ADll.dll">
      <Link>TidyFolder\ADll.dll</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </EmbeddedResource>
  </ItemGroup>