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

末鹿安然 提交于 2019-12-11 13:11:35

问题


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:


Why not adding them as embedded resource:

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


来源:https://stackoverflow.com/questions/30864223/add-as-link-to-within-a-project-folder-to-copy-always-to-root-of-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!