0

I have .net assembly which uses native dll. IIS copies files to 'Temporary ASP.NET Files' folder. And I want IIS copies dll together with native dll. I tried to use manifest dependencies but without success. I heard that I can user csc option -linkresource for native dll, as described here

Compile A.cs into a DLL, link to a native DLL N.dll, and put the output in the Global Assembly Cache (GAC). In this example, both A.dll and N.dll will reside in the GAC.

csc -linkresource:N.dll -t:library A.cs gacutil -i A.dll

I want to use this option but

This compiler option is unavailable in Visual Studio and cannot be changed programmatically.

But they forced me do not use visual studio project and build it by csc directly. It is a too robust task.

Can I change the project file to accomplish this task?

I saw this article but it is outdated and does not contain any useful information. I use 2019 Visual Studio.

Alexey Subbota
  • 938
  • 6
  • 23

2 Answers2

1

The solution was too simple for the 2019 Studio!

I just added several lines to the project file and ...voila!

  <ItemGroup>
    <LinkResource Include="..\Debug\NativeDll64.dll">
      <Link>NativeDll64.dll</Link>
    </LinkResource>
    <LinkResource Include="..\Debug\NativeDll32.dll">
      <Link>NativeDll32.dll</Link>
    </LinkResource>
  </ItemGroup>

And these two files now are copied to GAC or Temporary ASP.NET Files along with the managed assembly.

Alexey Subbota
  • 938
  • 6
  • 23
  • Glad to know you've found the solution for your issue, please consider marking it as [self-answer](https://stackoverflow.com/help/self-answer) to help share the useful info to others :) – LoLance Oct 09 '19 at 12:32
0

It seems that you're running your application in IIS, apart from overwriting the CoreCompile target, maybe you can also consider turning off shadow copying.

Set shadowCopyBinAssemblies to false in web.config.

<configuration>
  ...
  <system.web>
    ...
    <hostingEnvironment shadowCopyBinAssemblies="false" />

And then it will load assemblies from bin folder instead of Temporary folder. And it's easier to copy native assemblies to bin folder. Many topics about msbuild can give you help. More details about shadow copying please refer to this blog.

LoLance
  • 25,666
  • 1
  • 39
  • 73
  • Thank you for the answer but I am interested in shadow copying because it makes easier to upgrade installation. So, it is the solution to the last resort. – Alexey Subbota Oct 08 '19 at 06:09